/**
 * Collaboration form computed field component
 * Read-only display field that formats values as currency/percentage/number
 * Shows formula hint on hover when computed_formula exists
 */
'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { cn } from '../utils/cn.js';
import { format_currency, format_percentage } from '../utils/financial_format.js';
import { use_base_form_field } from './shared/use_base_form_field.js';
import { BaseFieldLayout } from './shared/base_field_layout.js';
/**
 * Format a computed value based on field configuration
 */
function format_computed_value(value, is_percentage, currency_symbol, decimal_places = 2) {
    const num = typeof value === 'number' ? value : parseFloat(String(value));
    if (isNaN(num))
        return String(value ?? '');
    if (is_percentage) {
        return format_percentage(num, decimal_places);
    }
    // Default to currency formatting when currency_symbol is set
    if (currency_symbol) {
        return format_currency(num, currency_symbol, decimal_places);
    }
    // Plain number
    return num.toFixed(decimal_places);
}
/**
 * Collaboration form computed field component
 */
export const HazoCollabFormComputed = React.forwardRef((props, ref) => {
    const base = use_base_form_field(props, ref);
    if (base.should_hide)
        return null;
    const { value, currency_symbol = '$', decimal_places = 2, is_percentage, computed_formula, input_wrapper_class_name, } = props;
    const formatted = format_computed_value(value, is_percentage, currency_symbol, decimal_places);
    return (_jsx(BaseFieldLayout, { base: base, wrapper_class_name: "cls_collab_computed_wrapper", wrapper_extra_class_name: input_wrapper_class_name, children: _jsx("div", { ref: base.component_ref, id: base.field_id_final, title: computed_formula ? `Formula: ${computed_formula}` : undefined, className: cn('cls_collab_computed w-full h-9 rounded-md border border-input bg-slate-50 px-3 py-1 text-base flex items-center md:text-sm cursor-default', computed_formula && 'cursor-help', base.className), children: formatted }) }));
});
HazoCollabFormComputed.displayName = 'HazoCollabFormComputed';
//# sourceMappingURL=hazo_collab_form_computed.js.map