/*!
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project.
 */ import { toggleListItem } from '@datashaper/utilities';
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),
        onChangeAll: (s, opts)=>s.args.columns = opts
    };
}
export function joinInputs(step, leftColumns, rightColumns) {
    const selectedLeftColumn = getLeftColumn(step);
    const selectedRightColumn = getRightColumn(step);
    return [
        dropdown(`Join key column`, leftColumns, selectedLeftColumn, (s, opt)=>{
            if (!s.args.on) {
                s.args.on = [];
            }
            s.args.on[0] = opt;
        }, {
            required: true,
            placeholder: 'Choose column'
        }),
        dropdown(`Second table key column`, rightColumns, selectedRightColumn, (s, opt)=>{
            if (s.args.on) {
                s.args.on[1] = opt;
            }
        }, {
            placeholder: 'Choose column',
            advanced: true
        }), 
    ];
}
export function dropdown(label, values, current, onChange, opts = {}) {
    return {
        label,
        type: FormInputType.SingleChoice,
        options: getSimpleDropdownOptions(values),
        current,
        onChange,
        ...opts
    };
}
export function tableDropdown(label, options, current, onChange, opts = {}) {
    return {
        label,
        type: FormInputType.SingleChoice,
        options,
        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
    };
}
