import { InputNumber } from 'primereact/inputnumber';
import parseLocaleNumber from '../../../../../../../helpers/parseLocaleNumber';

const NumericFormulaCell = ({ getValue, row: { index }, column: { id }, table }) => {
    const initialValue = getValue();
    const disabled = table.options.meta?.disabled;

    const onFocus = (e) => {
        e.target.select();
    }

    /*const onChange = (value) => {
        console.log('table.options.meta', table.options.meta)
        table.options.meta?.updateData(index, id, value);
    };*/

    const onBlur = (value) => {
        table.options.meta?.updateData(index, id, value);
    };

    return (
        <InputNumber
            disabled={disabled}
            value={parseLocaleNumber(initialValue)}
            /*onValueChange={(e) => onChange(e.value)}*/
            onFocus={onFocus}
            onBlur={(e) => onBlur(e.target.value)}
            minFractionDigits={0}
            maxFractionDigits={2}
            locale='it-IT'
            useGrouping={false}
            showButtons
        />
    );
};

export default NumericFormulaCell;