/**
 * Collaboration form radio component
 * Provides a reusable radio button group with labels, error message, data OK checkbox, 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 radio component
 * Has a unique layout: label + controls header row, radio options below
 */
export const HazoCollabFormRadio = 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 { options, value, onChange, field_validator, layout = 'vertical', radio_wrapper_class_name, radio_option_wrapper_class_name, } = props;
    const handle_change = React.useCallback((e) => {
        const new_value = e.target.value;
        if (field_validator) {
            base.set_validation_error(field_validator(new_value));
        }
        onChange(new_value);
    }, [field_validator, onChange, base.set_validation_error]);
    // Strip base props for DOM rest attributes
    const rest_props = strip_base_props(props);
    delete rest_props.options;
    delete rest_props.value;
    delete rest_props.onChange;
    return (_jsxs(CollabFormFieldContainer, { ...base.container_props, children: [_jsxs("div", { className: cn('cls_collab_radio_label_actions_wrapper flex items-center justify-between gap-2', base.is_hidden && base.user_role === 'author' && 'opacity-50'), children: [_jsx(CollabFormFieldLabel, { ...base.label_props }), _jsxs("div", { className: "cls_collab_radio_actions flex items-center gap-2 flex-shrink-0", suppressHydrationWarning: true, 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] })] }), _jsx("div", { className: cn('cls_collab_radio_wrapper', layout === 'horizontal' && 'flex flex-row items-center gap-4', layout === 'vertical' && 'flex flex-col gap-4', base.locked && 'bg-slate-100 rounded-md p-2', base.skipped && 'bg-slate-100 opacity-60 rounded-md p-2', radio_wrapper_class_name), children: options.map((option, index) => {
                    const option_id = `${base.field_id_final}-${option.value}`;
                    return (_jsxs("div", { className: cn('cls_collab_radio_option_wrapper flex items-center gap-2', radio_option_wrapper_class_name), children: [_jsx("input", { ref: index === 0 ? base.component_ref : undefined, id: option_id, type: "radio", name: base.field_id_final, value: option.value, checked: value === option.value, onChange: handle_change, disabled: base.is_field_disabled || option.disabled, className: cn('cls_collab_radio h-4 w-4 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.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: option_id, className: cn('cls_collab_radio_label text-sm font-medium leading-none cursor-pointer peer-disabled:cursor-not-allowed peer-disabled:opacity-70', base.display_error && 'text-destructive'), children: option.label })] }, option.value));
                }) }), 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 })] }));
});
HazoCollabFormRadio.displayName = 'HazoCollabFormRadio';
//# sourceMappingURL=hazo_collab_form_radio.js.map