"use strict";

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

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

var _core = require("@material-ui/core");

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

var _hooks = require("../../hooks");

const useStyles = (0, _core.makeStyles)(theme => {
  return (0, _core.createStyles)({
    root: {
      color: theme.palette.type === 'dark' ? theme.palette.common.white : '#556685',
      verticalAlign: 'middle'
    }
  });
});

const TypographyControl = props => {
  const localization = (0, _hooks.useLocalization)();
  const classes = useStyles();

  const getActiveValue = () => {
    if (props.editor.isActive('paragraph')) {
      return 0;
    } else if (props.editor.isActive('heading', {
      level: 1
    })) {
      return 1;
    } else if (props.editor.isActive('heading', {
      level: 2
    })) {
      return 2;
    } else if (props.editor.isActive('heading', {
      level: 3
    })) {
      return 3;
    } else if (props.editor.isActive('heading', {
      level: 4
    })) {
      return 4;
    } else if (props.editor.isActive('heading', {
      level: 5
    })) {
      return 5;
    } else if (props.editor.isActive('heading', {
      level: 6
    })) {
      return 6;
    }

    return 0;
  };

  const handleChange = event => {
    if (event.target.value !== 0) {
      props.editor.chain().focus().toggleHeading({
        level: event.target.value
      }).run();
    } else {
      props.editor.chain().focus().setParagraph().run();
    }
  };

  return /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
    title: localization.menubar.typography
  }, /*#__PURE__*/_react.default.createElement(_core.Select, {
    value: getActiveValue(),
    onChange: handleChange,
    disableUnderline: true,
    className: classes.root,
    MenuProps: {
      anchorOrigin: {
        vertical: 'bottom',
        horizontal: 'left'
      },
      transformOrigin: {
        vertical: 'top',
        horizontal: 'left'
      },
      getContentAnchorEl: null
    }
  }, /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    value: 0
  }, localization.typographyControl.paragraph), /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    value: 1
  }, localization.typographyControl.heading, " 1"), /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    value: 2
  }, localization.typographyControl.heading, " 2"), /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    value: 3
  }, localization.typographyControl.heading, " 3"), /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    value: 4
  }, localization.typographyControl.heading, " 4"), /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    value: 5
  }, localization.typographyControl.heading, " 5"), /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    value: 6
  }, localization.typographyControl.heading, " 6")));
};

exports.TypographyControl = TypographyControl;
//# sourceMappingURL=typography-control.js.map