{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "record-filters",
  "title": "Record search form and filter bar",
  "description": "A search input with submit and clear actions for filtering a list of records, and a bar of selects that narrow a list by the entity model's filter fields.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0",
    "lucide-react@1.43.0"
  ],
  "registryDependencies": [
    "@registrystack/lib-content",
    "@registrystack/ui-button",
    "@registrystack/ui-input"
  ],
  "files": [
    {
      "path": "record/record-filters.tsx",
      "content": "import { useId, useState } from \"react\";\nimport { Search } from \"lucide-react\";\nimport type { EntityModel } from \"@registrystack/app-runtime\";\nimport { Button } from \"@/components/ui/button\";\nimport { Input } from \"@/components/ui/input\";\nimport { useBlockContent } from \"@/blocks/lib/content\";\n\n/**\n * The one-field identifier search a record list offers. `label` and `hint`\n * are the app's own wording for the field the model filters on; the submit\n * and clear words are generic. Clear only shows once a search is applied.\n */\nexport function RecordSearchForm({\n  label,\n  hint,\n  applied,\n  onSearch,\n  onClear,\n}: {\n  label: string;\n  hint: string;\n  /** The applied filter value, or \"\" when none is applied. */\n  applied: string;\n  onSearch: (value: string) => void;\n  onClear: () => void;\n}) {\n  const c = useBlockContent();\n  const [search, setSearch] = useState(applied);\n  const inputId = useId();\n  return (\n    <form\n      className=\"search-form\"\n      onSubmit={(e) => {\n        e.preventDefault();\n        onSearch(search);\n      }}\n    >\n      <div>\n        <label htmlFor={inputId}>{label}</label>\n        <Input\n          id={inputId}\n          value={search}\n          onChange={(e) => setSearch(e.target.value)}\n          placeholder={hint}\n        />\n      </div>\n      <Button type=\"submit\" variant=\"outline\">\n        <Search />\n        {c.search}\n      </Button>\n      {applied && (\n        <Button\n          variant=\"ghost\"\n          onClick={() => {\n            setSearch(\"\");\n            onClear();\n          }}\n        >\n          {c.clearSearch}\n        </Button>\n      )}\n    </form>\n  );\n}\n\n/** The choice that selects a record where the field is empty, in a filter select. */\nconst EMPTY_CHOICE = \"empty\";\nconst VALUE_PREFIX = \"value:\";\n\n/**\n * One select per filter field that offers options, each narrowing the list as\n * soon as a choice is made. A nullable field with an empty label also offers\n * the records where it is empty, worded by that label. `applied` maps a field\n * id to its chosen value, or null for \"empty\"; `onChange` gets the field and\n * its new value, undefined when the choice applies no filter. `allLabel` words\n * that choice, `BlockContent.filterAll` by default.\n */\nexport function RecordFilterBar({\n  entity,\n  applied,\n  onChange,\n  allLabel,\n}: {\n  entity: EntityModel;\n  applied: Readonly<Record<string, string | null>>;\n  onChange: (field: string, value: string | null | undefined) => void;\n  allLabel?: string;\n}) {\n  const c = useBlockContent();\n  const selects = entity.list.filters.flatMap((filter) => {\n    const field = entity.fields.find((item) => item.id === filter.field);\n    return field?.options?.length ? [{ filter, field }] : [];\n  });\n  if (selects.length === 0) return null;\n  return (\n    <div className=\"filter-bar\">\n      {selects.map(({ filter, field }) => {\n        const current = applied[field.id];\n        const value =\n          current === null\n            ? EMPTY_CHOICE\n            : current === undefined\n              ? \"\"\n              : `${VALUE_PREFIX}${current}`;\n        const id = `filter-${field.id}`;\n        return (\n          <div key={field.id}>\n            <label htmlFor={id}>{filter.label}</label>\n            <select\n              id={id}\n              value={value}\n              onChange={(e) => {\n                const next = e.target.value;\n                onChange(\n                  field.id,\n                  next === \"\"\n                    ? undefined\n                    : next === EMPTY_CHOICE\n                      ? null\n                      : next.slice(VALUE_PREFIX.length),\n                );\n              }}\n            >\n              <option value=\"\">{allLabel ?? c.filterAll}</option>\n              {field.nullable && field.emptyLabel && (\n                <option value={EMPTY_CHOICE}>{field.emptyLabel}</option>\n              )}\n              {field.options!.map((option) => (\n                <option\n                  key={option.value}\n                  value={`${VALUE_PREFIX}${option.value}`}\n                >\n                  {option.label}\n                </option>\n              ))}\n            </select>\n          </div>\n        );\n      })}\n    </div>\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/record/record-filters.tsx"
    }
  ],
  "type": "registry:block"
}