{"version":3,"file":"DockTabs.mjs","names":[],"sources":["../../../../src/web/features/activity/DockTabs.tsx"],"sourcesContent":["import { type DockFaceContribution, useT } from '@agimon-ai/po-core/web';\nimport { ActivityIcon, Button, MessageIcon, NavTabBadge, PuzzleIcon } from '@agimon-ai/po-web-components';\nimport { useEffect, useRef } from 'react';\n\nimport type { DockTab } from '../../stores/uiStore';\n\nconst ACTIVITY_TAB = { id: 'activity', icon: ActivityIcon } as const;\nconst CONVERSATION_TAB = { id: 'conversation', icon: MessageIcon } as const;\nconst CONTEXT_TAB = { id: 'context', icon: PuzzleIcon } as const;\n\ntype Tab = Pick<DockFaceContribution, 'label' | 'icon'> & { id: DockTab };\n\n/**\n * Activity first, then the session's plugin-contributed faces, with Context always last.\n * Conversation, when offered, sits right after the face it is beside, the pair grouped as one piece\n * of work; without that face it keeps its place after Activity.\n */\nexport function DockTabs({\n  contributed = [],\n  conversation = false,\n  conversationBeside,\n  conversationLabel,\n  active,\n  onSelect,\n  badges = {},\n  waiting = 0,\n  attention = [],\n}: {\n  contributed?: readonly DockFaceContribution[];\n  /** The host is showing the conversation in the dock, beside a panel that gave up its own prompt. */\n  conversation?: boolean;\n  /** The face the conversation sits beside, grouped with it, such as the one whose canvas gave up the prompt. */\n  conversationBeside?: string;\n  /** What the conversation is about, such as the open file; names the Conversation tab and the group. */\n  conversationLabel?: string;\n  /** The face on screen, which may be a fallback for the saved pick. */\n  active: DockTab;\n  /** The person picked a face. */\n  onSelect: (tab: DockTab) => void;\n  /** Items on a face that want the person's eye, such as unviewed files. Zero shows nothing. */\n  badges?: Readonly<Record<string, number>>;\n  /** Things in Activity waiting on the person, such as pending approvals; shown in rose on the Activity tab. */\n  waiting?: number;\n  /** Faces that just appeared; they announce themselves with a short tint instead of taking over. */\n  attention?: readonly string[];\n}) {\n  const t = useT();\n  const activityTab: Tab = { ...ACTIVITY_TAB, label: t('webDashboard.activity.tabActivity', 'Activity') };\n  const contextTab: Tab = { ...CONTEXT_TAB, label: t('webDashboard.activity.tabContext', 'Context') };\n  const rest: Tab[] = [\n    ...contributed.map(({ id, label, icon, translateLabel }) => ({ id, label: translateLabel?.(t) ?? label, icon })),\n    contextTab,\n  ];\n  const conversationTab: Tab = {\n    ...CONVERSATION_TAB,\n    label:\n      conversationLabel === undefined\n        ? t('webDashboard.activity.tabConversation', 'Conversation')\n        : t('webDashboard.activity.tabConversationAbout', 'Conversation about {label}', { label: conversationLabel }),\n  };\n  const beside = conversation ? rest.find((tab) => tab.id === conversationBeside) : undefined;\n  // Each entry is one tab, or a face and the conversation beside it drawn as one group.\n  const items: (Tab | readonly [Tab, Tab])[] = beside\n    ? [activityTab, ...rest.map((tab) => (tab === beside ? ([tab, conversationTab] as const) : tab))]\n    : [activityTab, ...(conversation ? [conversationTab] : []), ...rest];\n  const listRef = useRef<HTMLDivElement>(null);\n  const shown = attention.at(-1) ?? active;\n  // A face that just appeared, or the one picked, is scrolled into the strip so\n  // its tint and underline are seen rather than clipped at the rail's edge.\n  useEffect(() => {\n    const list = listRef.current;\n    const tab = Array.from(list?.querySelectorAll<HTMLElement>('[role=\"tab\"]') ?? []).find(\n      (element) => element.dataset.testid === `dock-tab-${shown}`,\n    );\n    if (!list || !tab) return;\n    // The list is the tabs' offset parent, so these are positions inside the strip.\n    const left = tab.offsetLeft;\n    const right = left + tab.offsetWidth;\n    const target =\n      left < list.scrollLeft\n        ? left\n        : right > list.scrollLeft + list.clientWidth\n          ? right - list.clientWidth\n          : list.scrollLeft;\n    if (target === list.scrollLeft) return;\n    const reduced = globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches === true;\n    list.scrollTo({ left: target, behavior: reduced ? 'auto' : 'smooth' });\n  }, [shown]);\n\n  const renderTab = (tab: Tab) => {\n    const ask = tab.id === ACTIVITY_TAB.id;\n    const count = ask ? waiting : (badges[tab.id] ?? 0);\n    return (\n      <Button\n        key={tab.id}\n        variant=\"ghost\"\n        size=\"xs\"\n        role=\"tab\"\n        aria-selected={tab.id === active}\n        // An icon tab names itself on hover and to assistive tech.\n        aria-label={tab.icon ? tab.label : undefined}\n        title={tab.icon ? tab.label : undefined}\n        data-testid={`dock-tab-${tab.id}`}\n        data-active={tab.id === active}\n        data-attention={attention.includes(tab.id) || undefined}\n        onClick={() => onSelect(tab.id)}\n        // pt-2 leaves room for the count that overlaps the icon's top-right; the strip clips vertically.\n        className={`h-auto shrink-0 gap-1.5 rounded-none border-b-2 px-0 pt-2 pb-3 text-base hover:bg-transparent ${\n          tab.id === active\n            ? 'border-po-green font-semibold text-po-hi'\n            : 'border-transparent font-medium text-po-text hover:text-po-text'\n        }`}\n      >\n        {/* The tint fades out through the transition when attention ends; reduced motion just removes it. */}\n        <span\n          className={`relative -mx-1.5 flex items-center rounded px-1.5 py-0.5 transition-colors duration-700 ${\n            attention.includes(tab.id) ? 'bg-po-tint-green text-po-green' : ''\n          }`}\n        >\n          {tab.icon ? <tab.icon className=\"size-5\" /> : tab.label}\n          {count > 0 ? (\n            <>\n              {/* On an icon the count sits on its top-right corner; beside a word it stays inline. */}\n              <NavTabBadge active ask={ask} aria-hidden className={tab.icon ? 'absolute -top-2 -right-2' : 'ml-1.5'}>\n                {count}\n              </NavTabBadge>\n              <span className=\"sr-only\">\n                {ask\n                  ? t('webDashboard.activity.badgeWaiting', ', {count} waiting for you', { count })\n                  : t('webDashboard.activity.badgeNew', ', {count} new', { count })}\n              </span>\n            </>\n          ) : null}\n        </span>\n      </Button>\n    );\n  };\n\n  return (\n    <div\n      ref={listRef}\n      role=\"tablist\"\n      aria-label={t('webDashboard.activity.dockView', 'Dock view')}\n      // The track is always there, so a face appearing never shifts the row; a\n      // vertical wheel scrolls the strip sideways.\n      onWheel={(event) => {\n        if (Math.abs(event.deltaY) > Math.abs(event.deltaX)) event.currentTarget.scrollLeft += event.deltaY;\n      }}\n      className=\"relative flex min-w-0 items-end gap-6 overflow-x-scroll overflow-y-hidden pr-2 [scrollbar-width:thin]\"\n    >\n      {items.map((item) =>\n        'id' in item ? (\n          renderTab(item)\n        ) : (\n          <div\n            key={`group-${item[0].id}`}\n            role=\"group\"\n            aria-label={t('webDashboard.activity.workingOn', 'Working on {label}', {\n              label: conversationLabel ?? item[0].label,\n            })}\n            className=\"flex items-end gap-4 rounded-t-lg bg-po-panel px-2.5\"\n          >\n            {item.map(renderTab)}\n          </div>\n        ),\n      )}\n    </div>\n  );\n}\n"],"mappings":";;;;;AAMA,MAAM,eAAe;CAAE,IAAI;CAAY,MAAM;AAAa;AAC1D,MAAM,mBAAmB;CAAE,IAAI;CAAgB,MAAM;AAAY;AACjE,MAAM,cAAc;CAAE,IAAI;CAAW,MAAM;AAAW;;;;;;AAStD,SAAgB,SAAS,EACvB,cAAc,CAAC,GACf,eAAe,OACf,oBACA,mBACA,QACA,UACA,SAAS,CAAC,GACV,UAAU,GACV,YAAY,CAAC,KAmBZ;CACD,MAAM,IAAI,KAAK;CACf,MAAM,cAAmB;EAAE,GAAG;EAAc,OAAO,EAAE,qCAAqC,UAAU;CAAE;CACtG,MAAM,aAAkB;EAAE,GAAG;EAAa,OAAO,EAAE,oCAAoC,SAAS;CAAE;CAClG,MAAM,OAAc,CAClB,GAAG,YAAY,KAAK,EAAE,IAAI,OAAO,MAAM,sBAAsB;EAAE;EAAI,OAAO,iBAAiB,CAAC,KAAK;EAAO;CAAK,EAAE,GAC/G,UACF;CACA,MAAM,kBAAuB;EAC3B,GAAG;EACH,OACE,sBAAsB,KAAA,IAClB,EAAE,yCAAyC,cAAc,IACzD,EAAE,8CAA8C,8BAA8B,EAAE,OAAO,kBAAkB,CAAC;CAClH;CACA,MAAM,SAAS,eAAe,KAAK,MAAM,QAAQ,IAAI,OAAO,kBAAkB,IAAI,KAAA;CAElF,MAAM,QAAuC,SACzC,CAAC,aAAa,GAAG,KAAK,KAAK,QAAS,QAAQ,SAAU,CAAC,KAAK,eAAe,IAAc,GAAI,CAAC,IAC9F;EAAC;EAAa,GAAI,eAAe,CAAC,eAAe,IAAI,CAAC;EAAI,GAAG;CAAI;CACrE,M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