import { jsx as _jsx } from "react/jsx-runtime";
import { TextField } from './text_field.js';
import { NumberField } from './number_field.js';
import { BooleanField } from './boolean_field.js';
import { OptionField } from './option_field.js';
import { DateField } from './date_field.js';
import { EmailField } from './email_field.js';
import { TelField } from './tel_field.js';
import { TextareaField } from './textarea_field.js';
import { CurrencyField } from './currency_field.js';
import { PercentageField } from './percentage_field.js';
import { ComputedField } from './computed_field.js';
import { StaticTextField } from './static_text_field.js';
import { SummaryRowField } from './summary_row_field.js';
import { MaskedField } from './masked_field.js';
import { TableField } from './table_field.js';
/**
 * Built-in renderer map
 */
const RENDERER_MAP = {
    text: TextField,
    inputbox: TextField,
    number: NumberField,
    boolean: BooleanField,
    checkbox: BooleanField,
    option: OptionField,
    combo: OptionField,
    radio: OptionField,
    date: DateField,
    email: EmailField,
    tel: TelField,
    textarea: TextareaField,
    currency: CurrencyField,
    percentage: PercentageField,
    computed: ComputedField,
    static_text: StaticTextField,
    summary_row: SummaryRowField,
    masked: MaskedField,
    table: TableField,
};
/**
 * Resolve field type to renderer component
 *
 * Resolution order:
 * 1. Check field_types_config for custom types (TFN, ABN, etc.)
 *    - If has display_format -> use masked_field
 *    - Otherwise use base_type renderer
 * 2. Fall back to built-in renderer map
 * 3. Default to TextField
 */
export function resolve_field_renderer(field_type, field_types_config) {
    const ft = field_type || 'text';
    // Check custom field types config
    if (field_types_config?.field_types[ft]) {
        const type_def = field_types_config.field_types[ft];
        if (type_def.display_format) {
            return MaskedField;
        }
        // Use the base_type renderer
        return RENDERER_MAP[type_def.base_type] || TextField;
    }
    // Built-in renderer
    return RENDERER_MAP[ft] || TextField;
}
/**
 * Normalize HazoCollabForm* component_type to short renderer key
 * e.g., "HazoCollabFormRadio" → "radio", "HazoCollabFormCombo" → "combo"
 */
function normalize_component_type(component_type) {
    if (!component_type)
        return undefined;
    const match = component_type.match(/^HazoCollabForm(\w+)$/i);
    if (match)
        return match[1].toLowerCase();
    return component_type;
}
/**
 * FieldRenderer component that dispatches to the correct renderer
 *
 * Resolution order:
 * 1. field_type (if specific, i.e. not generic "field")
 * 2. input_type (e.g., "combo", "radio")
 * 3. component_type (normalized from HazoCollabFormRadio → "radio")
 * 4. Falls through to resolve_field_renderer default (TextField)
 */
export function DataFormFieldRenderer(props) {
    const { field_type, input_type, component_type } = props.field;
    // "field" is a generic field_type that doesn't map to a specific renderer - skip it
    const effective_field_type = field_type && field_type !== 'field' ? field_type : undefined;
    const Renderer = resolve_field_renderer(effective_field_type || input_type || normalize_component_type(component_type), props.config.field_types_config);
    return _jsx(Renderer, { ...props });
}
// Re-export individual renderers for direct use
export { TextField, NumberField, BooleanField, OptionField, DateField, EmailField, TelField, TextareaField, CurrencyField, PercentageField, ComputedField, StaticTextField, SummaryRowField, MaskedField, TableField, };
//# sourceMappingURL=index.js.map