/**
 * Collaboration form checkbox component
 * Provides a reusable checkbox field with label, error message, and chat icon functionality
 */
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from 'react';
import { cn } from '../utils/cn.js';
import { get_dom_safe_props } from '../utils/filter_dom_props.js';
import { CollabFormFieldContainer, CollabFormFieldLabel, CollabFormFieldError, CollabFormFieldReferenceTag, CollabFormFileUploadSection, CollabFormAddEntryIcon, CollabFormDeleteEntryIcon, } from './hazo_collab_form_base.js';
import { UnifiedFieldControls } from './shared/unified_field_controls/index.js';
import { use_base_form_field } from './shared/use_base_form_field.js';
import { use_field_action_slot } from './shared/use_field_action_slot.js';
import { strip_base_props } from './shared/strip_base_props.js';
/**
 * Collaboration form checkbox component
 * Has a unique layout: checkbox + inline label + controls on right, not using BaseFieldLayout
 */
export const HazoCollabFormCheckbox = React.forwardRef((props, ref) => {
    const base = use_base_form_field(props, ref);
    const { row_end, row_below } = use_field_action_slot(base.entry_props.field_id);
    if (base.should_hide)
        return null;
    const { checked, onChange, field_validator, checkbox_label, checkbox_wrapper_class_name, checkbox_label_class_name, } = props;
    const handle_change = React.useCallback((e) => {
        const new_value = e.target.checked;
        if (field_validator) {
            base.set_validation_error(field_validator(new_value));
        }
        onChange(new_value);
    }, [field_validator, onChange, base.set_validation_error]);
    const checkbox_label_text = checkbox_label ?? base.label_props.label;
    // Strip base props for DOM rest attributes
    const rest_props = strip_base_props(props);
    delete rest_props.checked;
    delete rest_props.onChange;
    return (_jsxs(CollabFormFieldContainer, { ...base.container_props, children: [_jsx(CollabFormFieldLabel, { ...base.label_props }), _jsxs("div", { className: cn('cls_collab_checkbox_wrapper flex items-center gap-2', checkbox_wrapper_class_name, base.is_hidden && base.user_role === 'author' && 'opacity-50'), suppressHydrationWarning: true, children: [_jsx("input", { ref: base.component_ref, id: base.field_id_final, type: "checkbox", checked: checked, onChange: handle_change, disabled: base.is_field_disabled, className: cn('cls_collab_checkbox h-4 w-4 rounded border border-input bg-transparent text-primary shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50', base.display_error && 'border-destructive focus-visible:ring-destructive', base.locked && 'bg-slate-100', base.skipped && 'bg-slate-100 opacity-60', base.className), "aria-invalid": base.display_error ? 'true' : 'false', "aria-describedby": base.display_error ? `${base.field_id_final}-error` : undefined, ...get_dom_safe_props(rest_props) }), _jsx("label", { htmlFor: base.field_id_final, className: cn('cls_collab_checkbox_label text-sm font-medium leading-none cursor-pointer peer-disabled:cursor-not-allowed peer-disabled:opacity-70 flex-1', checkbox_label_class_name), children: checkbox_label_text }), _jsxs("div", { className: "cls_collab_checkbox_actions flex items-center gap-2 flex-shrink-0", children: [base.entry_props.show_add_entry && (_jsx(CollabFormAddEntryIcon, { label: base.entry_props.label, field_id: base.entry_props.field_id, on_add_entry: base.entry_props.on_add_entry, borderless: base.entry_props.action_buttons_borderless })), base.entry_props.is_additional_entry && base.entry_props.on_delete_entry && (_jsx(CollabFormDeleteEntryIcon, { label: base.entry_props.label, field_id: base.entry_props.field_id, on_delete_entry: base.entry_props.on_delete_entry })), _jsx(UnifiedFieldControls, { ...base.controls_props }), row_end] })] }), row_below && _jsx("div", { className: "cls_field_action_below", children: row_below }), _jsx(CollabFormFieldReferenceTag, { ...base.reference_tag_props }), _jsx(CollabFormFieldError, { ...base.error_props }), _jsx(CollabFormFileUploadSection, { ...base.file_upload_props })] }));
});
HazoCollabFormCheckbox.displayName = 'HazoCollabFormCheckbox';
//# sourceMappingURL=hazo_collab_form_checkbox.js.map