"use client" import * as React from "react" import { useForm, useWatch } from "react-hook-form" import { z } from "zod" import { zodResolver } from "@hookform/resolvers/zod" import { devLog } from "@/lib/dev-log" import { COLLABORATOR_ACCESS_ICON_LIGHT, COLLABORATOR_ACCESS_LABELS, INVITE_COLLABORATOR_ACCESS_OPTIONS, ROSTER_COLLABORATOR_ACCESS_OPTIONS, canRemoveCollaboratorFromRoster, canSetCollaboratorAccessRole, collaboratorRemoveBlockedReason, type CollaboratorAccessRole, type InviteCollaboratorAccessRole, } from "@/lib/collaborator-access" import { initialsFromDisplayName } from "@/lib/initials-from-name" import { FLOATING_SHEET_CHROME_CLASS, floatingSheetWidthClass, useCompactFloatingSheet, } from "@/lib/floating-sheet-panel" import { cn } from "@/lib/utils" import type { PageHeaderCollaborator } from "@/components/page-header" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { Badge, badgeVariants } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Field, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field" import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group" import { Tip } from "@/components/ui/tip" import { Kbd, KbdGroup } from "@/components/ui/kbd" import { Shortcut } from "@/components/ui/dropdown-menu" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { Sheet, SheetContent, SheetTitle, } from "@/components/ui/sheet" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Form, FormControl, FormField, FormMessage, } from "@/components/ui/form" const inviteSchema = z.object({ email: z.string().min(1, "Email is required").email("Enter a valid email address"), access: z.enum(["editor", "commenter", "viewer"]), }) type InviteForm = z.infer export type InviteCollaboratorFormValues = InviteForm export interface InviteCollaboratorsDrawerProps { open: boolean onOpenChange: (open: boolean) => void collaborators: PageHeaderCollaborator[] resourceLabel?: string onInvite?: (values: InviteCollaboratorFormValues) => void onCollaboratorAccessChange?: (id: string, access: CollaboratorAccessRole) => void onCollaboratorRemove?: (id: string) => void } function collaboratorAccessLabel(access: PageHeaderCollaborator["access"]) { if (!access) return "Viewer" return COLLABORATOR_ACCESS_LABELS[access] } function isOverlaySelectorSheetTarget(target: EventTarget | null) { return ( target instanceof Element && target.closest( '[data-slot="popover-content"], [data-slot="popover-trigger"], [data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-trigger"]', ) != null ) } function CollaboratorAccessChipSelector({ value, onValueChange, options, ariaLabel, triggerId, triggerClassName, isOptionDisabled, }: { value: string onValueChange: (value: string) => void options: readonly { value: string; label: string }[] ariaLabel: string triggerId?: string triggerClassName?: string isOptionDisabled?: (value: string) => boolean }) { const [open, setOpen] = React.useState(false) const selected = options.find(option => option.value === value) const selectedLabel = selected?.label ?? value const selectedIcon = COLLABORATOR_ACCESS_ICON_LIGHT[value as CollaboratorAccessRole] return (