{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "checkbox",
  "type": "registry:ui",
  "title": "Checkbox، Switch",
  "description": "چک‌باکس",
  "registryDependencies": [
    "https://kashi.sepantapouya.com/r/cx.json",
    "https://kashi.sepantapouya.com/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/kashi/Checkbox.tsx",
      "type": "registry:ui",
      "target": "components/kashi/Checkbox.tsx",
      "content": "\"use client\";\n\nimport { forwardRef, useEffect, useId, useRef, type InputHTMLAttributes, type ReactNode } from \"react\";\nimport { cx } from \"./cx\";\nimport { mergeRefs } from \"./utils\";\n\nexport interface CheckClassNames { root?: string; control?: string; label?: string; description?: string }\n\ninterface CheckOwnProps {\n  /** «start»: برچسب پیش از کنترل و کشیده تا انتهای ردیف (مثل صفحهٔ تنظیمات) @default \"end\" */\n  labelPosition?: \"start\" | \"end\";\n  classNames?: CheckClassNames;\n  /** برچسب کنار کنترل */\n  label?: ReactNode;\n  /** توضیح زیر برچسب */\n  description?: ReactNode;\n  /** حالت خطا */\n  invalid?: boolean;\n}\n\nexport interface CheckboxProps extends CheckOwnProps, Omit<InputHTMLAttributes<HTMLInputElement>, \"type\" | \"size\"> {\n  /** حالت نیمه‌انتخاب (مثلاً برای «انتخاب همه») */\n  indeterminate?: boolean;\n  /** @default \"md\" */\n  size?: \"md\" | \"lg\";\n}\n\n/** برچسب و توضیح مشترک بین Checkbox و Switch */\nfunction CheckLabel({ id, label, description, className, classNames = {}, labelPosition = \"end\", children }: { id: string; label?: ReactNode; description?: ReactNode; className?: string; classNames?: CheckClassNames; labelPosition?: \"start\" | \"end\"; children: ReactNode }) {\n  if (!label && !description) return <>{children}</>;\n  return (\n    <label className={cx(\"k-check\", labelPosition === \"start\" && \"k-check--start\", className, classNames.root)} htmlFor={id}>\n      {children}\n      <span className=\"k-check__text\">\n        {label && <span className={cx(\"k-check__label\", classNames.label)}>{label}</span>}\n        {description && <span className={cx(\"k-check__description\", classNames.description)} id={`${id}-desc`}>{description}</span>}\n      </span>\n    </label>\n  );\n}\n\nexport const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(function Checkbox(\n  { label, description, invalid, indeterminate = false, size = \"md\", id, className, classNames, labelPosition, ...rest },\n  ref,\n) {\n  const autoId = useId();\n  const inputId = id ?? autoId;\n  const inner = useRef<HTMLInputElement>(null);\n  // indeterminate فقط از طریق DOM قابل‌تنظیم است\n  useEffect(() => {\n    if (inner.current) inner.current.indeterminate = indeterminate;\n  }, [indeterminate]);\n\n  return (\n    <CheckLabel id={inputId} label={label} description={description} className={className} classNames={classNames} labelPosition={labelPosition}>\n      <input\n        ref={mergeRefs(ref, inner)}\n        type=\"checkbox\"\n        id={inputId}\n        className={cx(\"k-checkbox\", size === \"lg\" && \"k-checkbox--lg\", !label && !description && className, classNames?.control)}\n        aria-invalid={invalid || undefined}\n        aria-describedby={description ? `${inputId}-desc` : undefined}\n        // برای رندر سمت سرور: اسکریپت صفحه می‌تواند indeterminate را پیش از hydrate تنظیم کند\n        data-indeterminate={indeterminate || undefined}\n        {...rest}\n      />\n    </CheckLabel>\n  );\n});\n\nexport interface SwitchProps extends CheckOwnProps, Omit<InputHTMLAttributes<HTMLInputElement>, \"type\" | \"size\" | \"role\"> {\n  /** @default \"md\" */\n  size?: \"sm\" | \"md\" | \"lg\";\n}\n\nexport const Switch = forwardRef<HTMLInputElement, SwitchProps>(function Switch(\n  { label, description, invalid, size = \"md\", id, className, classNames, labelPosition, ...rest },\n  ref,\n) {\n  const autoId = useId();\n  const inputId = id ?? autoId;\n  return (\n    <CheckLabel id={inputId} label={label} description={description} className={className} classNames={classNames} labelPosition={labelPosition}>\n      <input\n        ref={ref}\n        type=\"checkbox\"\n        role=\"switch\"\n        id={inputId}\n        className={cx(\"k-switch\", size !== \"md\" && `k-switch--${size}`, !label && !description && className, classNames?.control)}\n        aria-invalid={invalid || undefined}\n        aria-describedby={description ? `${inputId}-desc` : undefined}\n        {...rest}\n      />\n    </CheckLabel>\n  );\n});\n"
    }
  ]
}