{"version":3,"file":"QueueSheet.mjs","names":[],"sources":["../../../../src/web/features/session/QueueSheet.tsx"],"sourcesContent":["import { useT } from '@agimon-ai/po-core/web';\nimport {\n  Button,\n  ChevronUpIcon,\n  Dialog,\n  DialogBody,\n  DialogContent,\n  DialogHeader,\n  DialogTitle,\n  RefreshIcon,\n  TrashIcon,\n} from '@agimon-ai/po-web-components';\n\nimport type { QueuedEntry } from '../../lib/sessionModel';\nimport { useDashboardState } from '../../stores/dashboardStateStore';\n\nexport function QueueSheet({\n  sessionId,\n  count,\n  disabled = false,\n  entries,\n  onClear,\n  onDelete,\n  onPromote,\n  onResume,\n  operationId,\n  paused = false,\n}: {\n  sessionId: string | null;\n  count: number;\n  disabled?: boolean;\n  entries: readonly QueuedEntry[];\n  onClear: () => Promise<void>;\n  onDelete: (id: string) => Promise<void>;\n  onPromote?: (id: string, operationId?: string) => Promise<void>;\n  onResume?: () => Promise<void>;\n  operationId?: string;\n  paused?: boolean;\n}) {\n  const t = useT();\n  const key = JSON.stringify(['queue', sessionId]);\n  const [open, setOpen] = useDashboardState(`${key}/open`, false);\n  const [pending, setPending, pendingState] = useDashboardState<string | null>(`${key}/pending`, null);\n  const [error, setError] = useDashboardState<string | null>(`${key}/error`, null);\n  const [clearAcknowledged, setClearAcknowledged] = useDashboardState(`${key}/cleared`, false);\n  const unlisted = Math.max(0, count - entries.length);\n  const label =\n    count === 1\n      ? t('webDashboard.session.queuedCountOne', '{count} queued message', { count: String(count) })\n      : t('webDashboard.session.queuedCountOther', '{count} queued messages', { count: String(count) });\n\n  // Automatic delivery closes an empty queue, but explicit actions still need acknowledgement.\n  if (count === 0 && pending === null && (open || clearAcknowledged) && (clearAcknowledged || error === null)) {\n    setClearAcknowledged(false);\n    setOpen(false);\n  }\n\n  const act = async (action: string, command: () => Promise<void>): Promise<void> => {\n    if (disabled || pendingState.state !== null) return;\n    setPending(action);\n    setError(null);\n    setClearAcknowledged(false);\n    try {\n      await command();\n      if (action === 'clear') setClearAcknowledged(true);\n    } catch (failure) {\n      setError(failure instanceof Error ? failure.message : String(failure));\n    } finally {\n      setPending(null);\n    }\n  };\n  const actionDisabled = disabled || pending !== null;\n\n  if (count === 0 && !open) return null;\n\n  return (\n    <>\n      {count > 0 ? (\n        <Button\n          variant=\"subtle\"\n          size=\"sm\"\n          data-testid=\"composer-queued\"\n          aria-haspopup=\"dialog\"\n          aria-expanded={open}\n          onClick={() => setOpen(true)}\n          className=\"mb-2 h-7 w-full justify-between rounded-md border border-po-border-soft bg-po-panel/60 px-2.5 text-base font-medium text-po-dim hover:text-po-hi\"\n        >\n          <span className=\"flex min-w-0 items-center gap-2\">\n            <RefreshIcon className=\"h-3 w-3 shrink-0 text-po-cyan\" />\n            <span className=\"shrink-0 font-semibold text-po-hi\">{label}</span>\n            <span className=\"min-w-0 truncate text-sm font-normal text-po-dim\">\n              {paused\n                ? t('webDashboard.session.queuePausedUntilResumed', 'paused until resumed')\n                : t('webDashboard.session.queueWaitingForRun', 'waiting for the current run')}\n            </span>\n          </span>\n          <span className=\"flex shrink-0 items-center gap-1 text-sm text-po-dim\">\n            {t('webDashboard.session.viewQueue', 'view queue')}\n            <ChevronUpIcon className=\"h-3 w-3\" />\n          </span>\n        </Button>\n      ) : null}\n\n      <Dialog open={open} onOpenChange={setOpen}>\n        <DialogContent\n          width=\"lg\"\n          data-testid=\"queue-sheet\"\n          aria-describedby={undefined}\n          className=\"top-auto bottom-0 left-1/2 max-h-[min(72dvh,560px)] !w-full !max-w-2xl -translate-x-1/2 translate-y-0 rounded-t-xl rounded-b-none border-b-0 data-[state=open]:animate-none\"\n        >\n          <span aria-hidden className=\"mx-auto mt-2 h-1 w-10 shrink-0 rounded-full bg-po-border\" />\n          <DialogHeader\n            dismissible\n            closeLabel={t('webDashboard.session.queueClose', 'close queued messages')}\n            className=\"py-2.5\"\n          >\n            <DialogTitle>{t('webDashboard.session.queueSheetTitle', 'queued messages')}</DialogTitle>\n            <span className=\"text-sm text-po-dim\">\n              {paused\n                ? t('webDashboard.session.queuePaused', 'paused')\n                : t('webDashboard.session.queueLabelWaiting', '{label} waiting', { label })}\n            </span>\n          </DialogHeader>\n          <DialogBody className=\"overflow-y-auto p-2 pb-[max(0.75rem,env(safe-area-inset-bottom))]\">\n            <ol className=\"flex flex-col gap-1.5\">\n              {entries.map((entry, index) => (\n                <li\n                  key={entry.id}\n                  data-testid=\"queue-sheet-item\"\n                  className=\"flex min-w-0 gap-3 rounded-md border border-po-border-soft bg-po-deep px-3 py-2.5\"\n                >\n                  <span className=\"pt-0.5 text-xs font-semibold text-po-cyan\">\n                    {String(index + 1).padStart(2, '0')}\n                  </span>\n                  <div className=\"min-w-0 flex-1\">\n                    <p className=\"whitespace-pre-wrap break-words text-lg leading-relaxed text-po-text\">{entry.text}</p>\n                    {entry.images && entry.images.length > 0 ? (\n                      <p className=\"mt-1 text-sm text-po-dim\">\n                        {entry.images.length === 1\n                          ? t('webDashboard.session.imagesAttachedOne', '{count} image attached', {\n                              count: entry.images.length,\n                            })\n                          : t('webDashboard.session.imagesAttachedOther', '{count} images attached', {\n                              count: entry.images.length,\n                            })}\n                      </p>\n                    ) : null}\n                  </div>\n                  {entry.disposition === 'pending' && onPromote ? (\n                    <Button\n                      variant=\"ghost\"\n                      size=\"sm\"\n                      data-testid={`queue-steer-${String(index)}`}\n                      aria-label={\n                        operationId === undefined\n                          ? t('webDashboard.session.queueSendNowLabel', 'send now queued message {index}', {\n                              index: String(index + 1),\n                            })\n                          : t('webDashboard.session.queueSteerLabel', 'steer queued message {index}', {\n                              index: String(index + 1),\n                            })\n                      }\n                      disabled={actionDisabled}\n                      onClick={() => void act(`send:${entry.id}`, () => onPromote(entry.id, operationId))}\n                      className=\"h-7 shrink-0 text-po-cyan\"\n                    >\n                      {pending === `send:${entry.id}`\n                        ? t('webDashboard.session.queueSending', 'sending…')\n                        : operationId === undefined\n                          ? t('webDashboard.session.queueSendNow', 'send now')\n                          : t('webDashboard.session.queueSteer', 'steer')}\n                    </Button>\n                  ) : null}\n                  <Button\n                    variant=\"ghost\"\n                    size=\"icon\"\n                    data-testid={`queue-delete-${String(index)}`}\n                    aria-label={t('webDashboard.session.queueDeleteLabel', 'delete queued message {index}', {\n                      index: String(index + 1),\n                    })}\n                    title={\n                      entry.disposition === 'handoff'\n                        ? t('webDashboard.session.queueAlreadyDelivering', 'This message is already being delivered')\n                        : t('webDashboard.session.queueDeleteMessage', 'Delete this message')\n                    }\n                    disabled={actionDisabled || entry.disposition !== 'pending'}\n                    onClick={() => void act(`delete:${entry.id}`, () => onDelete(entry.id))}\n                    className=\"h-7 w-7 shrink-0 text-po-faint hover:text-po-red\"\n                  >\n                    <TrashIcon className=\"h-3.5 w-3.5\" />\n                  </Button>\n                </li>\n              ))}\n              {unlisted > 0 ? (\n                <li\n                  data-testid=\"queue-sheet-unlisted\"\n                  className=\"rounded-md border border-dashed border-po-border px-3 py-2.5 text-sm text-po-dim\"\n                >\n                  {unlisted === 1\n                    ? t(\n                        'webDashboard.session.queueUnlistedOne',\n                        '{count} more queued message is waiting in the session. Their text is not available in this browser.',\n                        { count: unlisted },\n                      )\n                    : t(\n                        'webDashboard.session.queueUnlistedOther',\n                        '{count} more queued messages are waiting in the session. Their text is not available in this browser.',\n                        { count: unlisted },\n                      )}\n                </li>\n              ) : null}\n            </ol>\n            {paused && onResume ? (\n              <Button\n                variant=\"subtle\"\n                size=\"sm\"\n                data-testid=\"queue-resume\"\n                className=\"mt-2 w-full\"\n                disabled={actionDisabled}\n                onClick={() => void act('resume', onResume)}\n              >\n                {pending === 'resume'\n                  ? t('webDashboard.session.queueResuming', 'resuming…')\n                  : t('webDashboard.session.queueResume', 'resume queued messages')}\n              </Button>\n            ) : null}\n            {count > 0 ? (\n              <Button\n                variant=\"danger\"\n                size=\"sm\"\n                data-testid=\"queue-clear\"\n                className=\"mt-2 w-full\"\n                disabled={actionDisabled}\n                onClick={() => void act('clear', onClear)}\n              >\n                {pending === 'clear'\n                  ? t('webDashboard.session.queueDeleting', 'deleting…')\n                  : t('webDashboard.session.queueDeleteAll', 'delete all queued messages')}\n              </Button>\n            ) : null}\n            {pending !== null ? (\n              <output className=\"mt-2 block text-sm text-po-dim\">\n                {t('webDashboard.session.queueAwaitingAck', 'waiting for the session to acknowledge this action…')}\n              </output>\n            ) : null}\n            {error !== null ? (\n              <p role=\"alert\" data-testid=\"queue-error\" className=\"mt-2 text-sm text-po-red\">\n                {error}\n              </p>\n            ) : clearAcknowledged && count > 0 ? (\n              <output data-testid=\"queue-clear-remaining\" className=\"mt-2 block text-sm text-po-dim\">\n                {t(\n                  'webDashboard.session.queueClearRemaining',\n                  'Messages remain or await confirmation. Messages being delivered or with uncertain delivery cannot be cleared.',\n                )}\n              </output>\n            ) : null}\n          </DialogBody>\n        </DialogContent>\n      </Dialog>\n    </>\n  );\n}\n"],"mappings":";;;;;AAgBA,SAAgB,WAAW,EACzB,WACA,OACA,WAAW,OACX,SACA,SACA,UACA,WACA,UACA,aACA,SAAS,SAYR;CACD,MAAM,IAAI,KAAK;CACf,MAAM,MAAM,KAAK,UAAU,CAAC,SAAS,SAAS,CAAC;CAC/C,MAAM,CAAC,MAAM,WAAW,kBAAkB,GAAG,IAAI,QAAQ,KAAK;CAC9D,MAAM,CAAC,SAAS,YAAY,gBAAgB,kBAAiC,GAAG,IAAI,WAAW,IAAI;CACnG,MAAM,CAAC,OAAO,YAAY,kBAAiC,GAAG,IAAI,SAAS,IAAI;CAC/E,MAAM,CAAC,mBAAmB,wBAAwB,kBAAkB,GAAG,IAAI,WAAW,KAAK;CAC3F,MAAM,WAAW,KAAK,IAAI,GAAG,QAAQ,QAAQ,MAAM;CACnD,MAAM,QACJ,UAAU,IACN,EAAE,uCAAuC,0BAA0B,EAAE,OAAO,OAAO,KAAK,EAAE,CAAC,IAC3F,EAAE,yCAAyC,2BAA2B,EAAE,OAAO,OAAO,KAAK,EAAE,CAAC;CAGpG,IAAI,UAAU,KAAK,YAAY,SAAS,QAAQ,uBAAuB,qBAAqB,UAAU,OAAO;EAC3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