import { AppIntroComponent } from "./app_intro.js";
import { AssistantMessageComponent } from "./assistant_message.js";
import { DiffReviewMessageComponent } from "./diff_review_message.js";
import { SessionDividerComponent } from "./session_divider.js";
import { SystemMessageComponent } from "./system_message.js";
import { buildToolOutputProps, renderToolOutput } from "./tool_output.js";
import { UserMessageComponent } from "./user_message.js";
export function isAssistantMessageModel(model) {
    return model.type === "assistant" || model.type === "assistant_partial";
}
export function renderChatMessage(model, options) {
    const { theme, thoughtsVisible, compactToolUi, toolUiRegistry } = options;
    switch (model.type) {
        case "app_intro": {
            const component = new AppIntroComponent(theme, {
                title: model.title,
                body: model.body,
            });
            return {
                component,
                isAssistant: false,
                update: (nextModel) => {
                    if (nextModel.type !== "app_intro")
                        return false;
                    component.update({
                        title: nextModel.title,
                        body: nextModel.body,
                    });
                    return true;
                },
            };
        }
        case "assistant": {
            const component = new AssistantMessageComponent(theme, model, thoughtsVisible);
            return {
                component,
                isAssistant: true,
                update: (nextModel, nextOptions) => {
                    if (!isAssistantMessageModel(nextModel))
                        return false;
                    component.setThinkingVisibility(nextOptions.thoughtsVisible);
                    component.update(nextModel);
                    return true;
                },
                hasVisibleText: () => component.hasVisibleText,
            };
        }
        case "assistant_partial": {
            const component = new AssistantMessageComponent(theme, model, thoughtsVisible);
            return {
                component,
                isAssistant: true,
                update: (nextModel, nextOptions) => {
                    if (!isAssistantMessageModel(nextModel))
                        return false;
                    component.setThinkingVisibility(nextOptions.thoughtsVisible);
                    component.update(nextModel);
                    return true;
                },
                hasVisibleText: () => component.hasVisibleText,
            };
        }
        case "diff_review": {
            const component = new DiffReviewMessageComponent(theme, model);
            return {
                component,
                isAssistant: false,
                update: (nextModel, nextOptions) => {
                    if (nextModel.type !== "diff_review")
                        return false;
                    component.setTheme(nextOptions.theme);
                    component.update(nextModel);
                    return true;
                },
            };
        }
        case "system": {
            const component = new SystemMessageComponent(theme, {
                text: model.text,
                kind: model.kind,
            });
            return {
                component,
                isAssistant: false,
                update: (nextModel) => {
                    if (nextModel.type !== "system")
                        return false;
                    component.update({ text: nextModel.text, kind: nextModel.kind });
                    return true;
                },
            };
        }
        case "user": {
            const component = new UserMessageComponent(theme, {
                text: model.text,
                kind: model.kind,
            });
            return {
                component,
                isAssistant: false,
                update: (nextModel) => {
                    if (nextModel.type !== "user")
                        return false;
                    component.update({ text: nextModel.text, kind: nextModel.kind });
                    return true;
                },
            };
        }
        case "tool": {
            const view = toolUiRegistry.render(model.event, {
                theme,
                compact: compactToolUi,
            });
            const component = renderToolOutput(view, compactToolUi);
            return {
                component,
                isAssistant: false,
                update: (nextModel, nextOptions) => {
                    if (nextModel.type !== "tool")
                        return false;
                    const nextView = nextOptions.toolUiRegistry.render(nextModel.event, {
                        theme: nextOptions.theme,
                        compact: nextOptions.compactToolUi,
                    });
                    component.update(buildToolOutputProps(nextView, nextOptions.compactToolUi));
                    return true;
                },
            };
        }
        case "session_divider": {
            const component = new SessionDividerComponent(theme, { label: model.label });
            return {
                component,
                isAssistant: false,
                update: (nextModel) => {
                    if (nextModel.type !== "session_divider")
                        return false;
                    component.update({ label: nextModel.label });
                    return true;
                },
            };
        }
    }
}
//# sourceMappingURL=chat_message_model.js.map