import React from 'react';
import classnames from 'classnames';
import { faBold } from '@fortawesome/free-solid-svg-icons/faBold';
import { faItalic } from '@fortawesome/free-solid-svg-icons/faItalic';
import { faUnderline } from '@fortawesome/free-solid-svg-icons/faUnderline';
import { faSuperscript } from '@fortawesome/free-solid-svg-icons/faSuperscript';
import { faListUl } from '@fortawesome/free-solid-svg-icons/faListUl';
import { faListOl } from '@fortawesome/free-solid-svg-icons/faListOl';
import { faCode } from '@fortawesome/free-solid-svg-icons/faCode';
import { faLink } from '@fortawesome/free-solid-svg-icons/faLink';
import { faUnlink } from '@fortawesome/free-solid-svg-icons/faUnlink';
import { faTextSlash } from '@fortawesome/free-solid-svg-icons/faTextSlash';
import { ACCENT_TYPES, Button } from '../../button';
import { useTextEditorDefaultTranslations } from '../text-editor-hooks';
import { BLOCK_TYPES, MARK_TYPES, TEXT_EDITOR_TOOLS, TEXT_EDITOR_DEFAULT_TOOLS, TOOLBAR_POSITION } from '../text-editor-constants';
import MarkButton from './components/mark-button';
import BlockButton from './components/block-button';
import TextTypeDropdown from './components/text-type-dropdown';
import LinkButton from './components/link-button';
import RemoveLinkButton from './components/remove-link-button';
import { useTranslation } from '../../hooks/use-translation';
import ClearFormattingButton from './components/clear-formatting-button';
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
const IsExtraTool = tool => tool === TEXT_EDITOR_TOOLS.BOLD_STYLE || tool === TEXT_EDITOR_TOOLS.ITALIC_STYLE || tool === TEXT_EDITOR_TOOLS.UNDERLINE_STYLE || tool === TEXT_EDITOR_TOOLS.SUPERSCRIPT_STYLE;
const IsActionTool = tool => tool === TEXT_EDITOR_TOOLS.LINKS || tool === TEXT_EDITOR_TOOLS.CLEAR_FORMATTING;
export default function TextEditorToolbar({
  enabledTools = TEXT_EDITOR_DEFAULT_TOOLS,
  labels,
  position = TOOLBAR_POSITION.BOTTOM,
  onSave,
  onCancel
}) {
  const {
    t
  } = useTranslation();
  const defaultLabels = useTextEditorDefaultTranslations();
  const labelsWithDefault = labels ?? defaultLabels;
  if (enabledTools.length === 0) {
    return null;
  }
  return /*#__PURE__*/_jsxs("div", {
    className: classnames('text-editor-toolbar', {
      'toolbar-top': position === TOOLBAR_POSITION.TOP,
      'toolbar-bottom': position === TOOLBAR_POSITION.BOTTOM
    }),
    children: [/*#__PURE__*/_jsxs("div", {
      className: "text-editor-toolbar-tools",
      children: [enabledTools.includes(TEXT_EDITOR_TOOLS.TYPE_FACES) && /*#__PURE__*/_jsx("span", {
        className: "text-editor-toolbar-tools-group",
        children: /*#__PURE__*/_jsx(TextTypeDropdown, {
          headingLargeText: labelsWithDefault.headingLargeText,
          headingMediumText: labelsWithDefault.headingMediumText,
          headingSmallText: labelsWithDefault.headingSmallText,
          regularText: labelsWithDefault.regularText
        })
      }), enabledTools.some(IsExtraTool) && /*#__PURE__*/_jsxs("span", {
        className: "text-editor-toolbar-tools-group",
        children: [enabledTools.includes(TEXT_EDITOR_TOOLS.BOLD_STYLE) && /*#__PURE__*/_jsx(MarkButton, {
          icon: faBold,
          format: MARK_TYPES.BOLD,
          tooltip: labelsWithDefault.tooltipTextBold,
          testId: "bold-button"
        }), enabledTools.includes(TEXT_EDITOR_TOOLS.ITALIC_STYLE) && /*#__PURE__*/_jsx(MarkButton, {
          icon: faItalic,
          format: MARK_TYPES.ITALIC,
          tooltip: labelsWithDefault.tooltipTextItalic,
          testId: "italic-button"
        }), enabledTools.includes(TEXT_EDITOR_TOOLS.UNDERLINE_STYLE) && /*#__PURE__*/_jsx(MarkButton, {
          icon: faUnderline,
          format: MARK_TYPES.UNDERLINE,
          tooltip: labelsWithDefault.tooltipTextUnderline,
          testId: "under-line-button"
        }), enabledTools.includes(TEXT_EDITOR_TOOLS.SUPERSCRIPT_STYLE) && /*#__PURE__*/_jsx(MarkButton, {
          icon: faSuperscript,
          format: MARK_TYPES.SUPERSCRIPT,
          tooltip: labelsWithDefault.tooltipTextSuperscript,
          testId: "superscript-button"
        })]
      }), enabledTools.includes(TEXT_EDITOR_TOOLS.LISTS) && /*#__PURE__*/_jsxs("span", {
        className: "text-editor-toolbar-tools-group",
        children: [/*#__PURE__*/_jsx(BlockButton, {
          icon: faListUl,
          format: BLOCK_TYPES.BULLETED_LIST,
          tooltip: labelsWithDefault.tooltipTextBulletedList,
          testId: "bullet-button"
        }), /*#__PURE__*/_jsx(BlockButton, {
          icon: faListOl,
          format: BLOCK_TYPES.NUMBERED_LIST,
          tooltip: labelsWithDefault.tooltipTextNumberedList,
          testId: "number-button"
        })]
      }), enabledTools.some(IsActionTool) && /*#__PURE__*/_jsxs("span", {
        className: "text-editor-toolbar-tools-group",
        children: [enabledTools.includes(TEXT_EDITOR_TOOLS.LINKS) && /*#__PURE__*/_jsxs(_Fragment, {
          children: [/*#__PURE__*/_jsx(LinkButton, {
            icon: faLink,
            tooltip: labelsWithDefault.tooltipTextLink,
            urlIsRequiredMessage: labelsWithDefault.urlIsRequiredMessage,
            enterValidUrlMessage: labelsWithDefault.enterValidUrlMessage,
            saveButtonText: labelsWithDefault.saveButtonText,
            validationErrorWarningMessage: labelsWithDefault.validationErrorWarningMessage,
            ariaLabel: labelsWithDefault.linkInputLabelText
          }), /*#__PURE__*/_jsx(RemoveLinkButton, {
            icon: faUnlink,
            tooltip: labelsWithDefault.tooltipTextRemoveLink
          })]
        }), enabledTools.includes(TEXT_EDITOR_TOOLS.CODE) && /*#__PURE__*/_jsx(BlockButton, {
          icon: faCode,
          format: BLOCK_TYPES.CODE,
          tooltip: labelsWithDefault.tooltipTextCode,
          testId: "code-button"
        }), enabledTools.includes(TEXT_EDITOR_TOOLS.CLEAR_FORMATTING) && /*#__PURE__*/_jsx(ClearFormattingButton, {
          icon: faTextSlash,
          tooltip: labelsWithDefault.tooltipTextClearFormatting,
          testId: "clear-formatting-button"
        })]
      })]
    }), (onCancel || onSave) && /*#__PURE__*/_jsxs("div", {
      className: "text-editor-toolbar-actions",
      children: [onCancel && /*#__PURE__*/_jsx(Button, {
        onClick: onCancel,
        accentType: ACCENT_TYPES.SECONDARY,
        testId: "button-text-editor-cancel",
        children: t('Cancel')
      }), onSave && /*#__PURE__*/_jsx(Button, {
        onClick: onSave,
        accentType: ACCENT_TYPES.PRIMARY,
        testId: "button-text-editor-save",
        children: t('Save')
      })]
    })]
  });
}