import { __ } from '@wordpress/i18n';
import { RichText } from '@wordpress/block-editor';

const URL_TAGS = ['post_permalink', 'comments_url'];

export function HeadingContent({ isDynamic, content, selectedTag, dynamicContent, setAttributes }) {
  if (!isDynamic) {
    return (
      <RichText
        tagName="span"
        value={content}
        onChange={(value) => setAttributes({ content: value })}
        placeholder={__('Enter heading…', 'axcelersblocks')}
        className="axcelersblocks-heading__content"
        allowedFormats={['core/bold', 'core/italic']}
      />
    );
  }

  // URL tags output a raw URL — show a descriptive chip instead
  if (URL_TAGS.includes(selectedTag)) {
    const label = selectedTag === 'post_permalink'
      ? __('Post Link', 'axcelersblocks')
      : __('Comments URL', 'axcelersblocks');
    return <span className="axcelersblocks-dynamic-chip axcelersblocks-dynamic-chip--link">{label}</span>;
  }

  if (dynamicContent) {
    return <span className="axcelersblocks-dynamic-preview">{dynamicContent}</span>;
  }

  return <span className="axcelersblocks-dynamic-chip">{selectedTag || 'dynamic'}</span>;
}
