{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "modal",
  "type": "registry:ui",
  "title": "",
  "description": "",
  "registryDependencies": [
    "https://kashi.sepantapouya.com/r/cx.json"
  ],
  "files": [
    {
      "path": "registry/kashi/modal.ts",
      "type": "registry:ui",
      "target": "components/kashi/modal.ts",
      "content": "\"use client\";\n\nimport { useEffect, useRef, type RefObject } from \"react\";\n\nconst reduced = () => typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n\n/**\n * باز و بسته کردن <dialog> بومی با showModal و انیمیشن خروج:\n * هنگام بستن data-closing می‌گیرد، پایان انیمیشن را صبر می‌کند و بعد close() می‌شود؛\n * فوکوس به عنصری که پنجره را باز کرده برمی‌گردد. با «کاهش حرکت» فوراً بسته می‌شود.\n */\nexport function useModalDialog(ref: RefObject<HTMLDialogElement | null>, open: boolean) {\n  const opener = useRef<Element | null>(null);\n\n  useEffect(() => {\n    const d = ref.current;\n    if (!d) return;\n    if (open) {\n      if (d.open && !d.hasAttribute(\"data-closing\")) return;\n      d.removeAttribute(\"data-closing\");\n      if (!d.open) {\n        opener.current = document.activeElement;\n        d.showModal();\n      }\n      return;\n    }\n    if (!d.open) return;\n    // اول بسته شود، بعد نشانهٔ بستن برداشته شود؛ برعکسش یک فریم انیمیشن ورود را دوباره اجرا می‌کرد (پرش هنگام بستن)\n    const finish = () => {\n      if (d.open) d.close();\n      d.removeAttribute(\"data-closing\");\n    };\n    if (reduced()) return finish();\n    d.setAttribute(\"data-closing\", \"\");\n    // پشتیبان: اگر انیمیشنی اجرا نشد (مثلاً در مرورگر قدیمی) باز هم بسته شود\n    const t = setTimeout(finish, 320);\n    const end = (e: AnimationEvent) => {\n      // رویداد ::backdrop (کوتاه‌تر) و انیمیشن فرزندها را نادیده بگیر؛ فقط پایان حرکت خود پنجره\n      if (e.target !== d || e.pseudoElement) return;\n      clearTimeout(t);\n      finish();\n    };\n    d.addEventListener(\"animationend\", end, { once: true });\n    return () => {\n      clearTimeout(t);\n      d.removeEventListener(\"animationend\", end);\n    };\n  }, [open, ref]);\n\n  /** پس از بسته شدن واقعی فراخوانده شود */\n  const restoreFocus = () => (opener.current as HTMLElement | null)?.focus?.();\n  return { restoreFocus };\n}\n"
    }
  ]
}