{"version":3,"file":"BackdropSettings.mjs","names":[],"sources":["../../../../src/web/features/settings/BackdropSettings.tsx"],"sourcesContent":["import { DEFAULT_BACKDROP_ID, HOST_SLOTS, NO_BACKDROP, useT } from '@agimon-ai/po-core/web';\nimport {\n  CheckIcon,\n  RadioGroup,\n  RadioGroupCard,\n  SettingsNote,\n  SettingsSection,\n  SettingsSectionDescription,\n  SettingsSectionHeader,\n  SettingsSectionTitle,\n} from '@agimon-ai/po-web-components';\n\nimport { reloadWebTemplateDecision } from '../../lib/pluginCompositions';\nimport { hostSlotFills, type ResolvedFill } from '../../lib/pluginRegistry';\nimport { backdropId, resolveBackdrop } from '../../lib/templateCatalog';\nimport { ToolRendererBoundary } from '../../lib/ToolRendererBoundary';\nimport { configuredBackdrop, saveBackdropDefault, useTemplateConfiguration } from '../../stores/templateStore';\nimport { usePluginSlotProps } from '../../stores/usePluginSlotProps';\nimport { useWebPluginRegistry } from '../../stores/useWebPluginRegistry';\n\n/** A backdrop names itself with `data: { label, description }` on its fill; its id stands in otherwise. */\nfunction describe(fill: ResolvedFill): { label: string; description?: string } {\n  const data = (typeof fill.data === 'object' && fill.data !== null ? fill.data : {}) as Record<string, unknown>;\n  return {\n    label: typeof data.label === 'string' ? data.label : backdropId(fill),\n    ...(typeof data.description === 'string' ? { description: data.description } : {}),\n  };\n}\n\n/** The backdrop itself, live and small: a backdrop fills whatever box it is given. */\nfunction Preview({ fill }: { fill?: ResolvedFill }) {\n  const props = usePluginSlotProps(null);\n  const Fill = fill?.component;\n  return (\n    <div aria-hidden className=\"relative aspect-video w-full overflow-hidden rounded border border-po-border bg-po-bg\">\n      {fill && Fill ? (\n        <ToolRendererBoundary toolName={backdropId(fill)}>\n          {(failed) => (failed ? null : <Fill {...props} />)}\n        </ToolRendererBoundary>\n      ) : null}\n    </div>\n  );\n}\n\nfunction BackdropCard({\n  value,\n  label,\n  description,\n  fill,\n  selected,\n}: {\n  value: string;\n  label: string;\n  description?: string;\n  fill?: ResolvedFill;\n  selected: boolean;\n}) {\n  return (\n    <RadioGroupCard\n      value={value}\n      data-testid={`backdrop-${value}`}\n      data-selected={selected}\n      className=\"flex flex-col gap-3 rounded-lg p-3\"\n    >\n      <Preview fill={fill} />\n      <span className=\"flex items-center gap-2\">\n        <span className=\"flex min-w-0 flex-1 flex-col\">\n          <span className=\"truncate text-base font-semibold text-po-hi\">{label}</span>\n          {description ? <span className=\"text-sm text-po-dim\">{description}</span> : null}\n        </span>\n        {selected ? <CheckIcon className=\"size-4 shrink-0 text-po-green\" /> : null}\n      </span>\n    </RadioGroupCard>\n  );\n}\n\n/**\n * The one background behind every template. Picking a card saves it to the global config at once,\n * like a theme, so there is nothing to confirm. Exactly one shows; installing a package never\n * switches it on its own.\n */\nexport function BackdropSettings() {\n  const t = useT();\n  useWebPluginRegistry();\n  const configuration = useTemplateConfiguration();\n  const fills = hostSlotFills(HOST_SLOTS.backdrop).filter((fill) => fill.component !== undefined);\n  const configured = configuredBackdrop(configuration);\n  const shown = resolveBackdrop(fills, configured);\n  const current = shown === undefined ? NO_BACKDROP : backdropId(shown);\n  const bamboo = fills.find((fill) => backdropId(fill) === DEFAULT_BACKDROP_ID);\n  const fromPlugins = fills.filter((fill) => fill !== bamboo);\n  const busy = configuration.saving || configuration.loading || configuration.config === undefined;\n  const choose = (value: string): void => {\n    void saveBackdropDefault(value).then((saved) => {\n      if (saved) void reloadWebTemplateDecision();\n    });\n  };\n  const group = 'grid grid-cols-1 gap-3 @md:grid-cols-2 @2xl:grid-cols-3';\n  return (\n    <SettingsSection data-testid=\"backdrop-settings\" className=\"@container\">\n      <SettingsSectionHeader>\n        <SettingsSectionTitle>{t('webDashboard.settings.backdrop.title', 'Background')}</SettingsSectionTitle>\n        <SettingsSectionDescription>\n          {t(\n            'webDashboard.settings.backdrop.description',\n            'What Po shows behind every layout. Applies straight away and is saved to your Po config.',\n          )}\n        </SettingsSectionDescription>\n      </SettingsSectionHeader>\n      <RadioGroup\n        aria-label={t('webDashboard.settings.backdrop.title', 'Background')}\n        className={group}\n        value={current}\n        onValueChange={choose}\n        disabled={busy}\n      >\n        {bamboo ? (\n          <BackdropCard\n            value={DEFAULT_BACKDROP_ID}\n            {...describe(bamboo)}\n            fill={bamboo}\n            selected={current === DEFAULT_BACKDROP_ID}\n          />\n        ) : null}\n        <BackdropCard\n          value={NO_BACKDROP}\n          label={t('webDashboard.settings.backdrop.plain', 'Plain')}\n          description={t('webDashboard.settings.backdrop.plainDetail', 'Just the theme colour.')}\n          selected={current === NO_BACKDROP}\n        />\n      </RadioGroup>\n      {fromPlugins.length > 0 ? (\n        <>\n          <SettingsSectionTitle>\n            {t('webDashboard.settings.appearance.fromPlugins', 'From your plugins')}\n          </SettingsSectionTitle>\n          <RadioGroup\n            aria-label={t('webDashboard.settings.backdrop.pluginBackdrops', 'Backgrounds from your plugins')}\n            className={group}\n            value={current}\n            onValueChange={choose}\n            disabled={busy}\n          >\n            {fromPlugins.map((fill) => (\n              <BackdropCard\n                key={backdropId(fill)}\n                value={backdropId(fill)}\n                {...describe(fill)}\n                fill={fill}\n                selected={current === backdropId(fill)}\n              />\n            ))}\n          </RadioGroup>\n        </>\n      ) : null}\n      {configured !== undefined && configured !== NO_BACKDROP && configured !== current ? (\n        <output className=\"block text-sm text-po-yellow\">\n          {t('webDashboard.settings.backdrop.missingStart', 'The background')}{' '}\n          <code className=\"font-mono\">{configured}</code>{' '}\n          {t('webDashboard.settings.backdrop.missingEnd', 'is not installed here, so {name} shows instead.', {\n            name:\n              shown === undefined\n                ? t('webDashboard.settings.backdrop.plainOne', 'the plain one')\n                : describe(shown).label,\n          })}\n        </output>\n      ) : null}\n      {configuration.error ? (\n        <p role=\"alert\" data-testid=\"backdrop-save-error\" className=\"text-sm text-po-red\">\n          {configuration.error}\n        </p>\n      ) : null}\n      <SettingsNote>\n        {t('webDashboard.settings.backdrop.noteSavedTo', 'Saved to')}{' '}\n        <code className=\"font-mono\">~/.po/config.yaml</code> {t('webDashboard.settings.backdrop.noteAs', 'as')}{' '}\n        <code className=\"font-mono\">web.backdrop</code>.{' '}\n        {t('webDashboard.settings.backdrop.noteAddOwn', 'Add your own from a global plugin with a')}{' '}\n        <code className=\"font-mono\">backdrop</code> {t('webDashboard.settings.backdrop.noteFill', 'fill.')}\n      </SettingsNote>\n    </SettingsSection>\n  );\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,SAAS,SAAS,MAA6D;CAC7E,MAAM,OAAQ,OAAO,KAAK,SAAS,YAAY,KAAK,SAAS,OAAO,KAAK,OAAO,CAAC;CACjF,OAAO;EACL,OAAO,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,WAAW,IAAI;EACpE,GAAI,OAAO,KAAK,gBAAgB,WAAW,EAAE,aAAa,KAAK,YAAY,IAAI,CAAC;CAClF;AACF;;AAGA,SAAS,QAAQ,EAAE,QAAiC;CAClD,MAAM,QAAQ,mBAAmB,IAAI;CACrC,MAAM,OAAO,MAAM;CACnB,OACE,oBAAC,OAAD;EAAK,eAAA;EAAY,WAAU;EACxB,UAAA,QAAQ,OACP,oBAAC,sBAAD;GAAsB,UAAU,WAAW,IAAI;GAC3C,WAAA,WAAY,SAAS,OAAO,oBAAC,MAAD,EAAM,GAAI,MAAQ,CAAA;EAC5B,CAAA,IACpB;CACD,CAAA;AAET;AAEA,SAAS,aAAa,EACpB,OACA,OACA,aACA,MACA,YAOC;CACD,OACE,qBAAC,gBAAD;EACS;EACP,eAAa,YAAY;EACzB,iBAAe;EACf,WAAU;EAJZ,UAAA,CAME,oBAAC,SAAD,EAAe,KAAO,CAAA,GACtB,qBAAC,QAAD;GAAM,WAAU;GAAhB,UAAA,CACE,qBAAC,QAAD;IAAM,WAAU;IAAhB,UAAA,CACE,oBAAC,QAAD;KAAM,WAAU;KAA+C,UAAA;IAAY,CAAA,GAC1E,cAAc,oBAAC,QAAD;KAAM,WAAU;KAAuB,UAAA;IAAkB,CAAA,IAAI,IACxE;GACL,CAAA,GAAA,WAAW,oBAAC,WAAD,EAAW,WAAU,gCA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