import * as React from 'react' import { useContext, useState, useMemo, } from '@wordpress/element' import { __experimentalVStack as VStack, __experimentalHStack as HStack, __experimentalGrid as Grid, __experimentalView as View, Button, } from '@wordpress/components' import { store as coreDataStore, } from '@wordpress/core-data' import { useSelect, } from '@wordpress/data' import { Pre, DiffView, ImportExportStringsContext, } from '@ska/components' import { createUseOptionsEdit, type RootKey, type Option, } from '@ska/plugin' import { getSchema, } from './util' export interface OptionImporterProps { /** Slug on plugin options, `ska_theme`, `ska_blocks`, etc. */ slug: RootKey /** Value to import. */ valueToImport: any } const OptionImporter: React.FC = ({ slug, valueToImport, }) => { const isTailwind = slug === 'ska_blocks_tailwind4' const currentValue = useSelect((select) => { const { getEditedEntityRecord, } = select(coreDataStore) // @ts-ignore const site: Record = getEditedEntityRecord('root', 'site', undefined!) || {} const { // @ts-ignore [slug]: currentValue = {}, } = site return currentValue }, [slug]) const {schema, useOptionsEdit} = useMemo(() => { return { schema: getSchema(slug), useOptionsEdit: createUseOptionsEdit(slug, currentValue), } }, [slug, currentValue]) const [, dispatch] = useOptionsEdit() const { importLabel, currentValueLabel, importedValueLabel, nothingToImportMessage, } = useContext(ImportExportStringsContext) const [imported, setImported] = useState([]) const importableOptions = schema.flatMap(category => { return category.options.map(option => { const key = option.id if(!Object(valueToImport).hasOwnProperty(key)) { return false } const value = currentValue[key] const nextValue = valueToImport[key] if( value === nextValue || JSON.stringify(value) === JSON.stringify(nextValue) || imported.includes(key) ) { return false } return option }).filter(v => v !== false) }) return (

{slug}

{schema.map(category => { const options = category.options.map(option => { const key = option.id if(!Object(valueToImport).hasOwnProperty(key)) { return false } const value = currentValue[key] const nextValue = valueToImport[key] if( value === nextValue || JSON.stringify(value) === JSON.stringify(nextValue) || imported.includes(key) ) { return false } return option }).filter(v => v !== false) if(!options.length) { return null } return (

{category.label || category.id}

{isTailwind &&
} {!isTailwind && <>

{currentValueLabel}

{importedValueLabel}

}
{(options as Option[]).map(option => { const key = option.id const value = currentValue[key] const nextValue = valueToImport[key] return (
{option.label || option.id}
{isTailwind && <>
} {!isTailwind && <>
												
											}
											
												{!isTailwind && <>
													
												}