{"version":3,"file":"BackdropSettings.cjs","names":["backdropId","usePluginSlotProps","ToolRendererBoundary","RadioGroupCard","CheckIcon","useT","useTemplateConfiguration","hostSlotFills","HOST_SLOTS","configuredBackdrop","resolveBackdrop","NO_BACKDROP","DEFAULT_BACKDROP_ID","saveBackdropDefault","reloadWebTemplateDecision","SettingsSection","SettingsSectionHeader","SettingsSectionTitle","SettingsSectionDescription","RadioGroup","SettingsNote"],"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,QAAQA,wBAAAA,WAAW,IAAI;EACpE,GAAI,OAAO,KAAK,gBAAgB,WAAW,EAAE,aAAa,KAAK,YAAY,IAAI,CAAC;CAClF;AACF;;AAGA,SAAS,QAAQ,EAAE,QAAiC;CAClD,MAAM,QAAQC,2BAAAA,mBAAmB,IAAI;CACrC,MAAM,OAAO,MAAM;CACnB,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EAAK,eAAA;EAAY,WAAU;EACxB,UAAA,QAAQ,OACP,iBAAA,GAAA,kBAAA,IAAA,CAACC,6BAAAA,sBAAD;GAAsB,UAAUF,wBAAAA,WAAW,IAAI;GAC3C,WAAA,WAAY,SAAS,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,MAAD,EAAM,GAAI,MAAQ,CAAA;EAC5B,CAAA,IACpB;CACD,CAAA;AAET;AAEA,SAAS,aAAa,EACpB,OACA,OACA,aACA,MACA,YAOC;CACD,OACE,iBAAA,GAAA,kBAAA,KAAA,CAACG,6B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