import { sanitizeOptionSelectorLabel, unwrapOptionSelector, } from '../..' export const createOptions = (selectors: string[]) => { const options: { type: 'toggle' | 'select' label: string options?: string[] }[] = [] selectors.forEach(s => { const selector = unwrapOptionSelector(s) if(selector.indexOf('=') === -1) { const label = sanitizeOptionSelectorLabel(selector) if(options.findIndex(({label: optionLabel}) => optionLabel === label) === -1) { options.push({ label, type: 'toggle', }) } return } const [rawLabel = '', value = ''] = selector.split('=') if(!rawLabel || !value) { return } const label = sanitizeOptionSelectorLabel(rawLabel) const option = options.findIndex(({type, label: optionLabel}) => type === 'select' && optionLabel === label) if(option > -1) { options[option]['options'] = options[option]['options']!.concat(value) } else { options.push({ label, type: 'select', options: [value], }) } }) return options }