import { X } from 'lucide-react'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../ui/select'; import { ORGANIZATION_ROLE_GROUPS } from '../../utils/staffRoleCatalog.ts'; import './NoteVisibilitySelect.css'; // Controlled visibility picker for org-internal patient notes. Emits the client-side // `{ mode, categoryLabels }` shape only - it never expands categories to wire `roleCodes` itself. // The consuming component (PatientNotes) calls `expandCategoriesToRoleCodes` at save time. // `categoryLabels` are `ORGANIZATION_ROLE_GROUPS[].label` values (see `utils/staffRoleCatalog.ts`). export interface NoteVisibilityValue { // '' = nothing chosen yet (shows the placeholder; save is gated on a real choice). mode: '' | 'me-only' | 'all-staff' | 'roles'; // Only meaningful when mode === 'roles'; cleared whenever another mode is chosen. categoryLabels: string[]; } interface NoteVisibilitySelectProps { value: NoteVisibilityValue; onChange: (value: NoteVisibilityValue) => void; disabled?: boolean; placeholder?: string; } const MODE_OPTIONS: Array<{ value: NoteVisibilityValue['mode']; label: string }> = [ { value: 'me-only', label: 'Me only' }, { value: 'all-staff', label: 'All staff' }, { value: 'roles', label: 'Specific role categories' }, ]; const NoteVisibilitySelect = ({ value, onChange, disabled = false, placeholder, }: NoteVisibilitySelectProps) => { const selectedLabels = value.categoryLabels; const handleModeChange = (nextMode: string) => { const mode = nextMode as NoteVisibilityValue['mode']; onChange({ mode, // "Me only" / "All staff" never carry categories - only "roles" does. categoryLabels: mode === 'roles' ? selectedLabels : [], }); }; const addCategory = (label: string) => { if (selectedLabels.includes(label)) return; onChange({ mode: 'roles', categoryLabels: [...selectedLabels, label] }); }; const removeCategory = (label: string) => { onChange({ mode: 'roles', categoryLabels: selectedLabels.filter((selected) => selected !== label), }); }; // Categories already chosen drop out of the add-picker. const availableGroups = ORGANIZATION_ROLE_GROUPS.filter( (group) => !selectedLabels.includes(group.label), ); return (
Select at least one role category so the right staff can see this note.
)}