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 (