/*!
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project.
 */ import { jsx as _jsx } from "react/jsx-runtime";
import { DataType, ParseType } from '@datashaper/schema';
import { num } from '@datashaper/utilities';
import { memo, useMemo } from 'react';
import { getDateFormatPatternOptions } from '../dateFormats.js';
import { getEnumDropdownOptions } from '../enums.js';
import { FormInputType, VerbForm } from '../verbForm/VerbForm.js';
/**
 * Provides inputs for a Convert step.
 */ export const ConvertBase = /*#__PURE__*/ memo(function ConvertBase({ step , onChange , fields  }) {
    const inputs = useMemo(()=>[
            {
                label: 'Data type',
                placeholder: 'Choose type',
                required: true,
                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(fields, step.args.column),
                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',
                allowFreeform: true,
                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,
        fields
    ]);
    return /*#__PURE__*/ _jsx(VerbForm, {
        inputs: inputs,
        step: step,
        onChange: onChange
    });
});
function isInputColumnArray(fields, column) {
    const meta = fields.find((field)=>field.name === column);
    return meta?.type === DataType.Array;
}
