{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "team-06",
  "description": "A share panel for inviting people with view or edit access, changing or removing it, and choosing who the link works for.",
  "registryDependencies": [
    "button",
    "input",
    "https://www.dashboardblocks.com/r/radix/option-select.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/settings.json",
    "https://www.dashboardblocks.com/r/radix/team.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/team/team-06.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n  useBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { OptionSelect } from '@/registry/components/dashboardblocks/option-select'\nimport { useCopyToClipboard } from '@/registry/components/dashboardblocks/settings'\nimport { PersonAvatar } from '@/registry/components/dashboardblocks/team'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { type FormEvent, type ReactNode, useId, useState } from 'react'\nimport { flushSync } from 'react-dom'\n\nimport { Button } from '@/components/ui/button'\nimport { Input } from '@/components/ui/input'\n\ntype ShareAccess = 'owner' | 'edit' | 'view'\n\ntype LinkAccess = 'restricted' | 'workspace' | 'anyone'\n\ninterface SharePerson {\n  avatar?: string\n  email: string\n  id: string\n  /** Leave out for someone invited who hasn't joined yet; the email is shown instead. */\n  name?: string\n  access: ShareAccess\n}\n\ninterface Team6Props extends BlockStateProps {\n  /** The signed-in person, who can't change their own access. */\n  currentPersonId: string\n  /** @default a sentence counting who has access and who can open the link */\n  description?: string\n  /** @default 'restricted' */\n  linkAccess?: LinkAccess\n  /** Who the link can be opened by, in the order offered. Leave out `anyone` for something only people in the workspace may open. @default ['restricted', 'workspace', 'anyone'] */\n  linkAccessOptions?: LinkAccess[]\n  onAccessChange?: (id: string, access: Exclude<ShareAccess, 'owner'> | null) => void\n  onInvite?: (email: string, access: Exclude<ShareAccess, 'owner'>) => void\n  onLinkAccessChange?: (access: LinkAccess) => void\n  /** Leave out, or pass none, to show the empty state. */\n  people?: SharePerson[]\n  title: string\n  url: string\n  workspace: string\n}\n\nconst exampleProps: Team6Props = {\n  currentPersonId: 'p1',\n  linkAccess: 'workspace',\n  people: [\n    {\n      access: 'owner',\n      avatar: '/images/avatar-05.webp',\n      email: 'amara@acme.co',\n      id: 'p1',\n      name: 'Amara Okafor',\n    },\n    {\n      access: 'edit',\n      avatar: '/images/avatar-04.webp',\n      email: 'liam@acme.co',\n      id: 'p2',\n      name: 'Liam Carter',\n    },\n    {\n      access: 'view',\n      avatar: '/images/avatar-01.webp',\n      email: 'sofia@acme.co',\n      id: 'p3',\n      name: 'Sofia Rossi',\n    },\n    { access: 'view', email: 'board@northwind.vc', id: 'p4' },\n  ],\n  title: 'Share Revenue overview',\n  url: 'https://app.acme.co/d/revenue-overview',\n  workspace: 'Acme',\n}\n\nconst accessLabels: Record<ShareAccess, string> = {\n  edit: 'Can edit',\n  owner: 'Owner',\n  view: 'Can view',\n}\n\nconst linkAccessConfig: Record<\n  LinkAccess,\n  { description: string; icon: ReactNode; label: (workspace: string) => string }\n> = {\n  anyone: {\n    description: 'Anyone on the internet with the link can view.',\n    icon: (\n      <IconPlaceholder\n        lucide='GlobeIcon'\n        tabler='IconGlobe'\n        hugeicons='Globe02Icon'\n        phosphor='GlobeIcon'\n        remixicon='RiGlobeLine'\n      />\n    ),\n    label: () => 'Anyone with the link',\n  },\n  restricted: {\n    description: 'Only people added above can open the link.',\n    icon: (\n      <IconPlaceholder\n        lucide='LockIcon'\n        tabler='IconLock'\n        hugeicons='SquareLock02Icon'\n        phosphor='LockIcon'\n        remixicon='RiLockLine'\n      />\n    ),\n    label: () => 'Only people added',\n  },\n  workspace: {\n    description: 'Everyone in the workspace can view with the link.',\n    icon: (\n      <IconPlaceholder\n        lucide='UsersIcon'\n        tabler='IconUsers'\n        hugeicons='UserGroupIcon'\n        phosphor='UsersIcon'\n        remixicon='RiTeamLine'\n      />\n    ),\n    label: (workspace) => `Anyone at ${workspace}`,\n  },\n}\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\nfunction ShareSettings(props: Team6Props) {\n  const {\n    currentPersonId,\n    description,\n    linkAccessOptions = ['restricted', 'workspace', 'anyone'],\n    onAccessChange,\n    onInvite,\n    onLinkAccessChange,\n    title,\n    url,\n    workspace,\n  } = props\n  const id = useId()\n  const state = useBlockState()\n  const [people, setPeople] = useState(props.people ?? [])\n  const [linkAccess, setLinkAccess] = useState(props.linkAccess ?? 'restricted')\n  const [email, setEmail] = useState('')\n  const [access, setAccess] = useState<Exclude<ShareAccess, 'owner'>>('view')\n  const [error, setError] = useState<string | null>(null)\n  const { copied, copy } = useCopyToClipboard()\n\n  const fail = (message: string) => {\n    flushSync(() => setError(message))\n    document.getElementById(`${id}-email`)?.focus()\n  }\n\n  const invite = (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault()\n    const address = email.trim().toLowerCase()\n    if (!EMAIL.test(address)) return fail('Enter an email address.')\n    if (people.some((person) => person.email === address)) {\n      return fail(`${address} already has access.`)\n    }\n    setPeople((current) => [\n      ...current,\n      { access, email: address, id: `share-${address}` },\n    ])\n    setEmail('')\n    setError(null)\n    onInvite?.(address, access)\n  }\n\n  const change = (person: SharePerson, value: string) => {\n    if (value === 'remove') {\n      setPeople((current) => current.filter((item) => item.id !== person.id))\n      return onAccessChange?.(person.id, null)\n    }\n    const next = value as Exclude<ShareAccess, 'owner'>\n    setPeople((current) =>\n      current.map((item) => (item.id === person.id ? { ...item, access: next } : item)),\n    )\n    onAccessChange?.(person.id, next)\n  }\n\n  const link = linkAccessConfig[linkAccess]\n  const editors = people.filter((person) => person.access !== 'view').length\n  const summary = `${people.length} ${people.length === 1 ? 'person has' : 'people have'} access, ${editors} can edit. ${link.description}`\n\n  return (\n    <section className='@container flex flex-col gap-4'>\n      <header className='flex flex-col gap-0.5'>\n        <h2 className='font-semibold tracking-tight'>{title}</h2>\n        {description ? (\n          <p className='text-muted-foreground text-sm'>{description}</p>\n        ) : (\n          <BlockReady className='text-sm'>\n            <p className='text-muted-foreground text-sm'>{summary}</p>\n          </BlockReady>\n        )}\n      </header>\n      <div className='flex flex-col gap-5'>\n        <form method='post' onSubmit={invite} noValidate className='flex flex-col gap-2'>\n          <label htmlFor={`${id}-email`} className='sr-only'>\n            Add people by email\n          </label>\n          <div className='flex flex-col gap-2 @md:flex-row'>\n            <Input\n              id={`${id}-email`}\n              type='email'\n              autoComplete='off'\n              placeholder='Add people by email'\n              disabled={state !== undefined}\n              value={email}\n              onChange={(event) => setEmail(event.target.value)}\n              aria-invalid={error ? true : undefined}\n              aria-describedby={error ? `${id}-error` : undefined}\n              className='@md:flex-1'\n            />\n            <div className='flex gap-2'>\n              <OptionSelect\n                aria-label='Access for new people'\n                disabled={state !== undefined}\n                value={access}\n                options={[\n                  { label: accessLabels.view, value: 'view' },\n                  { label: accessLabels.edit, value: 'edit' },\n                ]}\n                onValueChange={setAccess}\n              />\n              <Button\n                type='submit'\n                className='flex-1 @md:flex-none'\n                disabled={state !== undefined}\n              >\n                Invite\n              </Button>\n            </div>\n          </div>\n          {error && (\n            <p id={`${id}-error`} className='text-destructive text-sm'>\n              {error}\n            </p>\n          )}\n        </form>\n\n        <section aria-labelledby={`${id}-people`} className='flex flex-col gap-1'>\n          <h3 id={`${id}-people`} className='text-sm font-medium'>\n            People with access\n          </h3>\n          <BlockStateRows className='border-t' rows={3} />\n          {!state && (\n            <ul className='flex flex-col divide-y border-t'>\n              {people.map((person) => {\n                const isYou = person.id === currentPersonId\n                const name = person.name ?? person.email\n                return (\n                  <li key={person.id} className='flex items-center gap-3 py-2.5'>\n                    {person.name ? (\n                      <PersonAvatar person={{ ...person, name: person.name }} />\n                    ) : (\n                      <span\n                        aria-hidden\n                        className='bg-muted text-muted-foreground flex size-8 shrink-0 items-center justify-center rounded-full [&_svg]:size-4'\n                      >\n                        <IconPlaceholder\n                          lucide='MailIcon'\n                          tabler='IconMail'\n                          hugeicons='MailIcon'\n                          phosphor='EnvelopeIcon'\n                          remixicon='RiMailLine'\n                        />\n                      </span>\n                    )}\n                    <div className='flex min-w-0 flex-1 flex-col'>\n                      <span className='truncate text-sm font-medium'>\n                        {name}\n                        {isYou && (\n                          <span className='text-muted-foreground font-normal'>\n                            {' '}\n                            (you)\n                          </span>\n                        )}\n                      </span>\n                      <span className='text-muted-foreground truncate text-xs'>\n                        {person.name ? person.email : 'Invited'}\n                      </span>\n                    </div>\n                    {isYou || person.access === 'owner' ? (\n                      <span className='text-muted-foreground px-2.5 text-sm'>\n                        {accessLabels[person.access]}\n                      </span>\n                    ) : (\n                      <OptionSelect\n                        size='sm'\n                        aria-label={`Access for ${name}`}\n                        value={person.access}\n                        options={[\n                          { label: accessLabels.view, value: 'view' },\n                          { label: accessLabels.edit, value: 'edit' },\n                          { label: 'Remove', value: 'remove' },\n                        ]}\n                        onValueChange={(value) => change(person, value)}\n                      />\n                    )}\n                  </li>\n                )\n              })}\n            </ul>\n          )}\n        </section>\n\n        {!state && (\n          <section aria-labelledby={`${id}-link`} className='flex flex-col gap-1'>\n            <h3 id={`${id}-link`} className='text-sm font-medium'>\n              General access\n            </h3>\n            <div className='flex items-center gap-3 border-t pt-2.5'>\n              <span\n                aria-hidden\n                className='bg-muted text-muted-foreground flex size-8 shrink-0 items-center justify-center rounded-full [&_svg]:size-4'\n              >\n                {link.icon}\n              </span>\n              <div className='flex min-w-0 flex-1 flex-col items-start gap-0.5'>\n                <OptionSelect\n                  size='sm'\n                  aria-label='Who can open the link'\n                  aria-describedby={`${id}-link-description`}\n                  value={linkAccess}\n                  options={linkAccessOptions.map((value) => ({\n                    label: linkAccessConfig[value].label(workspace),\n                    value,\n                  }))}\n                  onValueChange={(next) => {\n                    setLinkAccess(next)\n                    onLinkAccessChange?.(next)\n                  }}\n                />\n                <span\n                  id={`${id}-link-description`}\n                  className='text-muted-foreground text-xs'\n                >\n                  {link.description}\n                </span>\n              </div>\n            </div>\n          </section>\n        )}\n      </div>\n      <footer className='flex items-center gap-2 border-t pt-3'>\n        <span className='text-muted-foreground min-w-0 flex-1 truncate font-mono text-xs'>\n          {url}\n        </span>\n        <Button variant='outline' size='sm' onClick={() => void copy(url)}>\n          {copied ? (\n            <IconPlaceholder\n              lucide='CheckIcon'\n              tabler='IconCheck'\n              hugeicons='Tick02Icon'\n              phosphor='CheckIcon'\n              remixicon='RiCheckLine'\n              data-icon='inline-start'\n              aria-hidden\n            />\n          ) : (\n            <IconPlaceholder\n              lucide='LinkIcon'\n              tabler='IconLink'\n              hugeicons='Link01Icon'\n              phosphor='LinkIcon'\n              remixicon='RiLinkM'\n              data-icon='inline-start'\n              aria-hidden\n            />\n          )}\n          {copied ? 'Copied' : 'Copy link'}\n        </Button>\n      </footer>\n    </section>\n  )\n}\n\nconst Team6 = (props: Team6Props) => {\n  const { people = [], errorMessage, status } = props\n  const state = getBlockState(status, people)\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <ShareSettings key={state ?? 'ready'} {...props} />\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Team6,\n  exampleProps as team6ExampleProps,\n  type LinkAccess,\n  type ShareAccess,\n  type SharePerson,\n  type Team6Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/team/team-06.tsx"
    }
  ],
  "meta": {
    "shows": "A share panel for inviting people with view or edit access, changing or removing it, and choosing who the link works for.",
    "size": "half",
    "usedWith": [
      "team-01",
      "settings-01"
    ],
    "component": "Team6",
    "props": "{ currentPersonId: string; description?: string; linkAccess?: \"restricted\" | \"workspace\" | \"anyone\"; linkAccessOptions?: (\"restricted\" | \"workspace\" | \"anyone\")[]; onAccessChange?: (id: string, access: null | \"edit\" | \"view\") => void; onInvite?: (email: string, access: \"edit\" | \"view\") => void; onLinkAccessChange?: (access: \"restricted\" | \"workspace\" | \"anyone\") => void; people?: { avatar?: string; email: string; id: string; name?: string; access: \"owner\" | \"edit\" | \"view\" }[]; title: string; url: string; workspace: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
