import { __ } from '@wordpress/i18n';
import { useMemo } from '@wordpress/element';
import { PanelBody } from '@wordpress/components';
import BodycopyTag from '../../../components/settings/BodycopyTag';
import DynamicContentSettings from '../../../components/settings/DynamicContentSettings';
import CustomLinkControl from '../../../components/settings/CustomLinkControl';

const ALLOWED_DYNAMIC_TAGS = [
  'post_excerpt', 'post_date', 'post_author', 'comments_count', 'comments_url',
  'post_title', 'post_permalink', 'post_meta', 'term_list',
  'term_name', 'term_description', 'term_meta', 'acf_field',
];

export function SettingsPanel({ attributes, setAttributes }) {
  const allowedTags = useMemo(() => ALLOWED_DYNAMIC_TAGS, []);

  return (
    <PanelBody title="BodyCopy" initialOpen>
      <div className="axcelersblocks-settings-section">
        <h3 className="axcelersblocks-settings-title">{__('Tag', 'axcelersblocks')}</h3>
        <BodycopyTag value={attributes.tagName} onChange={(value) => setAttributes({ tagName: value })} />
        <CustomLinkControl attributes={attributes} setAttributes={setAttributes} enableSeoAttributes />
      </div>
      <hr className="axcelersblocks-divider" />
      <div className="axcelersblocks-settings-section">
        <h3 className="axcelersblocks-settings-title">{__('Dynamic Data', 'axcelersblocks')}</h3>
        <DynamicContentSettings
          attributes={attributes}
          setAttributes={setAttributes}
          allowedTags={allowedTags}
        />
      </div>
    </PanelBody>
  );
}
