package ai.kilocode.client.session.views.base

import ai.kilocode.client.session.model.Content
import ai.kilocode.client.session.ui.style.SessionEditorStyle
import ai.kilocode.client.session.ui.style.SessionEditorStyleTarget
import com.intellij.openapi.Disposable
import javax.swing.JComponent
import javax.swing.JPanel

/**
 * Base class for all part renderers.
 *
 * Each subclass wraps one [Content] subtype and knows how to display
 * and update it. Subclasses extend [JPanel] so they can be added directly
 * to [ai.kilocode.client.session.views.MessageView] without an extra component wrapper.
 *
 * All methods must be called on the EDT.
 */
abstract class PartView : JPanel(), Disposable, SessionEditorStyleTarget {

    /** Stable [Content.id] this renderer was created for. */
    abstract val contentId: String

    var resize: ((JComponent, () -> Unit) -> Unit)? = null

    var hover: ((PartView, Boolean) -> Unit)? = null

    /**
     * Apply a full content update — replace, not append.
     * Called when [ai.kilocode.client.session.model.SessionModelEvent.ContentUpdated] fires.
     */
    abstract fun update(content: Content)

    /**
     * Append a streaming delta to the existing content.
     * Only meaningful for text-bearing renderers ([ai.kilocode.client.session.views.TextView],
     * [ai.kilocode.client.session.views.ReasoningView]); others ignore deltas by default.
     */
    open fun appendDelta(delta: String) {}

    open fun setHovered(value: Boolean) {}

    override fun applyStyle(style: SessionEditorStyle) {}

    override fun dispose() {}

    /** Readable name for test dumps. */
    open fun dumpLabel(): String = javaClass.simpleName
}
