import { LanguageType, PresentationConfig } from "../type"; import { useEffect, useRef, useState } from "react"; import { Check, ChevronUp, Languages } from "lucide-react"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; import { Input } from "@/components/ui/input"; import AdvanceSettings from "./AdvanceSettings"; import { clampSlideCountValue, MAX_NUMBER_OF_SLIDES, } from "@/utils/presentationLimits"; // Types interface ConfigurationSelectsProps { config: PresentationConfig; onConfigChange: (key: keyof PresentationConfig, value: any) => void; } type SlideOption = | "5" | "8" | "9" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" | "18" | "19" | "20"; // Constants const SLIDE_OPTIONS: SlideOption[] = [ "5", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", ]; /** * Renders a select component for slide count */ const SlideCountSelect: React.FC<{ value: string | null; onValueChange: (value: string) => void; open: boolean; onOpenChange: (open: boolean) => void; }> = ({ value, onValueChange, open, onOpenChange }) => { const [customInput, setCustomInput] = useState( value && !SLIDE_OPTIONS.includes(value as SlideOption) ? value : "" ); const isSelectingPresetRef = useRef(false); useEffect(() => { if (value && !SLIDE_OPTIONS.includes(value as SlideOption)) { setCustomInput(value); } else { setCustomInput(""); } }, [value]); useEffect(() => { if (!open) { isSelectingPresetRef.current = false; } }, [open]); const sanitizeToPositiveInteger = (raw: string): string => { return clampSlideCountValue(raw); }; const applyCustomValue = () => { const sanitized = sanitizeToPositiveInteger(customInput); if (sanitized && Number(sanitized) > 0) { onValueChange(sanitized); onOpenChange(false); } }; const displayLabel = value ? `${value} slides` : "Auto slides"; return (
e.stopPropagation()} onPointerDown={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()} >
e.stopPropagation()} onPointerDown={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()} onChange={(e) => { const next = sanitizeToPositiveInteger(e.target.value); setCustomInput(next); }} onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); applyCustomValue(); } }} onBlur={() => { if (!isSelectingPresetRef.current) { applyCustomValue(); } }} placeholder="--" className="h-8 w-16 px-2 text-sm min-[1800px]:h-9 min-[1800px]:w-20 min-[1800px]:text-base" /> slides
{SLIDE_OPTIONS.map((option) => ( { isSelectingPresetRef.current = true; }} onMouseDownCapture={() => { isSelectingPresetRef.current = true; }} onSelect={() => { onValueChange(option); setCustomInput(""); isSelectingPresetRef.current = false; onOpenChange(false); }} className="font-syne text-sm font-medium min-[1800px]:text-base" > {option} slides ))}
); }; /** * Renders a language selection component with search functionality */ const LanguageSelect: React.FC<{ value: string | null; onValueChange: (value: string) => void; open: boolean; onOpenChange: (open: boolean) => void; }> = ({ value, onValueChange, open, onOpenChange }) => ( No language found. {Object.values(LanguageType).map((language) => ( { onValueChange(currentValue); onOpenChange(false); }} className="font-instrument_sans" > {language} ))} ); export function ConfigurationSelects({ config, onConfigChange, }: ConfigurationSelectsProps) { const [openSlides, setOpenSlides] = useState(false); const [openLanguage, setOpenLanguage] = useState(false); return (
onConfigChange("slides", value)} open={openSlides} onOpenChange={setOpenSlides} /> onConfigChange("language", value)} open={openLanguage} onOpenChange={setOpenLanguage} />
); }