import {
createElement,
useMemo,
useRef,
useEffect,
useContext
} from '@wordpress/element'
import OptionsPanel from '../OptionsPanel'
import { normalizeCondition, matchValuesWithCondition } from 'match-conditions'
import {
useDeviceManagerState,
useDeviceManagerActions
} from '../../customizer/components/useDeviceManager'
import { capitalizeFirstLetter, optionWithDefault } from '../GenericOptionType'
import deepEqual from 'deep-equal'
import ResponsiveControls from '../../customizer/components/responsive-controls'
import { getOptionLabelFor } from '../helpers/get-label'
const SingleChoice = ({
singleChoice,
groupOption,
purpose,
onChange,
value,
hasRevertButton,
parentValue
}) => {
return (
{singleChoice.label && }
)
}
const LabeledGroup = ({
renderingChunk,
value,
onChange,
purpose,
parentValue,
hasRevertButton
}) => {
const { currentView } = useDeviceManagerState()
const { setDevice } = useDeviceManagerActions()
return renderingChunk.map((groupOption) => {
let valueForCondition = null
if (!valueForCondition) {
valueForCondition = {
...value,
wp_customizer_current_view: currentView
}
}
const totalAmountofMatched = groupOption.choices.filter(
(singleChoice) =>
singleChoice.condition
? matchValuesWithCondition(
normalizeCondition(singleChoice.condition),
valueForCondition
)
: true
)
let maybeLabel = getOptionLabelFor({
id: groupOption.id,
option: groupOption,
values: value
})
if (totalAmountofMatched.length === 0) {
return null
}
if (totalAmountofMatched.length === 1) {
return (
)
}
return (
{maybeLabel && }
{groupOption.responsive && (
)}
{totalAmountofMatched.map((singleChoice) => (
))}
)
})
}
export default LabeledGroup