import { jsx as _jsx } from "react/jsx-runtime";
import { ParseType } from '@data-wrangling-components/core';
import { num } from '@data-wrangling-components/utilities';
import { DataType } from '@essex/arquero';
import { memo, useMemo } from 'react';
import { getDateFormatPatternOptions } from '../dateFormats.js';
import { getEnumDropdownOptions } from '../enums.js';
import { FormInputType, VerbForm } from '../verbForm/VerbForm.js';
import { inputColumnList } from '../verbForm/VerbFormFactories.js';
/**
 * Provides inputs for a Convert step.
 */ export const ConvertBase = /*#__PURE__*/ memo(function ConvertBase({ step , onChange , columns , columnsMetadata  }) {
    const inputs = useMemo(()=>[
            inputColumnList(step, columns, 'Columns to Convert'),
            {
                label: 'Data type',
                type: FormInputType.SingleChoice,
                current: step.args.type,
                options: getEnumDropdownOptions(ParseType),
                onChange: (s, opt)=>s.args.type = opt
            },
            {
                label: 'Base (radix)',
                if: step.args.type === ParseType.Integer,
                type: FormInputType.Text,
                current: step.args.radix ? `${step.args.radix}` : '',
                onChange: (s, opt)=>s.args.radix = num(opt)
            },
            {
                label: 'Delimiter',
                if: step.args.type === ParseType.Array || isInputColumnArray(columnsMetadata, step.args.columns),
                type: FormInputType.Text,
                current: step.args.delimiter ? `${step.args.delimiter}` : '',
                onChange: (s, opt)=>s.args.delimiter = opt
            },
            {
                label: 'Date format pattern',
                if: step.args.type === ParseType.Date,
                type: FormInputType.ComboBox,
                options: getDateFormatPatternOptions(),
                placeholder: 'pattern',
                current: step.args.formatPattern ? `${step.args.formatPattern}` : undefined,
                onChange: (s, opt, value)=>s.args.formatPattern = opt ? opt : value,
                onInputValueChange: (s, value)=>s.args.formatPattern = value ? value : '%Y-%m-%d'
            }, 
        ], [
        step,
        columns,
        columnsMetadata
    ]);
    return /*#__PURE__*/ _jsx(VerbForm, {
        inputs: inputs,
        step: step,
        onChange: onChange
    });
});
function isInputColumnArray(columnsMetadata, columns) {
    return columns.some((column)=>{
        const meta1 = columnsMetadata.find((meta)=>meta.columnName === column);
        return meta1?.type === DataType.Array;
    });
}
