"use client";
import { jsx as _jsx } from "react/jsx-runtime";
import { useEditContext } from "../client/editContext";
import { Checkbox } from "../../components/ui/checkbox";
import { useEffect, useState } from "react";
import { Loader2 } from "lucide-react";
export function CheckboxEditor({ field, readOnly, }) {
    const editContext = useEditContext();
    const [isUpdating, setIsUpdating] = useState(false);
    useEffect(() => {
        setIsUpdating(false);
    }, [field]);
    if (!editContext)
        return;
    const fieldItem = field.descriptor.item;
    if (!fieldItem)
        return;
    if (isUpdating) {
        return (_jsx(Loader2, { strokeWidth: 1, className: "h-[18px] w-[18px] animate-spin" }));
    }
    const isChecked = field.value === true || field.rawValue === "1";
    return (_jsx(Checkbox, { checked: isChecked, disabled: readOnly, className: "focus-shadow", onCheckedChange: (checked) => {
            setIsUpdating(true);
            editContext.operations.editField({
                field: field.descriptor,
                rawValue: checked ? "1" : "0",
                value: checked,
                refresh: "immediate",
            });
        } }, fieldItem.id + field.id + fieldItem.language + fieldItem.version));
}
//# sourceMappingURL=CheckboxEditor.js.map