import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { cn } from '../../../utils/cn.js';
import { DataFormLabel } from './data_form_label.js';
import { DataFormBadge } from './data_form_badge.js';
import { DataFormReferenceValue } from './data_form_reference_value.js';
import { DataFormFileColumn } from './data_form_file_column.js';
import { FieldActionSlot } from '../../shared/field_action_slot.js';
import { FieldActionArraySlot } from '../../shared/field_action_array_slot.js';
export function DataFormFieldLayout({ field, mode, value, error, config, on_doc_link_click, badge_column_width, value_column_width, field_uploads, on_upload_click, upload_enabled, reserve_file_column, children, paired_children, computed_formula, reference_annotation, reference_entries, on_reference_delete, reference_background_color, force_layout, hide_label, section_id, group_id, field_action_components, field_actions, }) {
    const slot_ctx = {
        components: field_action_components,
        field,
        value,
        mode,
        section_id,
        group_id,
    };
    const action_ctx = {
        field,
        value,
        mode,
        section_id,
        group_id,
    };
    const has_field_actions = field_actions && field_actions.length > 0;
    const action_slot = has_field_actions
        ? _jsx(FieldActionArraySlot, { actions: field_actions, position: "row_end", ctx: action_ctx })
        : _jsx(FieldActionSlot, { ...slot_ctx, slot: "row_end" });
    const action_slot_below = has_field_actions
        ? _jsx(FieldActionArraySlot, { actions: field_actions, position: "row_below", ctx: action_ctx })
        : (field_action_components?.row_below
            ? _jsx("div", { className: "cls_field_action_below", children: _jsx(FieldActionSlot, { ...slot_ctx, slot: "row_below" }) })
            : null);
    const layout = force_layout || field.label_position || 'inline';
    const is_inline = layout === 'inline';
    const has_badge = Boolean(field.badge || field.formula_label);
    const has_error = Boolean(error);
    const has_files = Boolean((field.doc_links && field.doc_links.length > 0) ||
        (field_uploads && field_uploads.length > 0) ||
        upload_enabled);
    // Show file column area (active or spacer) to keep fields aligned
    const show_file_area = has_files || reserve_file_column;
    const error_style = config.style_resolver.has_style('error_message')
        ? config.style_resolver.to_style('error_message')
        : undefined;
    const row_style = field.row_variant === 'highlight' && config.style_resolver.has_style('highlight_row')
        ? config.style_resolver.to_style('highlight_row')
        : undefined;
    if (is_inline) {
        return (_jsxs(_Fragment, { children: [_jsxs("div", { className: cn('cls_data_form_field_row', 'flex items-center gap-2 py-1', has_error && 'items-start'), style: row_style, "data-field-id": field.id, children: [!hide_label && (_jsx("div", { className: "cls_data_form_label_col flex-1 min-w-0", children: _jsx(DataFormLabel, { field: field, config: config, computed_formula: computed_formula }) })), has_badge && (_jsx(DataFormBadge, { badge: field.badge, formula_label: field.formula_label, config: config, column_width: badge_column_width })), _jsxs("div", { className: "cls_data_form_value_col shrink-0", style: {
                                width: field.value_width || value_column_width || '200px',
                            }, children: [children, has_error && (_jsx("div", { className: "cls_data_form_error", style: error_style, children: error })), (reference_annotation || (reference_entries && reference_entries.length > 0)) && (_jsx(DataFormReferenceValue, { value: reference_annotation, background_color: reference_background_color, entries: reference_entries, on_delete: on_reference_delete }))] }), paired_children && (_jsx("div", { className: "cls_data_form_value_col cls_data_form_paired_col shrink-0", style: {
                                width: field.paired_field?.value_width || value_column_width || '200px',
                            }, children: paired_children })), action_slot, show_file_area && (has_files ? (_jsx(DataFormFileColumn, { doc_links: field.doc_links, field_uploads: field_uploads, on_doc_link_click: on_doc_link_click, on_upload_click: on_upload_click, upload_enabled: upload_enabled, mode: mode, config: config })) : (_jsx("div", { className: "cls_data_form_file_col_spacer shrink-0 ml-1", style: { width: 26 } })))] }), action_slot_below] }));
    }
    // Stacked layout
    return (_jsxs(_Fragment, { children: [_jsxs("div", { className: cn('cls_data_form_field_stacked', 'flex flex-col gap-1 py-1'), style: row_style, "data-field-id": field.id, children: [!hide_label && (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(DataFormLabel, { field: field, config: config, computed_formula: computed_formula }), has_badge && (_jsx(DataFormBadge, { badge: field.badge, formula_label: field.formula_label, config: config }))] })), _jsxs("div", { className: "flex items-start gap-1", children: [_jsxs("div", { className: "flex-1 min-w-0", children: [children, has_error && (_jsx("div", { className: "cls_data_form_error", style: error_style, children: error })), (reference_annotation || (reference_entries && reference_entries.length > 0)) && (_jsx(DataFormReferenceValue, { value: reference_annotation, background_color: reference_background_color, entries: reference_entries, on_delete: on_reference_delete }))] }), action_slot, show_file_area && (has_files ? (_jsx(DataFormFileColumn, { doc_links: field.doc_links, field_uploads: field_uploads, on_doc_link_click: on_doc_link_click, on_upload_click: on_upload_click, upload_enabled: upload_enabled, mode: mode, config: config })) : (_jsx("div", { className: "cls_data_form_file_col_spacer shrink-0 ml-1", style: { width: 26 } })))] })] }), action_slot_below] }));
}
//# sourceMappingURL=data_form_field_layout.js.map