{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forms-06",
  "description": "One option and several options picked from cards, each with its price and a line of detail, saved together.",
  "registryDependencies": [
    "field",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/choice-cards.json",
    "https://www.dashboardblocks.com/r/radix/forms.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/tag.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/forms/forms-06.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 ChoiceCardOption,\n  ChoiceCards,\n} from '@/registry/components/dashboardblocks/choice-cards'\nimport {\n  type FormErrors,\n  SaveBar,\n  useSimpleForm,\n} from '@/registry/components/dashboardblocks/forms'\nimport { Tag } from '@/registry/components/dashboardblocks/tag'\nimport { formatCurrency, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport {\n  FieldDescription,\n  FieldError,\n  FieldGroup,\n  FieldTitle,\n} from '@/components/ui/field'\n\ntype BillingSettings = {\n  addOns: readonly string[]\n  period: 'month' | 'year'\n}\n\ninterface AddOn {\n  description: string\n  /** An add-on the workspace's plan can't have, such as one on a higher plan. */\n  disabled?: boolean\n  id: string\n  name: string\n  /** What the price is for: the workspace (`month`) or each seat (`seat`), a month. */\n  per: 'month' | 'seat'\n  /** A month, in dollars. */\n  price: number\n}\n\ninterface Forms6Props extends BlockStateProps {\n  addOns: AddOn[]\n  /** Leave out to show the empty state. */\n  defaultValues?: BillingSettings\n  description: string\n  onSubmit?: (values: BillingSettings) => Promise<FormErrors<BillingSettings> | void>\n  /** A seat a month, in dollars, paid monthly or once a year. */\n  seatPrice: { month: number; year: number }\n  title: string\n}\n\nconst exampleProps: Forms6Props = {\n  addOns: [\n    {\n      description:\n        'Replies within 4 hours, around the clock, from the same two engineers.',\n      id: 'priority-support',\n      name: 'Priority support',\n      per: 'month',\n      price: 99,\n    },\n    {\n      description:\n        'Sign in with Okta, Entra ID or Google, and add or remove people from it.',\n      id: 'sso',\n      name: 'SSO and SCIM',\n      per: 'seat',\n      price: 4,\n    },\n    {\n      description: 'Every change anyone makes, kept for a year and exported as CSV.',\n      id: 'audit-log',\n      name: 'Audit log',\n      per: 'month',\n      price: 29,\n    },\n    {\n      description:\n        'Events copied to Snowflake or BigQuery every hour. On the Business plan.',\n      disabled: true,\n      id: 'warehouse-sync',\n      name: 'Warehouse sync',\n      per: 'month',\n      price: 199,\n    },\n  ],\n  defaultValues: { addOns: ['audit-log'], period: 'month' },\n  description: 'Changes apply from your next invoice, on Nov 14.',\n  seatPrice: { month: 49, year: 41 },\n  title: 'Billing',\n}\n\nasync function saveBilling() {\n  await new Promise((resolve) => setTimeout(resolve, 800))\n}\n\nfunction Price({ per, value }: { per: string; value: number }) {\n  return (\n    <>\n      {formatCurrency(value)}\n      <span className='text-muted-foreground group-has-[:checked]/field-label:text-foreground/70 font-normal'>\n        {' '}\n        {per}\n      </span>\n    </>\n  )\n}\n\nfunction Forms6Content(props: Forms6Props & { defaultValues: BillingSettings }) {\n  const { addOns, defaultValues, onSubmit = saveBilling, seatPrice } = props\n  const form = useSimpleForm({ defaultValues, onSubmit })\n  const changes = form.changedFields.length\n  const periodId = form.getId('period')\n  const addOnsId = form.getId('addOns')\n\n  const periods: ChoiceCardOption[] = [\n    {\n      aside: <Price per='a seat' value={seatPrice.month} />,\n      description: 'Billed each month. Cancel any time.',\n      title: 'Monthly',\n      value: 'month',\n    },\n    {\n      aside: <Price per='a seat' value={seatPrice.year} />,\n      badge: (\n        <Tag tone='good'>\n          Save{' '}\n          {formatPercent(1 - seatPrice.year / seatPrice.month, {\n            maximumFractionDigits: 0,\n          })}\n        </Tag>\n      ),\n      description: `Billed ${formatCurrency(seatPrice.year * 12)} a seat once a year.`,\n      title: 'Yearly',\n      value: 'year',\n    },\n  ]\n  const addOnOptions: ChoiceCardOption[] = addOns.map((addOn) => ({\n    aside: (\n      <Price per={addOn.per === 'seat' ? 'a seat' : 'a month'} value={addOn.price} />\n    ),\n    description: addOn.description,\n    disabled: addOn.disabled,\n    title: addOn.name,\n    value: addOn.id,\n  }))\n\n  return (\n    <form method='post' noValidate onSubmit={(event) => void form.submit(event)}>\n      <FieldGroup className='border-t pt-4'>\n        <div className='flex flex-col gap-3'>\n          <FieldTitle id={`${periodId}-label`}>Billing period</FieldTitle>\n          <ChoiceCards\n            aria-labelledby={`${periodId}-label`}\n            className='@md:grid-cols-2'\n            options={periods}\n            {...form.select('period')}\n          />\n          <FieldError {...form.error('period')} />\n        </div>\n        <div className='flex flex-col gap-3'>\n          <div className='flex flex-col gap-1'>\n            <FieldTitle id={`${addOnsId}-label`}>Add-ons</FieldTitle>\n            <FieldDescription>\n              Prices are a month, billed with your plan.\n            </FieldDescription>\n          </div>\n          <ChoiceCards type='checkbox' options={addOnOptions} {...form.list('addOns')} />\n          <FieldError {...form.error('addOns')} />\n        </div>\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 Forms6 = (props: Forms6Props) => {\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          <Forms6Content {...props} defaultValues={defaultValues} />\n        ) : (\n          <div className='border-t'>\n            <BlockStateRows rows={3} />\n          </div>\n        )}\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport { Forms6, exampleProps as forms6ExampleProps, type Forms6Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/forms/forms-06.tsx"
    }
  ],
  "meta": {
    "shows": "One option and several options picked from cards, each with its price and a line of detail, saved together.",
    "size": "half",
    "usedWith": [
      "forms-05",
      "settings-01"
    ],
    "component": "Forms6",
    "props": "{ addOns: { description: string; disabled?: boolean; id: string; name: string; per: \"month\" | \"seat\"; price: number }[]; defaultValues?: { addOns: string[]; period: \"month\" | \"year\" }; description: string; onSubmit?: (values: { addOns: string[]; period: \"month\" | \"year\" }) => Promise<void | { addOns?: string; period?: string }>; seatPrice: { month: number; year: number }; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
