import React, { useState } from 'react' import { CheckboxControl, ExternalLink, Modal } from '@wordpress/components' import { __ } from '@wordpress/i18n' import { useSnippetForm } from '../../../hooks/useSnippetForm' import { Button } from '../../common/Button' import { CopyToClipboardButton } from '../../common/CopyToClipboardButton' import type { Dispatch, SetStateAction } from 'react' type ShortcodeAtts = Record const buildShortcodeTag = (tag: string, atts: ShortcodeAtts): string => `[${[ tag, ...Object.entries(atts) .filter(([, value]) => Boolean(value)) .map(([att, value]) => 'boolean' === typeof value ? att : `${att}=${JSON.stringify(value)}`) ].filter(Boolean).join(' ')}]` const SHORTCODE_TAG = 'code_snippet' interface ShortcodeOptions { php: boolean format: boolean shortcodes: boolean } interface CheckboxListProps { options: T[] checked: Record disabled: boolean setChecked: Dispatch>> optionLabels: Partial> optionDescriptions: Partial> } const CheckboxList = ({ options, checked, disabled, setChecked, optionLabels, optionDescriptions }: CheckboxListProps) =>
    {options.map(option =>
  • setChecked(previous => ({ ...previous, [option]: value }))} />
  • )}
const ShortcodeDescription = () =>

{__('Copy the below shortcode to insert this snippet into a post, page, or other content.', 'code-snippets')}{'\n'} {__('You can also use the Classic Editor button, Block editor (Pro) or Elementor widget (Pro).', 'code-snippets')}{'\n'} {__('Learn more', 'code-snippets')}

const OPTION_LABELS: Record = { php: __('Evaluate PHP code', 'code-snippets'), format: __('Add paragraphs and formatting', 'code-snippets'), shortcodes: __('Evaluate additional shortcode tags', 'code-snippets') } const OPTION_DESCRIPTIONS: Record = { php: __('Run code within tags.', 'code-snippets'), format: __('Wrap output in paragraphs and apply formatting.', 'code-snippets'), shortcodes: __('Replace [shortcodes] embedded within the snippet.', 'code-snippets') } const ModalContent = () => { const { snippet, isReadOnly } = useSnippetForm() const [options, setOptions] = useState(() => ({ php: snippet.code.includes('

{shortcodeTag}

{__('Shortcode Options', 'code-snippets')}

) } export const ShortcodeInfo: React.FC = () => { const { snippet, isReadOnly } = useSnippetForm() const [isModalOpen, setIsModalOpen] = useState(false) return 'content' === snippet.scope && snippet.id ?

{__('Shortcode', 'code-snippets')}

{isModalOpen ? setIsModalOpen(false)} >
: null}
: null }