/**
 * Collaboration form currency input component
 * Provides a number input with currency symbol prefix and formatted display
 */
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from 'react';
import { cn } from '../utils/cn.js';
import { format_currency } from '../utils/financial_format.js';
import { get_dom_safe_props } from '../utils/filter_dom_props.js';
import { use_base_form_field } from './shared/use_base_form_field.js';
import { BaseFieldLayout } from './shared/base_field_layout.js';
import { strip_base_props } from './shared/strip_base_props.js';
/**
 * Collaboration form currency input component
 */
export const HazoCollabFormCurrency = React.forwardRef((props, ref) => {
    const base = use_base_form_field(props, ref);
    if (base.should_hide)
        return null;
    const { value, onChange, field_validator, currency_symbol = '$', decimal_places = 2, input_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 to get only DOM-safe attributes
    const rest_props = strip_base_props(props);
    delete rest_props.value;
    delete rest_props.onChange;
    delete rest_props.currency_symbol;
    delete rest_props.decimal_places;
    delete rest_props.input_wrapper_class_name;
    const is_readonly = base.locked || base.skipped;
    const numeric_value = typeof value === 'number' ? value : parseFloat(String(value));
    const display_formatted = !isNaN(numeric_value) ? format_currency(numeric_value, currency_symbol, decimal_places) : '';
    return (_jsx(BaseFieldLayout, { base: base, wrapper_class_name: "cls_collab_currency_wrapper", wrapper_extra_class_name: input_wrapper_class_name, children: is_readonly ? (_jsx("div", { className: cn('cls_collab_currency_display w-full h-9 rounded-md border border-input bg-slate-100 px-3 py-1 text-base flex items-center md:text-sm', base.skipped && 'opacity-60'), children: display_formatted || String(value ?? '') })) : (_jsxs("div", { className: "relative w-full", children: [_jsx("span", { className: "absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm pointer-events-none", children: currency_symbol }), _jsx("input", { ref: base.component_ref, id: base.field_id_final, type: "number", step: decimal_places > 0 ? `0.${'0'.repeat(decimal_places - 1)}1` : '1', value: String(value ?? ''), onChange: handle_change, disabled: base.is_field_disabled, className: cn('cls_collab_currency w-full h-9 rounded-md border border-input bg-transparent pl-7 pr-3 py-1 text-base shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm', base.display_error && 'border-destructive focus-visible:ring-destructive', base.show_required_highlight && 'bg-red-50', 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) })] })) }));
});
HazoCollabFormCurrency.displayName = 'HazoCollabFormCurrency';
//# sourceMappingURL=hazo_collab_form_currency.js.map