import * as React from 'react' import {__, _x} from '@wordpress/i18n' import { BaseControl, ToggleControl, __experimentalVStack as VStack, } from '@wordpress/components' import { ButtonGroup, } from '@ska/components' import { useSkaBlocksDispatch, } from '../../../../tailwind/reducer' import type { tBlockAttributes, tBlockEditProps, } from '@ska/shared' import { createOptions, } from './util' import { isOptionSelector, } from '../..' import './style.scss' export interface SelectorOptionsProps { attributes: tBlockAttributes setAttributes: tBlockEditProps['setAttributes'] } const SelectorOptions: React.FC = ({ attributes, setAttributes, }) => { const { skaBlocksSelectors = {}, skaBlocksOptions = {}, } = attributes const dispatch = useSkaBlocksDispatch(attributes, setAttributes) const selectors = Object.keys(skaBlocksSelectors) if(!selectors.length) { return null } const optionSelectors = selectors.filter(isOptionSelector) if(!optionSelectors.length) { return null } const options = createOptions(optionSelectors) return <> {options.map(({type, label, options = []}) => { switch(type) { case 'toggle': return ( dispatch.setSelectorOption({option: label, value: !skaBlocksOptions[label]})} __nextHasNoMarginBottom /> ) case 'select': return ( v !== 'DEFAULT').map(option => ({label: option, value: option})))} value={skaBlocksOptions[label] || 'DEFAULT'} onChange={(nextValue) => dispatch.setSelectorOption({option: label, value: nextValue ? nextValue : 'DEFAULT'})} /> ) default: return null } })} } export default SelectorOptions