import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command"; import { ICondition, ConditionType } from "@/types/workflow"; import { Plus, X, Check } from "lucide-react"; import { listPeople } from "@/handlers/api/people.handler"; import { IPerson } from "@/types/person"; import { PERSON_THUBNAIL_PATH } from "@/config/routes"; import { useEffect, useState } from "react"; import { cn } from "@/lib/utils"; const conditionTypeLabels: Record = { person: "Person", person_unnamed: "Unnamed People", city: "City", state: "State", country: "Country", geo_radius: "Geo Radius", date_range: "Date Range", date_relative: "Relative Date", day_of_week: "Day of Week", camera_make: "Camera Make", camera_model: "Camera Model", lens: "Lens", asset_type: "Asset Type", iso_range: "ISO Range", focal_length: "Focal Length", resolution: "Resolution", rating: "Rating", is_favorited: "Favorited", file_size: "File Size", filename: "File Name / Path", file_extension: "File Extension", face_count: "Face Count", time_of_day: "Time of Day", not_in_album: "Not in Any Album", not_in_specific_album: "Not in Specific Album", }; const conditionTypes = Object.keys(conditionTypeLabels) as ConditionType[]; interface PersonPickerProps { selectedIds: string[]; onChange: (personIds: string[], personNames: string[]) => void; } function PersonPicker({ selectedIds, onChange }: PersonPickerProps) { const [open, setOpen] = useState(false); const [people, setPeople] = useState([]); const [loading, setLoading] = useState(false); useEffect(() => { setLoading(true); listPeople({ page: 1, perPage: 500, sort: "createdAt", sortOrder: "desc", visibility: "visible", type: "named" }) .then((res) => setPeople(res.people)) .finally(() => setLoading(false)); }, []); const selectedSet = new Set(selectedIds || []); const selectedPeople = people.filter((p) => selectedSet.has(p.id)); const togglePerson = (person: IPerson) => { let nextIds: string[]; let nextNames: string[]; if (selectedSet.has(person.id)) { nextIds = selectedIds.filter((id) => id !== person.id); nextNames = selectedPeople.filter((p) => p.id !== person.id).map((p) => p.name); } else { nextIds = [...selectedIds, person.id]; nextNames = [...selectedPeople.map((p) => p.name), person.name]; } onChange(nextIds, nextNames); }; return (
{/* Selected people chips */} {selectedPeople.length > 0 && (
{selectedPeople.map((p) => ( ))}
)} {/* Picker */} {loading ? "Loading..." : "No people found."} {people.map((person) => ( togglePerson(person)} className="flex items-center gap-2" > {person.name || "Unknown"} ))}
); } interface ConditionEditorProps { conditions: ICondition[]; onChange: (conditions: ICondition[]) => void; } function ConditionFields({ condition, onChange }: { condition: ICondition; onChange: (c: ICondition) => void }) { switch (condition.type) { case "city": case "state": case "country": return (
onChange({ ...condition, [condition.type]: e.target.value })} />
); case "camera_make": return onChange({ ...condition, make: e.target.value })} />; case "camera_model": return onChange({ ...condition, model: e.target.value })} />; case "lens": return onChange({ ...condition, lensModel: e.target.value })} />; case "asset_type": return ( ); case "date_range": return (
onChange({ ...condition, after: e.target.value })} /> onChange({ ...condition, before: e.target.value })} />
); case "date_relative": return (
Last onChange({ ...condition, lastDays: parseInt(e.target.value) || 0 })} /> days
); case "iso_range": case "focal_length": return (
onChange({ ...condition, min: parseFloat(e.target.value) || undefined })} /> onChange({ ...condition, max: parseFloat(e.target.value) || undefined })} />
); case "rating": return (
onChange({ ...condition, min: parseInt(e.target.value) || undefined })} /> onChange({ ...condition, max: parseInt(e.target.value) || undefined })} />
); case "resolution": { const unit = (condition.metric || "megapixels") === "megapixels" ? "MP" : "px"; return (
onChange({ ...condition, min: e.target.value === "" ? undefined : parseFloat(e.target.value) })} /> onChange({ ...condition, max: e.target.value === "" ? undefined : parseFloat(e.target.value) })} />
); } case "is_favorited": return ( ); case "file_size": return (
onChange({ ...condition, min: e.target.value === "" ? undefined : parseFloat(e.target.value) })} /> onChange({ ...condition, max: e.target.value === "" ? undefined : parseFloat(e.target.value) })} />
); case "filename": return (
onChange({ ...condition, text: e.target.value })} />
); case "file_extension": return (
onChange({ ...condition, extensions: e.target.value })} />
); case "face_count": return (
onChange({ ...condition, min: e.target.value === "" ? undefined : parseInt(e.target.value) })} /> onChange({ ...condition, max: e.target.value === "" ? undefined : parseInt(e.target.value) })} /> faces
); case "time_of_day": return (
From onChange({ ...condition, fromHour: e.target.value === "" ? undefined : parseInt(e.target.value) })} /> to onChange({ ...condition, toHour: e.target.value === "" ? undefined : parseInt(e.target.value) })} /> h

Hours 0–23; From > To wraps past midnight (e.g. 22 to 5).

); case "person": return (
onChange({ ...condition, personIds, personNames })} />
); case "geo_radius": return (
onChange({ ...condition, lat: parseFloat(e.target.value) || 0 })} /> onChange({ ...condition, lng: parseFloat(e.target.value) || 0 })} />
onChange({ ...condition, radiusKm: parseFloat(e.target.value) || 0 })} /> km
); case "day_of_week": return (
{["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"].map((day, i) => { const days: number[] = condition.days || []; const active = days.includes(i); return ( ); })}
); case "not_in_album": case "person_unnamed": return null; case "not_in_specific_album": return onChange({ ...condition, albumId: e.target.value })} />; default: return null; } } export default function ConditionEditor({ conditions, onChange }: ConditionEditorProps) { const addCondition = () => { onChange([...conditions, { type: "city" }]); }; const removeCondition = (index: number) => { onChange(conditions.filter((_, i) => i !== index)); }; const updateCondition = (index: number, condition: ICondition) => { const next = [...conditions]; next[index] = condition; onChange(next); }; const changeType = (index: number, type: ConditionType) => { const next = [...conditions]; next[index] = { type }; onChange(next); }; return (
{conditions.map((condition, i) => (
updateCondition(i, c)} /> {i < conditions.length - 1 && (
AND
)}
))}
); }