{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "people-picker",
  "title": "People Picker",
  "author": "vmnog <https://vmnog.com>",
  "description": "Notion Calendar's F and P dialog: search your contacts to meet with someone or show a teammate's calendar.",
  "registryDependencies": [
    "@calendarcn/calendar-core",
    "command",
    "dialog",
    "kbd"
  ],
  "files": [
    {
      "path": "src/components/people-picker.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { useCalendarPeople } from \"@/components/calendar-people\";\nimport type {\n  EventContact,\n  PeoplePickerMode,\n} from \"@/components/calendar-types\";\nimport {\n  Command,\n  CommandEmpty,\n  CommandInput,\n  CommandItem,\n  CommandList,\n} from \"@/components/ui/command\";\nimport {\n  Dialog,\n  DialogContent,\n  DialogDescription,\n  DialogTitle,\n} from \"@/components/ui/dialog\";\nimport { Kbd } from \"@/components/ui/kbd\";\nimport {\n  getPersonName,\n  getTypedPerson,\n  isSameEmail,\n  matchesPerson,\n} from \"@/lib/people\";\n\n/** The picker's look, as the command menu's: translucent and blurred in dark mode */\nconst DIALOG_CLASS =\n  \"overflow-hidden p-0 dark:bg-popover/60 dark:backdrop-blur-xl dark:border-border/50 dark:[&_[data-slot=command]]:bg-transparent\";\n\n/** Taller input and rows, as the command menu has them */\nconst COMMAND_CLASS =\n  \"**:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-2.5 [&_[cmdk-list]]:p-1\";\n\n/** Placeholder, and accessible title, of each mode */\nconst PICKER_TITLES: Record<PeoplePickerMode, string> = {\n  \"meet-with\": \"Meet with...\",\n  teammate: \"Show teammate calendar...\",\n};\n\n/** What the dialog's hidden description says each mode does */\nconst PICKER_DESCRIPTIONS: Record<PeoplePickerMode, string> = {\n  \"meet-with\":\n    \"Pick someone to see their events beside yours and the times you're both free.\",\n  teammate: \"Pick a teammate to show their calendar beside yours.\",\n};\n\ninterface PeoplePickerProps {\n  /** Whether the picker is open */\n  open: boolean;\n  /** Called when it opens or closes, including after someone is picked */\n  onOpenChange: (open: boolean) => void;\n  /** Meet with the picked person, or show their calendar. Defaults to \"meet-with\" */\n  mode?: PeoplePickerMode;\n}\n\n/**\n * Notion Calendar's people picker, opened by F (\"Meet with...\") and P\n * (\"Show teammate calendar...\"): a search over the provider's `contacts`\n * (or a typed address), arrows to move, Enter to pick, Escape to close.\n * Picking someone meets with them or shows their calendar, through\n * `useCalendarPeople()`, so it goes inside `CalendarProvider`.\n */\nexport function PeoplePicker({\n  open,\n  onOpenChange,\n  mode = \"meet-with\",\n}: PeoplePickerProps) {\n  const { contacts, meetWith, teammates, addMeetWith, addTeammate } =\n    useCalendarPeople();\n  const [query, setQuery] = React.useState(\"\");\n  const trimmed = query.trim();\n  const added = mode === \"meet-with\" ? meetWith : teammates;\n\n  // A closed picker opens empty next time\n  const [prevOpen, setPrevOpen] = React.useState(open);\n  if (open !== prevOpen) {\n    setPrevOpen(open);\n    if (!open) setQuery(\"\");\n  }\n\n  const people = React.useMemo<EventContact[]>(() => {\n    const available = contacts.filter(\n      (contact) => !added.some((email) => isSameEmail(email, contact.email)),\n    );\n    const matches = available.filter((contact) =>\n      matchesPerson(contact, trimmed),\n    );\n    const typed = getTypedPerson(contacts, trimmed, added);\n    return typed ? [...matches, typed] : matches;\n  }, [contacts, added, trimmed]);\n\n  const pick = (email: string) => {\n    onOpenChange(false);\n    if (mode === \"meet-with\") {\n      addMeetWith(email);\n      return;\n    }\n    addTeammate(email);\n  };\n\n  return (\n    <Dialog open={open} onOpenChange={onOpenChange}>\n      <DialogContent\n        showCloseButton={false}\n        data-people-picker={mode}\n        className={DIALOG_CLASS}\n      >\n        <DialogTitle className=\"sr-only\">{PICKER_TITLES[mode]}</DialogTitle>\n        <DialogDescription className=\"sr-only\">\n          {PICKER_DESCRIPTIONS[mode]}\n        </DialogDescription>\n        {/* Filtered here: cmdk's fuzzy match would also offer unrelated people */}\n        <Command shouldFilter={false} className={COMMAND_CLASS}>\n          <CommandInput\n            placeholder={PICKER_TITLES[mode]}\n            value={query}\n            onValueChange={setQuery}\n          />\n          <CommandList>\n            <CommandEmpty>No people found.</CommandEmpty>\n            {people.map((contact) => (\n              <CommandItem\n                key={contact.email}\n                value={contact.email}\n                onSelect={() => pick(contact.email)}\n              >\n                <span className=\"truncate font-medium\">\n                  {getPersonName(contact)}\n                </span>\n                {contact.name && (\n                  <span className=\"text-muted-foreground truncate\">\n                    {contact.email}\n                  </span>\n                )}\n              </CommandItem>\n            ))}\n          </CommandList>\n          <div className=\"text-muted-foreground flex items-center gap-4 border-t px-3 py-2 text-xs\">\n            <span className=\"flex items-center gap-1\">\n              <span className=\"text-muted-foreground/70\">↑↓</span> Navigate\n            </span>\n            <span className=\"flex items-center gap-1\">\n              <span className=\"text-muted-foreground/70\">↵</span> Select\n            </span>\n            <span className=\"flex items-center gap-1\">\n              <Kbd>esc</Kbd> Close\n            </span>\n          </div>\n        </Command>\n      </DialogContent>\n    </Dialog>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "calendar",
    "scheduling"
  ],
  "type": "registry:component"
}