{
  "$schema": "https://zoblocks.design/schema/registry-item.json",
  "name": "safety-plan",
  "type": "zoblocks:component",
  "title": "Safety Plan",
  "description": "A patient-facing safety plan: warning signs, coping, distraction, people to ask, professionals and agencies, and means restriction. The crisis step cannot be collapsed, empty steps say they are unfinished rather than disappearing, and the wording is a patient catalog throughout.",
  "categories": [
    "disclosure",
    "clinical"
  ],
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "registryDependencies": [
    "utils",
    "tokens",
    "accordion-core",
    "accordion"
  ],
  "files": [
    {
      "path": "registry/zoblocks/safety-plan/safety-plan.tsx",
      "type": "zoblocks:component",
      "target": "components/zoblocks/safety-plan.tsx",
      "content": "\"use client\";\n\n/**\n * SafetyPlan — the six steps, with the fifth one open.\n *\n * The Stanley-Brown Safety Planning Intervention is six ordered steps: warning\n * signs, internal coping, people and settings that distract, people to ask for\n * help, professionals and agencies, and making the environment safer. It is\n * written collaboratively in a room and read alone, often on a phone, often at\n * the worst hour of someone's week.\n *\n * That reading context is the entire design.\n *\n *   **Step five does not collapse.** It holds the crisis numbers. A person in\n *   crisis does not scroll, does not scan, and should not have to make a\n *   correct decision about a chevron to reach a phone number. The step renders\n *   open and its trigger reports itself disabled — which is exactly the case\n *   APG carves out for aria-disabled: the panel is visible and the accordion\n *   prevents collapsing it.\n *\n *   **The order is the intervention, not a layout.** Steps are rendered in the\n *   sequence the instrument defines. The component does not sort, filter, or\n *   let a caller reorder them, because the escalation from \"things I can do\n *   alone\" to \"who I call\" is the clinical content.\n *\n *   **A missing step is stated, not skipped.** A plan written in one sitting\n *   often has gaps. Rendering five steps and numbering them 1–5 would claim the\n *   sixth was never part of the instrument. Each empty step says it is not\n *   filled in yet, which is also the prompt to finish it.\n *\n * Wording here is patient-facing and second person throughout — a different\n * catalog from the clinician's, not a softened version of it (CONTENT.md §7).\n */\n\nimport * as React from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport { Accordion, type AccordionDensity } from \"@/components/zoblocks/accordion\";\nimport type { AccordionHeadingLevel, AccordionItem } from \"@/lib/zoblocks-accordion\";\n\n/** A person or service the plan names. */\nexport interface SafetyPlanContact {\n  name: string;\n  /** How to reach them, as the plan records it. Rendered verbatim. */\n  detail?: string;\n  /** When they are reachable. \"24 hours\" is a fact worth stating. */\n  availability?: string;\n}\n\nexport interface SafetyPlanStepContent {\n  /** Free text the person wrote. */\n  entries?: readonly string[];\n  /** People and services, for the steps that hold them. */\n  contacts?: readonly SafetyPlanContact[];\n}\n\nexport type SafetyPlanStepKey =\n  | \"warningSigns\"\n  | \"internalCoping\"\n  | \"distractions\"\n  | \"supportContacts\"\n  | \"professionals\"\n  | \"environment\";\n\nexport type SafetyPlanSteps = Partial<Record<SafetyPlanStepKey, SafetyPlanStepContent>>;\n\nexport interface SafetyPlanLabels {\n  warningSigns: string;\n  internalCoping: string;\n  distractions: string;\n  supportContacts: string;\n  professionals: string;\n  environment: string;\n  /** Shown on the pinned crisis step. */\n  alwaysOpen: string;\n  /** Shown on the crisis step when it is not pinned, so the rail still has words. */\n  crisisStep: string;\n  /** Shown on a step nobody has filled in yet. */\n  empty: string;\n  /** Reassurance under the crisis step, so the pinning does not read as a glitch. */\n  pinnedExplanation: string;\n  revised: (date: string) => string;\n}\n\n/**\n * The six steps in the instrument's order. Exported so a product can label them\n * in its own words without being able to change the sequence.\n */\nexport const SAFETY_PLAN_STEP_ORDER: readonly SafetyPlanStepKey[] = [\n  \"warningSigns\",\n  \"internalCoping\",\n  \"distractions\",\n  \"supportContacts\",\n  \"professionals\",\n  \"environment\",\n];\n\nexport const DEFAULT_SAFETY_PLAN_LABELS: SafetyPlanLabels = {\n  warningSigns: \"Signs that things are getting harder\",\n  internalCoping: \"Things I can do on my own\",\n  distractions: \"People and places that take my mind off it\",\n  supportContacts: \"People I can ask for help\",\n  professionals: \"If none of that is working\",\n  environment: \"Making home safer\",\n  alwaysOpen: \"Always open\",\n  crisisStep: \"Crisis contacts\",\n  empty: \"Not filled in yet. You can add to this with your clinician.\",\n  pinnedExplanation: \"This part of your plan stays open. You do not have to look for it.\",\n  revised: (date) => `Revised ${date}`,\n};\n\nexport interface SafetyPlanProps extends Omit<\n  React.HTMLAttributes<HTMLDivElement>,\n  \"children\" | \"onChange\"\n> {\n  /**\n   * The six Stanley-Brown steps, in order. The order is the intervention; a plan rendered out\n   * of sequence is a different document.\n   */\n  steps: SafetyPlanSteps;\n  /** ISO 8601. Shown so a reader knows how current the plan is. */\n  revisedAt?: string;\n  /** Replaces the built-in patient-facing wording. */\n  labels?: Partial<SafetyPlanLabels>;\n  /**\n   * Keep the crisis step open and uncloseable.\n   *\n   * Defaults to true and should stay true on any surface a person in crisis\n   * might open. Turning it off is for a clinician's editing view, where every\n   * step is being worked on and none of them is the emergency.\n   */\n  pinCrisisStep?: boolean;\n  /**\n   * Where the plan's headings sit in the page outline. Set it to match the surrounding\n   * document rather than letting a plan start at h1 inside a chart.\n   */\n  headingLevel?: AccordionHeadingLevel;\n  /** Row height and type scale. Inherited from the nearest density provider when omitted. */\n  density?: AccordionDensity;\n}\n\nfunction StepBody({\n  content,\n  emptyLabel,\n  explanation,\n}: {\n  content: SafetyPlanStepContent | undefined;\n  emptyLabel: string;\n  explanation?: string;\n}) {\n  const entries = content?.entries ?? [];\n  const contacts = content?.contacts ?? [];\n\n  if (!entries.length && !contacts.length) {\n    // Absence with a reason, never a blank — CONTENT.md §1.\n    return <p className=\"zb-safety-plan__empty\">{emptyLabel}</p>;\n  }\n\n  return (\n    <>\n      {entries.length ? (\n        <ul className=\"zb-safety-plan__entries\">\n          {entries.map((entry) => (\n            <li key={entry}>{entry}</li>\n          ))}\n        </ul>\n      ) : null}\n\n      {contacts.length ? (\n        <dl className=\"zb-safety-plan__contacts\">\n          {contacts.map((contact) => (\n            <React.Fragment key={contact.name}>\n              <dt>{contact.name}</dt>\n              <dd>\n                {contact.detail ? (\n                  <span className=\"zb-safety-plan__detail\">{contact.detail}</span>\n                ) : null}\n                {contact.availability ? (\n                  <span className=\"zb-safety-plan__availability\">{contact.availability}</span>\n                ) : null}\n              </dd>\n            </React.Fragment>\n          ))}\n        </dl>\n      ) : null}\n\n      {explanation ? <p className=\"zb-safety-plan__explanation\">{explanation}</p> : null}\n    </>\n  );\n}\n\nexport function SafetyPlan({\n  steps,\n  revisedAt,\n  labels: labelOverride,\n  pinCrisisStep = true,\n  headingLevel = 3,\n  density = \"patient\",\n  className,\n  ...rest\n}: SafetyPlanProps) {\n  const labels = React.useMemo(\n    () => ({ ...DEFAULT_SAFETY_PLAN_LABELS, ...labelOverride }),\n    [labelOverride],\n  );\n\n  const items = React.useMemo<AccordionItem[]>(\n    () =>\n      SAFETY_PLAN_STEP_ORDER.map((key, index) => {\n        const isCrisis = key === \"professionals\";\n        const pinned = isCrisis && pinCrisisStep;\n\n        return {\n          key,\n          // The number is part of the label rather than a separate element, so\n          // it survives being read out, copied, or printed.\n          label: `${index + 1} · ${labels[key]}`,\n          ...(pinned ? { pinned: true } : {}),\n          // The crisis step always carries words beside its rail, pinned or\n          // not. In the clinician's editing view the step is closeable, so\n          // \"Always open\" would be a lie — but a red rail with nothing beside\n          // it is worse, because it is a signal only some readers receive.\n          ...(isCrisis\n            ? {\n                severity: \"critical\" as const,\n                summary: pinned ? labels.alwaysOpen : labels.crisisStep,\n              }\n            : {}),\n          children: (\n            <StepBody\n              content={steps[key]}\n              emptyLabel={labels.empty}\n              {...(pinned ? { explanation: labels.pinnedExplanation } : {})}\n            />\n          ),\n        };\n      }),\n    [labels, pinCrisisStep, steps],\n  );\n\n  return (\n    <div className={cn(\"zb-safety-plan\", className)} {...rest}>\n      {revisedAt ? (\n        <p className=\"zb-safety-plan__revised\">\n          <time dateTime={revisedAt}>{labels.revised(revisedAt)}</time>\n        </p>\n      ) : null}\n\n      <Accordion\n        items={items}\n        // One at a time: this is read under load, and a page of six open\n        // sections is a page nobody finishes.\n        accordion\n        variant=\"separate\"\n        density={density}\n        headingLevel={headingLevel}\n      />\n    </div>\n  );\n}\n"
    }
  ]
}
