import { toggleListItem } from '@data-wrangling-components/utilities';
import upperFirst from 'lodash-es/upperFirst.js';
import { getEnumDropdownOptions } from '../enums.js';
import { getLeftColumn, getRightColumn, getSimpleDropdownOptions } from '../hooks/index.js';
import { FormInputType } from './VerbForm.js';
export function inputColumnList(step, columns, label = 'Columns') {
    return {
        required: true,
        label,
        placeholder: 'Choose columns',
        type: FormInputType.MultiChoice,
        options: getSimpleDropdownOptions(columns),
        current: step.args.columns,
        onChange: (s, opt)=>s.args.columns = toggleListItem(s.args.columns, opt)
    };
}
export function joinInputs(step, leftColumns, rightColumns, label = 'join') {
    const selectedLeftColumn = getLeftColumn(step);
    const selectedRightColumn = getRightColumn(step);
    return [
        dropdown(`Input ${label} key`, leftColumns, selectedLeftColumn, (s, opt)=>{
            if (!s.args.on) {
                s.args.on = [];
            }
            s.args.on[0] = opt;
        }, {
            required: true,
            placeholder: 'Choose column'
        }),
        dropdown(`${upperFirst(label)} table key`, rightColumns, selectedRightColumn, (s, opt)=>{
            if (s.args.on) {
                s.args.on[1] = opt;
            }
        }, {
            placeholder: 'Choose column'
        }), 
    ];
}
export function dropdown(label, values, current, onChange, opts = {}) {
    return {
        label,
        type: FormInputType.SingleChoice,
        options: getSimpleDropdownOptions(values),
        current,
        onChange,
        ...opts
    };
}
export function enumDropdown(label, enumeration, current, onChange, opts = {}, nameMapping) {
    return {
        label,
        type: FormInputType.SingleChoice,
        options: getEnumDropdownOptions(enumeration, nameMapping),
        current,
        onChange,
        ...opts
    };
}
export function checkbox(label, current, onChange, opts = {}) {
    return {
        label,
        type: FormInputType.Checkbox,
        current,
        onChange,
        ...opts
    };
}
