import React from 'react';
import Box from '../box';
import IconButton from '../iconButton';
import Tooltip from '../tooltip';
import { TextSmall } from '../typography';
import getOS, { OS_TYPES } from '../../utils/getOS';
var TooltippedIconButton = Tooltip(IconButton);
var OPERATING_SYSTEM = getOS();

var TooltipMessage = function TooltipMessage(_ref) {
  var optionType = _ref.optionType,
      name = _ref.name;
  var isMacOS = OPERATING_SYSTEM === OS_TYPES.MAC_OS;
  var shortcutsByOptionType = {
    bold: {
      shortcut: isMacOS ? '⌘ Cmd + B' : 'Ctrl + B'
    },
    italic: {
      shortcut: isMacOS ? '⌘ Cmd + I' : 'Ctrl + I'
    }
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TextSmall, null, name), /*#__PURE__*/React.createElement(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.createElement(Box, {
    display: "flex",
    borderRightWidth: 1,
    marginRight: 2
  }, options.map(function (optionType) {
    return /*#__PURE__*/React.createElement(TooltippedIconButton, {
      "data-wysiwyg": true,
      tooltip: /*#__PURE__*/React.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
    });
  }));
};

export default InlineStylingOptions;