{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forms-05",
  "description": "Several values picked from a searchable list and shown as removable chips, with a limit checked on save.",
  "registryDependencies": [
    "field",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/country-flag.json",
    "https://www.dashboardblocks.com/r/radix/forms.json",
    "https://www.dashboardblocks.com/r/radix/multi-select.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/forms/forms-05.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { CountryFlag } from '@/registry/components/dashboardblocks/country-flag'\nimport {\n  type FormErrors,\n  SaveBar,\n  useSimpleForm,\n} from '@/registry/components/dashboardblocks/forms'\nimport {\n  MultiSelect,\n  type MultiSelectOption,\n} from '@/registry/components/dashboardblocks/multi-select'\n\nimport {\n  Field,\n  FieldDescription,\n  FieldError,\n  FieldGroup,\n  FieldLabel,\n} from '@/components/ui/field'\n\ntype ReportSettings = {\n  markets: readonly string[]\n  metrics: readonly string[]\n  recipients: readonly string[]\n}\n\ninterface Country {\n  /** ISO 3166-1 alpha-2 code, such as `DE`. */\n  code: string\n  name: string\n}\n\ninterface Forms5Props extends BlockStateProps {\n  countries: Country[]\n  /** Leave out to show the empty state. */\n  defaultValues?: ReportSettings\n  description: string\n  /** @default 5 */\n  maxMetrics?: number\n  metrics: MultiSelectOption[]\n  onSubmit?: (values: ReportSettings) => Promise<FormErrors<ReportSettings> | void>\n  people: MultiSelectOption[]\n  title: string\n}\n\nconst exampleProps: Forms5Props = {\n  countries: [\n    { code: 'US', name: 'United States' },\n    { code: 'GB', name: 'United Kingdom' },\n    { code: 'DE', name: 'Germany' },\n    { code: 'FR', name: 'France' },\n    { code: 'NL', name: 'Netherlands' },\n    { code: 'ES', name: 'Spain' },\n    { code: 'SE', name: 'Sweden' },\n    { code: 'CA', name: 'Canada' },\n    { code: 'AU', name: 'Australia' },\n    { code: 'JP', name: 'Japan' },\n    { code: 'BR', name: 'Brazil' },\n    { code: 'IN', name: 'India' },\n  ],\n  defaultValues: {\n    markets: ['US', 'GB', 'DE'],\n    metrics: ['mrr', 'new-customers', 'churn'],\n    recipients: ['amara', 'jonas'],\n  },\n  description: 'Sent every Monday at 9:00 with last week’s numbers.',\n  metrics: [\n    { label: 'MRR', value: 'mrr' },\n    { label: 'New customers', value: 'new-customers' },\n    { label: 'Churn rate', value: 'churn' },\n    { label: 'Active users', value: 'active-users' },\n    { label: 'Trial conversion', value: 'trial-conversion' },\n    { label: 'Average revenue per account', value: 'arpa' },\n    { label: 'Net revenue retention', value: 'nrr' },\n    { label: 'Support tickets', value: 'tickets' },\n  ],\n  people: [\n    { label: 'Amara Okafor', value: 'amara' },\n    { label: 'Jonas Weber', value: 'jonas' },\n    { label: 'Li Wei', value: 'li' },\n    { label: 'Sofia Marquez', value: 'sofia' },\n    { label: 'Ravi Shah', value: 'ravi' },\n    { label: 'Hanna Becker', value: 'hanna' },\n    { label: 'Noor Haddad', value: 'noor' },\n  ],\n  title: 'Weekly report',\n}\n\nasync function saveReport() {\n  await new Promise((resolve) => setTimeout(resolve, 800))\n}\n\nfunction Forms5Content(props: Forms5Props & { defaultValues: ReportSettings }) {\n  const {\n    countries,\n    defaultValues,\n    maxMetrics = 5,\n    metrics,\n    onSubmit = saveReport,\n    people,\n  } = props\n  const form = useSimpleForm({\n    defaultValues,\n    onSubmit,\n    validate: (values): FormErrors<ReportSettings> => ({\n      markets: values.markets.length === 0 ? 'Pick at least one market.' : undefined,\n      metrics:\n        values.metrics.length === 0\n          ? 'Pick at least one metric.'\n          : values.metrics.length > maxMetrics\n            ? `Pick ${maxMetrics} metrics or fewer, so the email stays short.`\n            : undefined,\n      recipients:\n        values.recipients.length === 0 ? 'Pick at least one person.' : undefined,\n    }),\n  })\n  const changes = form.changedFields.length\n  const markets = countries.map((country) => ({\n    icon: <CountryFlag code={country.code} />,\n    label: country.name,\n    value: country.code,\n  }))\n\n  return (\n    <form method='post' noValidate onSubmit={(event) => void form.submit(event)}>\n      <FieldGroup className='border-t pt-4'>\n        <Field data-invalid={form.errors.recipients ? true : undefined}>\n          <FieldLabel\n            id={`${form.getId('recipients')}-label`}\n            htmlFor={form.getId('recipients')}\n          >\n            Send to\n          </FieldLabel>\n          <MultiSelect\n            options={people}\n            placeholder='Add people'\n            {...form.list('recipients')}\n          />\n          <FieldError {...form.error('recipients')} />\n        </Field>\n        <Field data-invalid={form.errors.metrics ? true : undefined}>\n          <FieldLabel\n            id={`${form.getId('metrics')}-label`}\n            htmlFor={form.getId('metrics')}\n          >\n            Metrics\n          </FieldLabel>\n          <MultiSelect\n            options={metrics}\n            placeholder='Add metrics'\n            {...form.list('metrics')}\n          />\n          <FieldDescription>\n            {form.values.metrics.length} picked, up to {maxMetrics}. The email shows them\n            in this order.\n          </FieldDescription>\n          <FieldError {...form.error('metrics')} />\n        </Field>\n        <Field data-invalid={form.errors.markets ? true : undefined}>\n          <FieldLabel\n            id={`${form.getId('markets')}-label`}\n            htmlFor={form.getId('markets')}\n          >\n            Markets\n          </FieldLabel>\n          <MultiSelect\n            options={markets}\n            placeholder='Add countries'\n            {...form.list('markets')}\n          />\n          <FieldDescription>Each metric is split by these countries.</FieldDescription>\n          <FieldError {...form.error('markets')} />\n        </Field>\n      </FieldGroup>\n      <SaveBar\n        className='mt-6'\n        isDirty={form.isDirty}\n        isSubmitting={form.isSubmitting}\n        message={`${changes} unsaved ${changes === 1 ? 'change' : 'changes'}`}\n        onDiscard={() => form.reset()}\n      />\n    </form>\n  )\n}\n\nconst Forms5 = (props: Forms5Props) => {\n  const { defaultValues, description, errorMessage, status, title } = props\n  const ready = !status && defaultValues !== undefined\n\n  return (\n    <BlockStateProvider\n      errorMessage={errorMessage}\n      state={getBlockState(status, defaultValues)}\n    >\n      <section className='@container flex flex-col gap-3'>\n        <header className='flex flex-col gap-0.5'>\n          <h2 className='font-semibold tracking-tight'>{title}</h2>\n          <p className='text-muted-foreground text-sm'>{description}</p>\n        </header>\n        {ready ? (\n          <Forms5Content {...props} defaultValues={defaultValues} />\n        ) : (\n          <div className='border-t'>\n            <BlockStateRows rows={3} />\n          </div>\n        )}\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport { Forms5, exampleProps as forms5ExampleProps, type Forms5Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/forms/forms-05.tsx"
    }
  ],
  "meta": {
    "shows": "Several values picked from a searchable list and shown as removable chips, with a limit checked on save.",
    "size": "half",
    "usedWith": [
      "forms-01",
      "settings-01"
    ],
    "component": "Forms5",
    "props": "{ countries: { code: string; name: string }[]; defaultValues?: { markets: string[]; metrics: string[]; recipients: string[] }; description: string; maxMetrics?: number; metrics: { disabled?: boolean; icon?: ReactNode; label: string; value: string }[]; onSubmit?: (values: { markets: string[]; metrics: string[]; recipients: string[] }) => Promise<void | { markets?: string; metrics?: string; recipients?: string }>; people: { disabled?: boolean; icon?: ReactNode; label: string; value: string }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
