{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "localization-settings",
  "title": "Localization settings",
  "description": "Languages table with completion bars, publish and default controls, auto-translate progress, an add-language dialog and a booking-page preview that flips to RTL.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/badge.json",
    "https://goodui.dev/r/button.json",
    "https://goodui.dev/r/dialog.json",
    "https://goodui.dev/r/dropdown-menu.json",
    "https://goodui.dev/r/select.json",
    "https://goodui.dev/r/switch.json",
    "label"
  ],
  "files": [
    {
      "path": "registry/blocks/settings/localization-settings.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ArrowLeftRight, CalendarDays, Check, Languages, MoreHorizontal, Plus, Sparkles, Star, Trash2 } from \"lucide-react\"\nimport { Label } from \"@/components/ui/label\"\nimport { Badge } from \"@/components/goodui/badge\"\nimport { Button } from \"@/components/goodui/button\"\nimport { Dialog } from \"@/components/goodui/dialog\"\nimport { DropdownMenu } from \"@/components/goodui/dropdown-menu\"\nimport { Select } from \"@/components/goodui/select\"\nimport { Switch } from \"@/components/goodui/switch\"\nimport { cn } from \"@/lib/utils\"\n\n/* ---------- Demo data ---------- */\n\ntype Lang = { code: string; name: string; native: string; completion: number; published: boolean; updated: string; rtl?: boolean; translating?: boolean }\n\nconst LANGS: Lang[] = [\n  { code: \"en\", name: \"English\", native: \"English\", completion: 100, published: true, updated: \"Source\" },\n  { code: \"de\", name: \"German\", native: \"Deutsch\", completion: 100, published: true, updated: \"2 days ago\" },\n  { code: \"fr\", name: \"French\", native: \"Français\", completion: 92, published: true, updated: \"1 week ago\" },\n  { code: \"es\", name: \"Spanish\", native: \"Español\", completion: 64, published: false, updated: \"3 weeks ago\" },\n  { code: \"ar\", name: \"Arabic\", native: \"العربية\", completion: 38, published: false, updated: \"Yesterday\", rtl: true },\n]\n\nconst CATALOG = [\n  { value: \"it\", label: \"Italian\", description: \"Italiano\" },\n  { value: \"pt\", label: \"Portuguese\", description: \"Português\" },\n  { value: \"nl\", label: \"Dutch\", description: \"Nederlands\" },\n  { value: \"tr\", label: \"Turkish\", description: \"Türkçe\" },\n  { value: \"pl\", label: \"Polish\", description: \"Polski\" },\n  { value: \"he\", label: \"Hebrew\", description: \"עברית\", keywords: [\"rtl\"] },\n  { value: \"ja\", label: \"Japanese\", description: \"日本語\" },\n  { value: \"ko\", label: \"Korean\", description: \"한국어\" },\n  { value: \"sv\", label: \"Swedish\", description: \"Svenska\" },\n]\nconst RTL_CODES = new Set([\"ar\", \"he\", \"fa\", \"ur\"])\n\nconst STRINGS: Record<string, { title: string; cta: string; with: string; at: string }> = {\n  en: { title: \"Book your next visit\", cta: \"Choose a time\", with: \"with Mira\", at: \"Thu 14 Mar · 10:30\" },\n  de: { title: \"Nächsten Termin buchen\", cta: \"Zeit wählen\", with: \"bei Mira\", at: \"Do. 14. März · 10:30\" },\n  fr: { title: \"Réservez votre prochaine visite\", cta: \"Choisir un créneau\", with: \"avec Mira\", at: \"jeu. 14 mars · 10:30\" },\n  es: { title: \"Reserva tu próxima visita\", cta: \"Elegir hora\", with: \"con Mira\", at: \"jue. 14 mar · 10:30\" },\n  ar: { title: \"احجز زيارتك القادمة\", cta: \"اختر وقتًا\", with: \"مع ميرا\", at: \"الخميس ١٤ مارس · ١٠:٣٠\" },\n}\n\n/* ---------- Pieces ---------- */\n\nfunction LangDot({ code, rtl }: { code: string; rtl?: boolean }) {\n  const hue = (code.charCodeAt(0) * 37 + (code.charCodeAt(1) ?? 0) * 11) % 360\n  return (\n    <span className=\"relative flex size-9 shrink-0 items-center justify-center rounded-full text-xs font-bold text-white uppercase\" style={{ background: `oklch(0.48 0.15 ${hue})` }} aria-hidden=\"true\">\n      {code}\n      {rtl && <span className=\"absolute -right-0.5 -bottom-0.5 flex size-4 items-center justify-center rounded-full border-2 border-card bg-foreground text-[8px] text-background\">R</span>}\n    </span>\n  )\n}\n\nfunction CompletionBar({ value }: { value: number }) {\n  return (\n    <div className=\"flex items-center gap-2\">\n      <div className=\"h-2 w-28 overflow-hidden rounded-full bg-muted\" role=\"progressbar\" aria-valuenow={value} aria-valuemin={0} aria-valuemax={100} aria-label=\"Translation completion\">\n        <div className={cn(\"h-full rounded-full transition-all duration-500\", value === 100 ? \"bg-emerald-500\" : value >= 70 ? \"bg-sky-500\" : \"bg-amber-500\")} style={{ width: `${value}%` }} />\n      </div>\n      <span className=\"w-9 text-xs tabular-nums text-muted-foreground\">{value}%</span>\n    </div>\n  )\n}\n\n/* ---------- Block ---------- */\n\nexport default function LocalizationSettings() {\n  const [langs, setLangs] = React.useState(LANGS)\n  const [defaultCode, setDefaultCode] = React.useState(\"en\")\n  const [preview, setPreview] = React.useState(\"en\")\n  const [forceRtl, setForceRtl] = React.useState(false)\n  const [addOpen, setAddOpen] = React.useState(false)\n  const [addCode, setAddCode] = React.useState<string | null>(null)\n  const [removeTarget, setRemoveTarget] = React.useState<Lang | null>(null)\n  const [toast, setToast] = React.useState<string | null>(null)\n\n  const flash = (m: string) => {\n    setToast(m)\n    setTimeout(() => setToast(null), 2400)\n  }\n\n  const current = langs.find((l) => l.code === preview) ?? langs[0]\n  const rtl = forceRtl || !!current?.rtl\n  const strings = STRINGS[preview] ?? STRINGS.en!\n  const available = CATALOG.filter((c) => !langs.some((l) => l.code === c.value))\n\n  const autoTranslate = (code: string) => {\n    setLangs((list) => list.map((l) => (l.code === code ? { ...l, translating: true } : l)))\n    let step = 0\n    const tick = () => {\n      step++\n      setLangs((list) =>\n        list.map((l) => {\n          if (l.code !== code) return l\n          const next = Math.min(100, l.completion + 12)\n          const done = next >= 100 || step > 8\n          return { ...l, completion: done ? 100 : next, translating: !done, updated: done ? \"Just now\" : l.updated }\n        }),\n      )\n      if (step <= 8) setTimeout(tick, 260)\n    }\n    setTimeout(tick, 260)\n  }\n\n  const addLanguage = () => {\n    const c = available.find((x) => x.value === addCode)\n    if (!c) throw new Error(\"Pick a language first\")\n    setLangs((list) => [...list, { code: c.value, name: c.label, native: c.description ?? c.label, completion: 0, published: false, updated: \"Just now\", rtl: RTL_CODES.has(c.value) }])\n    setAddCode(null)\n    flash(`${c.label} added. Run auto-translate to get a first draft.`)\n  }\n\n  return (\n    <div className=\"p-4 md:p-6\">\n      <div className=\"mx-auto max-w-6xl\">\n        <div className=\"flex flex-wrap items-end justify-between gap-3\">\n          <div>\n            <h2 className=\"font-heading text-xl font-semibold tracking-tight\">Languages</h2>\n            <p className=\"text-sm text-muted-foreground\">Your booking page, emails and reminders in each client's language.</p>\n          </div>\n          <Button iconLeft={<Plus />} onClick={() => setAddOpen(true)} disabled={available.length === 0}>\n            Add language\n          </Button>\n        </div>\n\n        {toast && (\n          <p role=\"status\" className=\"mt-4 rounded-xl bg-emerald-500/10 px-3 py-2 text-sm text-emerald-700 dark:text-emerald-300\">\n            {toast}\n          </p>\n        )}\n\n        <div className=\"mt-5 grid gap-5 lg:grid-cols-[1fr_340px]\">\n          {/* Table */}\n          <div className=\"min-w-0 overflow-hidden rounded-2xl border bg-card shadow-sm\">\n            <ul className=\"divide-y\" aria-label=\"Languages\">\n              {langs.map((l) => {\n                const isDefault = l.code === defaultCode\n                return (\n                  <li key={l.code} className={cn(\"grid items-center gap-3 px-4 py-3 sm:grid-cols-[auto_1fr_auto_auto] sm:gap-4\", preview === l.code && \"bg-muted/30\")}>\n                    <div className=\"flex items-center gap-3 sm:contents\">\n                      <LangDot code={l.code} rtl={l.rtl} />\n                      <div className=\"min-w-0\">\n                        <p className=\"flex flex-wrap items-center gap-1.5 text-sm font-medium\">\n                          <span className=\"truncate\">{l.name}</span>\n                          <span className=\"font-normal text-muted-foreground\" lang={l.code}>\n                            {l.native}\n                          </span>\n                          {isDefault && (\n                            <Badge tone=\"primary\" size=\"xs\" icon={<Star className=\"size-3\" />}>\n                              Default\n                            </Badge>\n                          )}\n                          {l.published ? (\n                            <Badge tone=\"success\" variant=\"dot\" size=\"xs\">\n                              Published\n                            </Badge>\n                          ) : (\n                            <Badge tone=\"neutral\" variant=\"dot\" size=\"xs\">\n                              Draft\n                            </Badge>\n                          )}\n                        </p>\n                        <p className=\"text-xs text-muted-foreground\">\n                          {l.rtl ? \"Right to left · \" : \"\"}Updated {l.updated}\n                        </p>\n                      </div>\n                    </div>\n                    <CompletionBar value={l.completion} />\n                    <div className=\"flex items-center justify-end gap-1 sm:w-[236px]\">\n                      <Button size=\"xs\" variant={preview === l.code ? \"soft\" : \"ghost\"} tone=\"neutral\" onClick={() => setPreview(l.code)} aria-pressed={preview === l.code}>\n                        Preview\n                      </Button>\n                      {l.completion < 100 ? (\n                        <Button size=\"xs\" variant=\"soft\" tone=\"primary\" iconLeft={<Sparkles />} loading={l.translating} onClick={() => autoTranslate(l.code)} className=\"w-[118px]\">\n                          Auto-translate\n                        </Button>\n                      ) : !l.published ? (\n                        <Button size=\"xs\" variant=\"soft\" tone=\"success\" iconLeft={<Check />} className=\"w-[118px]\" onClick={() => { setLangs((list) => list.map((x) => (x.code === l.code ? { ...x, published: true } : x))); flash(`${l.name} is now live on your booking page`) }}>\n                          Publish\n                        </Button>\n                      ) : (\n                        <span className=\"inline-flex w-[118px] items-center justify-center gap-1 text-xs text-emerald-700 dark:text-emerald-300\">\n                          <Check className=\"size-3.5\" /> Complete\n                        </span>\n                      )}\n                      <DropdownMenu\n                        trigger={\n                          <Button size=\"xs\" variant=\"ghost\" tone=\"neutral\" iconOnly aria-label={`More actions for ${l.name}`}>\n                            <MoreHorizontal />\n                          </Button>\n                        }\n                        align=\"end\"\n                        items={[\n                          { label: \"Make default\", icon: <Star className=\"size-4\" />, disabled: isDefault || !l.published, onSelect: () => { setDefaultCode(l.code); flash(`${l.name} is the default language`) } },\n                          { label: l.published ? \"Unpublish\" : \"Publish\", icon: <Check className=\"size-4\" />, disabled: isDefault || l.completion < 100, onSelect: () => setLangs((list) => list.map((x) => (x.code === l.code ? { ...x, published: !x.published } : x))) },\n                          { type: \"separator\" },\n                          { label: \"Remove language\", icon: <Trash2 className=\"size-4\" />, destructive: true, disabled: isDefault, onSelect: () => setRemoveTarget(l) },\n                        ]}\n                      />\n                    </div>\n                  </li>\n                )\n              })}\n            </ul>\n            <div className=\"flex flex-wrap items-center gap-3 border-t bg-muted/30 px-4 py-3 text-sm\">\n              <Languages className=\"size-4 text-muted-foreground\" />\n              <Label htmlFor=\"ls-fallback\" className=\"text-muted-foreground\">\n                When a string is missing, show it in\n              </Label>\n              <Select id=\"ls-fallback\" size=\"sm\" options={langs.filter((l) => l.completion === 100).map((l) => ({ value: l.code, label: l.name }))} value={defaultCode} onValueChange={(v) => v && setDefaultCode(v)} className=\"w-40\" />\n            </div>\n          </div>\n\n          {/* Preview */}\n          <div className=\"grid content-start gap-3\">\n            <div className=\"flex items-center justify-between\">\n              <p className=\"text-sm font-medium\">Booking page preview</p>\n              <Badge tone=\"neutral\" variant=\"outline\" size=\"xs\">\n                {current?.name} · {rtl ? \"RTL\" : \"LTR\"}\n              </Badge>\n            </div>\n            <div dir={rtl ? \"rtl\" : \"ltr\"} lang={preview} className=\"rounded-2xl border bg-card p-4 shadow-sm transition-all\">\n              <div className=\"flex items-center gap-3\">\n                <span className=\"flex size-10 items-center justify-center rounded-xl bg-gradient-to-br from-[var(--chart-1)] to-[var(--chart-4)] font-heading text-sm font-bold text-white\">N</span>\n                <div className=\"min-w-0 flex-1\">\n                  <p className=\"truncate text-sm font-semibold\">Nova Salon</p>\n                  <p className=\"truncate text-xs text-muted-foreground\">{strings.with}</p>\n                </div>\n                <Star className=\"size-4 fill-amber-400 text-amber-400\" aria-hidden=\"true\" />\n              </div>\n              <h4 className=\"mt-4 font-heading text-lg font-semibold\">{strings.title}</h4>\n              <div className=\"mt-3 flex items-center gap-2 rounded-xl border bg-muted/40 p-3 text-sm\">\n                <CalendarDays className=\"size-4 text-muted-foreground\" />\n                <span className=\"flex-1\">{strings.at}</span>\n                <span className=\"text-xs text-muted-foreground\">45 min</span>\n              </div>\n              <Button fullWidth className=\"mt-3\" iconRight={<ArrowLeftRight className={cn(rtl && \"rotate-180\")} />}>\n                {strings.cta}\n              </Button>\n              {(current?.completion ?? 100) < 100 && <p className=\"mt-2 text-center text-[11px] text-muted-foreground\">{100 - (current?.completion ?? 100)}% of strings fall back to {langs.find((l) => l.code === defaultCode)?.name}</p>}\n            </div>\n            <Switch label=\"Force right-to-left\" description=\"Check how layouts mirror before adding Arabic or Hebrew.\" labelPosition=\"left\" size=\"sm\" checked={forceRtl} onCheckedChange={setForceRtl} className=\"rounded-xl border p-3\" />\n          </div>\n        </div>\n      </div>\n\n      <Dialog open={addOpen} onOpenChange={setAddOpen} title=\"Add a language\" description=\"We create a draft from your English source. Publish once a native speaker has reviewed it.\" icon={<Languages />} confirmText=\"Add language\" onConfirm={addLanguage}>\n        <div className=\"grid gap-1.5\">\n          <Label htmlFor=\"ls-add\">Language</Label>\n          <Select id=\"ls-add\" options={available} value={addCode} onValueChange={setAddCode} placeholder=\"Search languages\" searchable searchPlaceholder=\"Type to search\" className=\"w-full\" />\n        </div>\n      </Dialog>\n\n      <Dialog open={!!removeTarget} onOpenChange={(o) => !o && setRemoveTarget(null)} role=\"alertdialog\" tone=\"danger\" icon={<Trash2 />} title={`Remove ${removeTarget?.name ?? \"\"}?`} description=\"Clients using it see the default language instead. Translations are deleted after 30 days.\" confirmText=\"Remove\" onConfirm={() => { setLangs((list) => list.filter((x) => x.code !== removeTarget?.code)); if (preview === removeTarget?.code) setPreview(defaultCode) }} />\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/localization-settings.tsx"
    }
  ],
  "categories": [
    "settings"
  ],
  "type": "registry:block"
}
