"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = TextEditorToolbar;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _faBold = require("@fortawesome/free-solid-svg-icons/faBold");
var _faItalic = require("@fortawesome/free-solid-svg-icons/faItalic");
var _faUnderline = require("@fortawesome/free-solid-svg-icons/faUnderline");
var _faSuperscript = require("@fortawesome/free-solid-svg-icons/faSuperscript");
var _faListUl = require("@fortawesome/free-solid-svg-icons/faListUl");
var _faListOl = require("@fortawesome/free-solid-svg-icons/faListOl");
var _faCode = require("@fortawesome/free-solid-svg-icons/faCode");
var _faLink = require("@fortawesome/free-solid-svg-icons/faLink");
var _faUnlink = require("@fortawesome/free-solid-svg-icons/faUnlink");
var _faTextSlash = require("@fortawesome/free-solid-svg-icons/faTextSlash");
var _button = require("../../button");
var _textEditorHooks = require("../text-editor-hooks");
var _textEditorConstants = require("../text-editor-constants");
var _markButton = _interopRequireDefault(require("./components/mark-button"));
var _blockButton = _interopRequireDefault(require("./components/block-button"));
var _textTypeDropdown = _interopRequireDefault(require("./components/text-type-dropdown"));
var _linkButton = _interopRequireDefault(require("./components/link-button"));
var _removeLinkButton = _interopRequireDefault(require("./components/remove-link-button"));
var _useTranslation = require("../../hooks/use-translation");
var _clearFormattingButton = _interopRequireDefault(require("./components/clear-formatting-button"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const IsExtraTool = tool => tool === _textEditorConstants.TEXT_EDITOR_TOOLS.BOLD_STYLE || tool === _textEditorConstants.TEXT_EDITOR_TOOLS.ITALIC_STYLE || tool === _textEditorConstants.TEXT_EDITOR_TOOLS.UNDERLINE_STYLE || tool === _textEditorConstants.TEXT_EDITOR_TOOLS.SUPERSCRIPT_STYLE;
const IsActionTool = tool => tool === _textEditorConstants.TEXT_EDITOR_TOOLS.LINKS || tool === _textEditorConstants.TEXT_EDITOR_TOOLS.CLEAR_FORMATTING;
function TextEditorToolbar({
  enabledTools = _textEditorConstants.TEXT_EDITOR_DEFAULT_TOOLS,
  labels,
  position = _textEditorConstants.TOOLBAR_POSITION.BOTTOM,
  onSave,
  onCancel
}) {
  const {
    t
  } = (0, _useTranslation.useTranslation)();
  const defaultLabels = (0, _textEditorHooks.useTextEditorDefaultTranslations)();
  const labelsWithDefault = labels ?? defaultLabels;
  if (enabledTools.length === 0) {
    return null;
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: (0, _classnames.default)('text-editor-toolbar', {
      'toolbar-top': position === _textEditorConstants.TOOLBAR_POSITION.TOP,
      'toolbar-bottom': position === _textEditorConstants.TOOLBAR_POSITION.BOTTOM
    }),
    children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "text-editor-toolbar-tools",
      children: [enabledTools.includes(_textEditorConstants.TEXT_EDITOR_TOOLS.TYPE_FACES) && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
        className: "text-editor-toolbar-tools-group",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_textTypeDropdown.default, {
          headingLargeText: labelsWithDefault.headingLargeText,
          headingMediumText: labelsWithDefault.headingMediumText,
          headingSmallText: labelsWithDefault.headingSmallText,
          regularText: labelsWithDefault.regularText
        })
      }), enabledTools.some(IsExtraTool) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
        className: "text-editor-toolbar-tools-group",
        children: [enabledTools.includes(_textEditorConstants.TEXT_EDITOR_TOOLS.BOLD_STYLE) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_markButton.default, {
          icon: _faBold.faBold,
          format: _textEditorConstants.MARK_TYPES.BOLD,
          tooltip: labelsWithDefault.tooltipTextBold,
          testId: "bold-button"
        }), enabledTools.includes(_textEditorConstants.TEXT_EDITOR_TOOLS.ITALIC_STYLE) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_markButton.default, {
          icon: _faItalic.faItalic,
          format: _textEditorConstants.MARK_TYPES.ITALIC,
          tooltip: labelsWithDefault.tooltipTextItalic,
          testId: "italic-button"
        }), enabledTools.includes(_textEditorConstants.TEXT_EDITOR_TOOLS.UNDERLINE_STYLE) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_markButton.default, {
          icon: _faUnderline.faUnderline,
          format: _textEditorConstants.MARK_TYPES.UNDERLINE,
          tooltip: labelsWithDefault.tooltipTextUnderline,
          testId: "under-line-button"
        }), enabledTools.includes(_textEditorConstants.TEXT_EDITOR_TOOLS.SUPERSCRIPT_STYLE) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_markButton.default, {
          icon: _faSuperscript.faSuperscript,
          format: _textEditorConstants.MARK_TYPES.SUPERSCRIPT,
          tooltip: labelsWithDefault.tooltipTextSuperscript,
          testId: "superscript-button"
        })]
      }), enabledTools.includes(_textEditorConstants.TEXT_EDITOR_TOOLS.LISTS) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
        className: "text-editor-toolbar-tools-group",
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_blockButton.default, {
          icon: _faListUl.faListUl,
          format: _textEditorConstants.BLOCK_TYPES.BULLETED_LIST,
          tooltip: labelsWithDefault.tooltipTextBulletedList,
          testId: "bullet-button"
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockButton.default, {
          icon: _faListOl.faListOl,
          format: _textEditorConstants.BLOCK_TYPES.NUMBERED_LIST,
          tooltip: labelsWithDefault.tooltipTextNumberedList,
          testId: "number-button"
        })]
      }), enabledTools.some(IsActionTool) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
        className: "text-editor-toolbar-tools-group",
        children: [enabledTools.includes(_textEditorConstants.TEXT_EDITOR_TOOLS.LINKS) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_linkButton.default, {
            icon: _faLink.faLink,
            tooltip: labelsWithDefault.tooltipTextLink,
            urlIsRequiredMessage: labelsWithDefault.urlIsRequiredMessage,
            enterValidUrlMessage: labelsWithDefault.enterValidUrlMessage,
            saveButtonText: labelsWithDefault.saveButtonText,
            validationErrorWarningMessage: labelsWithDefault.validationErrorWarningMessage,
            ariaLabel: labelsWithDefault.linkInputLabelText
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_removeLinkButton.default, {
            icon: _faUnlink.faUnlink,
            tooltip: labelsWithDefault.tooltipTextRemoveLink
          })]
        }), enabledTools.includes(_textEditorConstants.TEXT_EDITOR_TOOLS.CODE) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockButton.default, {
          icon: _faCode.faCode,
          format: _textEditorConstants.BLOCK_TYPES.CODE,
          tooltip: labelsWithDefault.tooltipTextCode,
          testId: "code-button"
        }), enabledTools.includes(_textEditorConstants.TEXT_EDITOR_TOOLS.CLEAR_FORMATTING) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_clearFormattingButton.default, {
          icon: _faTextSlash.faTextSlash,
          tooltip: labelsWithDefault.tooltipTextClearFormatting,
          testId: "clear-formatting-button"
        })]
      })]
    }), (onCancel || onSave) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "text-editor-toolbar-actions",
      children: [onCancel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
        onClick: onCancel,
        accentType: _button.ACCENT_TYPES.SECONDARY,
        testId: "button-text-editor-cancel",
        children: t('Cancel')
      }), onSave && /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
        onClick: onSave,
        accentType: _button.ACCENT_TYPES.PRIMARY,
        testId: "button-text-editor-save",
        children: t('Save')
      })]
    })]
  });
}