import {
  RichTextField,
  RichTextFieldType,
} from '@hubspot/cms-components/fields';
import type { ContentFieldsProps } from './types.js';

const simpleTextEnabledFeatures: RichTextFieldType['enabledFeatures'] = [
  'icon',
];

const headingEnabledFeatures: RichTextFieldType['enabledFeatures'] = [
  'heading',
  'alignment',
  'standard_emphasis',
  'link',
];

const bodyContentEnabledFeatures: RichTextFieldType['enabledFeatures'] = [
  'block',
  'alignment',
  'indents',
  'lists',
  'standard_emphasis',
  'advanced_emphasis',
  'link',
];

const featureSetMap = {
  bodyContent: bodyContentEnabledFeatures,
  heading: headingEnabledFeatures,
  simpleText: simpleTextEnabledFeatures,
};

const ContentFields = ({
  textLabel = 'Text',
  textName = 'text',
  textDefault = '<p>Add text here</p>',
  textFeatureSet = 'bodyContent',
}: ContentFieldsProps) => {
  return (
    <RichTextField
      label={textLabel}
      name={textName}
      default={textDefault}
      required={true}
      enabledFeatures={featureSetMap[textFeatureSet]}
    />
  );
};

export default ContentFields;
