"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _box = _interopRequireDefault(require("../box"));

var _iconButton = _interopRequireDefault(require("../iconButton"));

var _tooltip = _interopRequireDefault(require("../tooltip"));

var _typography = require("../typography");

var _getOS = _interopRequireWildcard(require("../../utils/getOS"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var TooltippedIconButton = (0, _tooltip.default)(_iconButton.default);
var OPERATING_SYSTEM = (0, _getOS.default)();

var TooltipMessage = function TooltipMessage(_ref) {
  var optionType = _ref.optionType,
      name = _ref.name;
  var isMacOS = OPERATING_SYSTEM === _getOS.OS_TYPES.MAC_OS;
  var shortcutsByOptionType = {
    bold: {
      shortcut: isMacOS ? '⌘ Cmd + B' : 'Ctrl + B'
    },
    italic: {
      shortcut: isMacOS ? '⌘ Cmd + I' : 'Ctrl + I'
    }
  };
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_typography.TextSmall, null, name), /*#__PURE__*/_react.default.createElement(_typography.TextSmall, {
    color: "neutral"
  }, shortcutsByOptionType[optionType].shortcut));
};

var InlineStylingOptions = function InlineStylingOptions(_ref2) {
  var _ref2$config = _ref2.config,
      options = _ref2$config.options,
      boldIcon = _ref2$config.bold.icon,
      italicIcon = _ref2$config.italic.icon,
      currentState = _ref2.currentState,
      onChange = _ref2.onChange,
      translations = _ref2.translations;
  var iconsByOptionType = {
    bold: boldIcon,
    italic: italicIcon
  };
  return /*#__PURE__*/_react.default.createElement(_box.default, {
    display: "flex",
    borderRightWidth: 1,
    marginRight: 2
  }, options.map(function (optionType) {
    return /*#__PURE__*/_react.default.createElement(TooltippedIconButton, {
      "data-wysiwyg": true,
      tooltip: /*#__PURE__*/_react.default.createElement(TooltipMessage, {
        optionType: optionType,
        name: translations["components.controls.inline.".concat(optionType)]
      }),
      tooltipSize: "small",
      tooltipShowDelay: 1000,
      icon: iconsByOptionType[optionType],
      color: "black",
      key: optionType,
      onClick: function onClick() {
        return onChange(optionType);
      },
      selected: currentState[optionType],
      marginRight: 2
    });
  }));
};

var _default = InlineStylingOptions;
exports.default = _default;