/**
* Meta Options build.
*/
import { useState } from 'react';
import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/edit-post';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import AstCheckboxControl from './ast-checkbox.js';
import AstRadioImageControl from './ast-radio-image.js';
import AstSelectorControl from './ast-selector.js';
import svgIcons from '../../../../assets/svg/svgs.json';
import { SelectControl, PanelBody, Modal } from '@wordpress/components';
import parse from 'html-react-parser';
const { __ } = wp.i18n;
const MetaSettings = props => {
const modalIcon = parse( svgIcons['meta-popup-icon'] );
const brandIcon = astMetaParams.isWhiteLabelled ? '' : parse( svgIcons['astra-brand-icon'] );
const [ isOpen, setOpen ] = useState( false );
const openModal = () => setOpen( true );
const closeModal = () => setOpen( false );
// Adjust spacing & borders for table.
const topTableSpacing =
| |
;
const bottomTableSpacing = | |
;
const icon = parse( svgIcons['astra-meta-settings'] );
const sidebarOptions = Object.entries( astMetaParams.sidebar_options ).map( ( [ key, name ] ) => {
return ( { label: name, value: key } );
} );
const contentLayoutOptions = Object.entries( astMetaParams.content_layout ).map( ( [ key, name ] ) => {
return ( { label: name, value: key } );
} );
// Taransparent and Sticky Header Options.
const headerOptions = Object.entries( astMetaParams.header_options ).map( ( [ key, name ] ) => {
return ( { label: name, value: key } );
} );
// Page header optins.
const pageHeaderOptions = Object.entries( astMetaParams.page_header_options ).map( ( [ key, name ] ) => {
return ( { label: name, value: key } );
} );
// Checkbox control
const disableSections = Object.entries( astMetaParams.disable_sections ).map( ( [ key, value ] ) => {
let sectionValue = ( 'disabled' === props.meta[value['key']] ) ? true : false;
return (
{
props.setMetaFieldValue( val, value['key'] );
} }
/>);
});
const headers_meta_options = Object.entries( astMetaParams.headers_meta_options ).map( ( [ key, value ] ) => {
let sectionValue = ( 'disabled' === props.meta[value['key']] ) ? true : false;
return (
{
props.setMetaFieldValue( val, value['key'] );
} }
/>);
});
// Checkbox control
const stickyHeadderOptions = Object.entries( astMetaParams.sticky_header_options ).map( ( [ key, value ] ) => {
let stickyValue = ( 'disabled' === props.meta[value['key']] ) ? true : false;
return (
{
props.setMetaFieldValue( val, value['key'] );
} }
/>);
});
return (
<>
{/* Meta settings icon */}
{ astMetaParams.title }
{/* Meta seetings popup area */}
>
);
}
export default compose(
withSelect( ( select ) => {
const postMeta = select( 'core/editor' ).getEditedPostAttribute( 'meta' );
const oldPostMeta = select( 'core/editor' ).getCurrentPostAttribute( 'meta' );
return {
meta: { ...oldPostMeta, ...postMeta },
oldMeta: oldPostMeta,
};
} ),
withDispatch( ( dispatch ) => ( {
setMetaFieldValue: ( value, field ) => dispatch( 'core/editor' ).editPost(
{ meta: { [ field ]: value } }
),
} ) ),
)( MetaSettings );