"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const designSystem = require("@choiceform/design-system");
const iconsReact = require("@choiceform/icons-react");
const react = require("../_vendor/@legendapp/state/react.cjs");
const index = require("../_vendor/usehooks-ts/dist-index.cjs");
const index$1 = require("../i18n/index.cjs");
const coreStore = require("../stores/core-store.cjs");
const messageStore = require("../stores/message-store.cjs");
const HeaderTv = designSystem.tcv({
  slots: {
    root: "flex h-10 min-w-0 items-center justify-between px-2",
    title: "truncate pl-2 font-strong",
    headerMessage: "text-secondary-foreground",
    management: "",
    messageCount: "text-secondary-foreground ml-1 font-normal"
  }
});
const Header = react.observer(function Header2(props) {
  const { onCreateNewChat, onSwitchToChat, onDeleteCurrentChat, availableChats = [] } = props;
  const currentChat = react.use$(coreStore.coreStore$.currentChat);
  const currentMessages = react.use$(messageStore.messageComputed$.currentMessages);
  const language = react.use$(coreStore.coreStore$.ui.language);
  const handleCreateNewChat = index.useEventCallback(() => {
    if (onCreateNewChat) {
      onCreateNewChat();
    } else {
      console.warn("onCreateNewChat callback not provided");
    }
  });
  const handleSwitchToChat = index.useEventCallback((chatId) => {
    if (onSwitchToChat) {
      onSwitchToChat(chatId);
    } else {
      console.warn("onSwitchToChat callback not provided");
    }
  });
  const handleDeleteChat = index.useEventCallback((chatId) => {
    if (onDeleteCurrentChat) {
      onDeleteCurrentChat(chatId);
    } else {
      console.warn("onDeleteCurrentChat callback not provided");
    }
  });
  const chatList = index$1.t("header", "chat-list");
  const chatManagement = index$1.t("header", "chat-management");
  const deleteCurrentChat = index$1.t("header", "delete-current-chat");
  const message = index$1.t("header", "message");
  const newChat = index$1.t("header", "new-chat");
  const title = index$1.t("header", "title");
  const tv = HeaderTv();
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: tv.root(), children: [
    /* @__PURE__ */ jsxRuntime.jsxs("h1", { className: tv.title(), children: [
      /* @__PURE__ */ jsxRuntime.jsxs("span", { className: tv.headerMessage(), children: [
        currentChat?.title || title,
        " "
      ] }),
      currentMessages.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: tv.messageCount(), children: `(${currentMessages.length} ${message})` })
    ] }),
    /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dropdown, { selection: true, children: [
      /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dropdown.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
        designSystem.IconButton,
        {
          className: tv.management(),
          tooltip: { content: chatManagement },
          children: /* @__PURE__ */ jsxRuntime.jsx(iconsReact.RoboSmall, {})
        }
      ) }),
      /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dropdown.Content, { className: "min-w-64", children: [
        /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dropdown.Label, { children: chatList }),
        availableChats.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
          /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dropdown.Divider, {}),
          availableChats.map((chat) => /* @__PURE__ */ jsxRuntime.jsx(
            designSystem.Dropdown.Item,
            {
              onClick: () => handleSwitchToChat(chat.id),
              selected: chat.id === currentChat?.id,
              shortcut: {
                keys: designSystem.formatRelativeTime(new Date(chat.updatedAt), {
                  language
                })
              },
              children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dropdown.Value, { children: chat.title })
            },
            chat.id
          ))
        ] }),
        /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dropdown.Divider, {}),
        /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dropdown.Item, { onClick: handleCreateNewChat, children: [
          /* @__PURE__ */ jsxRuntime.jsx(iconsReact.AddSmall, {}),
          newChat
        ] }),
        currentChat && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
          /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dropdown.Divider, {}),
          /* @__PURE__ */ jsxRuntime.jsxs(
            designSystem.Dropdown.Item,
            {
              variant: "danger",
              onClick: () => handleDeleteChat(currentChat.id),
              children: [
                /* @__PURE__ */ jsxRuntime.jsx(iconsReact.TrashSmall, {}),
                deleteCurrentChat
              ]
            }
          )
        ] })
      ] })
    ] })
  ] });
});
exports.Header = Header;
//# sourceMappingURL=header.cjs.map
