import { useEffect, useState, Fragment, createElement, createPortal, } from '@wordpress/element' import useForceUpdate from '../containers/use-force-update' import Overlay from '../../customizer/components/Overlay' import { __, sprintf } from 'ct-i18n' import { getFirstLevelOptions } from '../helpers/get-value-from-input' import Select from './ct-select' import classnames from 'classnames' const OptionsActions = ({ option, option: { areas, prefix }, onChangeFor }) => { const [isOverlayOpen, setIsOverlayOpen] = useState(false) const [currentPrefix, setCurrentPrefix] = useState(false) const [currentOptionsArea, setCurrentOptionsArea] = useState(false) const forceUpdate = useForceUpdate() const maybePostsListing = areas.find((area) => area.id === 'posts_listing') const maybePageStructure = areas.find( (area) => area.id === 'page_structure' ) const allAreas = [ { title: __('All Options', 'blocksy'), sources: maybePageStructure ? maybePageStructure.sources : maybePostsListing ? maybePostsListing.sources : null, }, ...areas, ] const sources = currentOptionsArea && allAreas.find(({ title }) => title === currentOptionsArea) && allAreas.find(({ title }) => title === currentOptionsArea).sources ? allAreas.find(({ title }) => title === currentOptionsArea).sources : areas.reduce( (acc, { sources }) => [ ...acc, ...sources.filter( ({ title }) => !acc.find(({ title: t }) => t === title) ), ], [] ) useEffect(() => { const wrapper = document .querySelector( '.customize-control-ct-options .ct-options-container' ) .closest('ul') .firstElementChild.firstElementChild.insertAdjacentHTML( 'beforeend', '
' ) }, []) if ( !document.querySelector( '.customize-control-ct-options .ct-options-container' ) ) { setTimeout(() => { forceUpdate() }, 100) return null } const maybeTarget = document .querySelector('.customize-control-ct-options .ct-options-container') .closest('ul') .querySelector('.ct-customize-section-title-actions') if (!maybeTarget) { setTimeout(() => { forceUpdate() }, 100) return null } return createPortal( {__('Advanced', 'blocksy')} { setIsOverlayOpen(false) }} render={() => (

{sprintf(__('Copy Options', 'blocksy'))}

{__( '1. Choose what set of options you want to copy:', 'blocksy' )}

{allAreas.map(({ title, options }) => (
{ setCurrentOptionsArea(title) }} key={title}> {title}
))}

{__('2. Choose options source:', 'blocksy')}