// Copyright: © 2026 TWWIM UG. All rights reserved. (www.twwim.com) /** * SnippetSection — server-controlled snippet runtime configuration. * * Operates on `form.snippet`. Renders: * - theme: 1..50 chars / /^[a-z0-9-]+$/i, text input * - dock: select with the 10 dock positions * - uiCacheTTL: bounded NumberInput (0..86400) * - scenario: optional text input (empty → null) * - domIndexer: sr-only peer-style switch * - deploymentTarget: select with (none) + Shopify * * @layer Presentation */ import type { Dispatch, SetStateAction } from 'react'; import { DOCK_OPTIONS, type FormState, type TFunction, } from '../lib/constants'; import { NumberInput } from './NumberInput'; interface SnippetSectionProps { form: FormState; setForm: Dispatch>; t: TFunction; } const THEME_REGEX = /^[a-z0-9-]+$/i; export function SnippetSection({ form, setForm, t }: SnippetSectionProps) { const snippet = form.snippet; const updateSnippet = (changes: Partial): void => { setForm({ ...form, snippet: { ...snippet, ...changes }, }); }; const themeInvalid = snippet.theme.length < 1 || snippet.theme.length > 50 || !THEME_REGEX.test(snippet.theme); const scenarioInvalid = snippet.scenario !== null && (snippet.scenario.length < 1 || snippet.scenario.length > 50); return (

{t('tenants.pluginSettings.snippet.section')}

{t('tenants.pluginSettings.snippet.sectionHint')}

{/* theme */}
updateSnippet({ theme: e.target.value })} className={`w-full px-3 py-2 text-sm border rounded-lg focus:ring-2 focus:ring-cyan-500 focus:outline-none ${ themeInvalid ? 'border-red-400 bg-red-50' : 'border-gray-300 bg-white' }`} />

{t('tenants.pluginSettings.snippet.themeHelp')}

{/* dock */}

{t('tenants.pluginSettings.snippet.dockHelp')}

{/* uiCacheTTL */} updateSnippet({ uiCacheTTL: v })} /> {/* scenario */}
{ const next = e.target.value; updateSnippet({ scenario: next.length === 0 ? null : next }); }} className={`w-full px-3 py-2 text-sm border rounded-lg focus:ring-2 focus:ring-cyan-500 focus:outline-none ${ scenarioInvalid ? 'border-red-400 bg-red-50' : 'border-gray-300 bg-white' }`} />

{t('tenants.pluginSettings.snippet.scenarioHelp')}

{/* domIndexer */}

{t('tenants.pluginSettings.snippet.domIndexerLabel')}

{t('tenants.pluginSettings.snippet.domIndexerHelp')}

{/* deploymentTarget */}

{t('tenants.pluginSettings.snippet.deploymentTargetHelp')}

); }