{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forms-07",
  "description": "Numbers with their unit or currency, formatted when you leave the field, with minus and plus for a count of seats.",
  "registryDependencies": [
    "field",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/forms.json",
    "https://www.dashboardblocks.com/r/radix/number-field.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/forms/forms-07.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  type FormErrors,\n  SaveBar,\n  useSimpleForm,\n} from '@/registry/components/dashboardblocks/forms'\nimport { NumberField } from '@/registry/components/dashboardblocks/number-field'\nimport {\n  formatCurrency,\n  formatNumber,\n  formatPercent,\n} from '@/registry/lib/dashboardblocks/format'\n\nimport {\n  Field,\n  FieldDescription,\n  FieldError,\n  FieldGroup,\n  FieldLabel,\n} from '@/components/ui/field'\n\ntype UsageSettings = {\n  /** The share of the cap, from 1 to 100, at which the owners get an email. */\n  alertAt: number | null\n  /** Usage above the plan, in dollars a month, billed before new runs pause. */\n  cap: number | null\n  seats: number | null\n}\n\ninterface Forms7Props extends BlockStateProps {\n  /** Leave out to show the empty state. */\n  defaultValues?: UsageSettings\n  description: string\n  /** People in the workspace: each needs a seat. */\n  members: number\n  onSubmit?: (values: UsageSettings) => Promise<FormErrors<UsageSettings> | void>\n  /** A seat a month, in dollars. */\n  seatPrice: number\n  title: string\n}\n\nconst exampleProps: Forms7Props = {\n  defaultValues: { alertAt: 80, cap: 500, seats: 12 },\n  description: 'Billed on the 14th of each month, with usage from the month before.',\n  members: 9,\n  seatPrice: 49,\n  title: 'Seats and usage',\n}\n\nasync function saveUsage() {\n  await new Promise((resolve) => setTimeout(resolve, 800))\n}\n\nfunction Forms7Content(props: Forms7Props & { defaultValues: UsageSettings }) {\n  const { defaultValues, members, onSubmit = saveUsage, seatPrice } = props\n  const form = useSimpleForm({\n    defaultValues,\n    onSubmit,\n    validate: (values): FormErrors<UsageSettings> => ({\n      alertAt: values.alertAt === null ? 'Enter a share of the cap.' : undefined,\n      cap:\n        values.cap === null\n          ? 'Enter a cap, or 0 to pause at the plan’s limit.'\n          : undefined,\n      seats: values.seats === null ? 'Enter a number of seats.' : undefined,\n    }),\n  })\n  const changes = form.changedFields.length\n  const { alertAt, cap, seats } = form.values\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.seats ? true : undefined}>\n          <FieldLabel htmlFor={form.getId('seats')}>Seats</FieldLabel>\n          <NumberField\n            className='@md:w-48'\n            decrementLabel='Remove a seat'\n            incrementLabel='Add a seat'\n            max={500}\n            min={members}\n            stepper\n            unit='seats'\n            {...form.number('seats')}\n          />\n          <FieldDescription>\n            {seats === null\n              ? `${formatCurrency(seatPrice)} a seat a month. ${formatNumber(members)} are in use, so you can’t go below that.`\n              : `${formatCurrency(seats * seatPrice)} a month at ${formatCurrency(seatPrice)} a seat. ${formatNumber(members)} are in use, so you can’t go below that.`}\n          </FieldDescription>\n          <FieldError {...form.error('seats')} />\n        </Field>\n        <Field data-invalid={form.errors.cap ? true : undefined}>\n          <FieldLabel htmlFor={form.getId('cap')}>Usage cap</FieldLabel>\n          <NumberField\n            className='@md:w-56'\n            currency='USD'\n            min={0}\n            unit='a month'\n            {...form.number('cap')}\n          />\n          <FieldDescription>\n            Usage above your plan is billed up to this amount, then new runs pause until\n            the 14th.\n          </FieldDescription>\n          <FieldError {...form.error('cap')} />\n        </Field>\n        <Field data-invalid={form.errors.alertAt ? true : undefined}>\n          <FieldLabel htmlFor={form.getId('alertAt')}>Email the owners at</FieldLabel>\n          <NumberField\n            className='@md:w-40'\n            max={100}\n            min={1}\n            unit='% of the cap'\n            {...form.number('alertAt')}\n          />\n          <FieldDescription>\n            {alertAt !== null && cap !== null && cap > 0\n              ? `They get an email once usage passes ${formatCurrency(cap * (alertAt / 100), { precision: 'exact' })}, ${formatPercent(alertAt / 100)} of ${formatCurrency(cap, { precision: 'exact' })}.`\n              : 'They get an email once usage passes this share of the cap.'}\n          </FieldDescription>\n          <FieldError {...form.error('alertAt')} />\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 Forms7 = (props: Forms7Props) => {\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          <Forms7Content {...props} defaultValues={defaultValues} />\n        ) : (\n          <div className='border-t'>\n            <BlockStateRows rows={3} />\n          </div>\n        )}\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport { Forms7, exampleProps as forms7ExampleProps, type Forms7Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/forms/forms-07.tsx"
    }
  ],
  "meta": {
    "shows": "Numbers with their unit or currency, formatted when you leave the field, with minus and plus for a count of seats.",
    "size": "half",
    "usedWith": [
      "forms-06",
      "settings-01"
    ],
    "component": "Forms7",
    "props": "{ defaultValues?: { alertAt: null | number; cap: null | number; seats: null | number }; description: string; members: number; onSubmit?: (values: { alertAt: null | number; cap: null | number; seats: null | number }) => Promise<void | { alertAt?: string; cap?: string; seats?: string }>; seatPrice: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
