{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"settings-accordion-with-nested-sections","type":"registry:block","title":"Settings Accordion With Nested Sections","description":"","dependencies":[],"files":[{"path":"components/we-inc/settings-accordion-with-nested-sections.tsx","type":"registry:component","content":"import { useState } from \"react\";\n\ntype Row = { id: string; label: string; hint: string; on: boolean };\ntype Group = { id: string; title: string; summary: string; rows: Row[] };\n\nconst groups: Group[] = [\n  { id: \"notify\", title: \"Notifications\", summary: \"Email, push and the weekly digest\", rows: [\n    { id: \"n1\", label: \"New booking\", hint: \"Email me the moment a client books a slot\", on: true },\n    { id: \"n2\", label: \"Cancellations\", hint: \"Push alert when a booking is cancelled\", on: true },\n    { id: \"n3\", label: \"Weekly digest\", hint: \"A Monday summary of last week's sessions\", on: false },\n  ] },\n  { id: \"privacy\", title: \"Privacy\", summary: \"Who can see your profile and calendar\", rows: [\n    { id: \"p1\", label: \"Public profile\", hint: \"Show your page in the studio directory\", on: true },\n    { id: \"p2\", label: \"Show full calendar\", hint: \"Let clients see busy times, not just free ones\", on: false },\n  ] },\n  { id: \"billing\", title: \"Billing\", summary: \"Invoices, receipts and payment reminders\", rows: [\n    { id: \"b1\", label: \"Send receipts\", hint: \"Email clients a receipt after each payment\", on: true },\n    { id: \"b2\", label: \"Overdue reminders\", hint: \"Nudge clients three days after an unpaid invoice\", on: false },\n  ] },\n];\n\nfunction Chevron({ open }: { open: boolean }) {\n  return (\n    <svg viewBox=\"0 0 20 20\" className={`h-5 w-5 shrink-0 text-slate-500 transition-transform duration-200 motion-reduce:transition-none ${open ? \"rotate-90\" : \"\"}`} fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" aria-hidden=\"true\">\n      <path d=\"M7.5 5l5 5-5 5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\n\nexport default function SettingsAccordionWithNestedSections() {\n  const [openGroups, setOpenGroups] = useState<string[]>([\"notify\"]);\n  const [values, setValues] = useState<Record<string, boolean>>(() =>\n    Object.fromEntries(groups.flatMap((g) => g.rows.map((r) => [r.id, r.on]))),\n  );\n  const flip = (id: string) => setOpenGroups((g) => (g.includes(id) ? g.filter((x) => x !== id) : [...g, id]));\n  return (\n    <section className=\"bg-violet-50 px-5 py-14 sm:py-20\">\n      <div className=\"mx-auto max-w-xl rounded-2xl border border-violet-100 bg-white p-2 shadow-sm\">\n        <div className=\"px-4 pb-3 pt-4\">\n          <h2 className=\"text-lg font-semibold text-slate-900\">Settings</h2>\n          <p className=\"text-sm text-slate-600\">Juniper Pilates, instructor account</p>\n        </div>\n        {groups.map((g) => {\n          const open = openGroups.includes(g.id);\n          const count = g.rows.filter((r) => values[r.id]).length;\n          return (\n            <div key={g.id} className=\"border-t border-slate-100\">\n              <h3>\n                <button\n                  type=\"button\"\n                  id={`nsa-${g.id}`}\n                  aria-expanded={open}\n                  aria-controls={`nsa-${g.id}-rows`}\n                  onClick={() => flip(g.id)}\n                  className=\"flex min-h-[64px] w-full items-center gap-3 rounded-xl px-4 py-3 text-left hover:bg-slate-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-violet-600\"\n                >\n                  <Chevron open={open} />\n                  <span className=\"flex-1\">\n                    <span className=\"block text-[15px] font-semibold text-slate-900\">{g.title}</span>\n                    <span className=\"block text-sm text-slate-600\">{g.summary}</span>\n                  </span>\n                  <span className=\"rounded-full bg-violet-100 px-2.5 py-0.5 text-xs font-medium text-violet-800\">{count} on</span>\n                </button>\n              </h3>\n              {open && (\n                <ul id={`nsa-${g.id}-rows`} role=\"region\" aria-labelledby={`nsa-${g.id}`} className=\"mb-2 ml-11 mr-2 border-l border-violet-200\">\n                  {g.rows.map((r) => (\n                    <li key={r.id} className=\"flex items-center gap-4 py-3 pl-4 pr-2\">\n                      <span className=\"flex-1\">\n                        <span id={`nsa-l-${r.id}`} className=\"block text-sm font-medium text-slate-900\">{r.label}</span>\n                        <span className=\"block text-[13px] text-slate-600\">{r.hint}</span>\n                      </span>\n                      <button\n                        type=\"button\"\n                        role=\"switch\"\n                        aria-checked={values[r.id]}\n                        aria-labelledby={`nsa-l-${r.id}`}\n                        onClick={() => setValues((v) => ({ ...v, [r.id]: !v[r.id] }))}\n                        className={`relative h-6 w-11 shrink-0 rounded-full transition-colors motion-reduce:transition-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-violet-600 focus-visible:ring-offset-2 ${values[r.id] ? \"bg-violet-600\" : \"bg-slate-300\"}`}\n                      >\n                        <span className={`absolute left-0.5 top-0.5 h-5 w-5 rounded-full bg-white shadow transition-transform motion-reduce:transition-none ${values[r.id] ? \"translate-x-5\" : \"\"}`} />\n                      </button>\n                    </li>\n                  ))}\n                </ul>\n              )}\n            </div>\n          );\n        })}\n      </div>\n    </section>\n  );\n}\n"}]}
