'use client';

import { Checkbox } from '@admin/components/ui/checkbox';
import { Label } from '@admin/components/ui/label';
import { cn } from '@admin/utils/common';
import { Controller, useFormContext } from 'react-hook-form';

interface CheckboxFieldProps {
    name: string;
    disabled?: boolean;
    className?: string;
    checkboxLabel?: string;
}

export const CheckboxField = ({ name, disabled, className, checkboxLabel }: CheckboxFieldProps) => {
    const { control } = useFormContext();

    return (
        <Controller
            control={control}
            name={name}
            render={({ field }) => (
                <div className="flex items-center space-x-2">
                    <Checkbox checked={field.value || false} onCheckedChange={field.onChange} disabled={disabled} className={cn(className)} />
                    {checkboxLabel && <Label className="cursor-pointer">{checkboxLabel}</Label>}
                </div>
            )}
        />
    );
};
