"use client";
import * as React from "react";
import { X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem, ComboboxList } from "@/components/ui/combobox";
const hours = Array.from({ length: 24 }, (_, index) => index.toString().padStart(2, "0"));
const minutes = Array.from({ length: 60 }, (_, index) => index.toString().padStart(2, "0"));
function splitTime(value?: string) {
const match = value?.slice(0, 5).match(/^(\d{2}):(\d{2})$/);
return match ? { hour: match[1], minute: match[2] } : { hour: undefined, minute: undefined };
}
function TimePart({
value,
items,
max,
placeholder,
ariaLabel,
onValueChange,
}: {
value?: string;
items: string[];
max: number;
placeholder: string;
ariaLabel: string;
onValueChange: (value: string) => void;
}) {
const [inputValue, setInputValue] = React.useState(value ?? "");
React.useEffect(() => setInputValue(value ?? ""), [value]);
const commit = (raw: string) => {
const digits = raw.replace(/\D/g, "").slice(0, 2);
if (!digits) {
setInputValue("");
return;
}
const number = Number(digits);
if (number > max) {
setInputValue(value ?? "");
return;
}
const next = digits.padStart(2, "0");
setInputValue(next);
onValueChange(next);
};
return (