"use strict";

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

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

var _classnames = _interopRequireDefault(require("classnames"));

var _indexModule = _interopRequireDefault(require("./index.module.less"));

var _coreUtil = require("../../../utils/coreUtil");

var _decorator = require("../../../decorator");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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; }

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

var __extends = void 0 && (void 0).__extends || function () {
  var _extendStatics = function extendStatics(d, b) {
    _extendStatics = Object.setPrototypeOf || {
      __proto__: []
    } instanceof Array && function (d, b) {
      d.__proto__ = b;
    } || function (d, b) {
      for (var p in b) {
        if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
      }
    };

    return _extendStatics(d, b);
  };

  return function (d, b) {
    if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");

    _extendStatics(d, b);

    function __() {
      this.constructor = d;
    }

    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  };
}();

var __assign = void 0 && (void 0).__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};

var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
  var c = arguments.length,
      r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
      d;
  if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
    if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  }
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};

var Button =
/** @class */
function (_super) {
  __extends(Button, _super);

  function Button() {
    var _this = _super !== null && _super.apply(this, arguments) || this;

    _this.state = {
      hover: false
    };
    return _this;
  }

  Button.prototype.render = function () {
    var _this = this;

    var _a;

    var _b = this.props,
        data = _b.data,
        className = _b.className,
        readonly = _b.readonly;
    var hover = this.state.hover;

    var style = __assign({
      backgroundColor: data.content.backgroundColor,
      border: data.buttonBorder.open && data.buttonBorder.borderColor ? "1px solid ".concat(data.buttonBorder.borderColor) : '1px solid transparent',
      borderRadius: data.buttonBorder.open ? data.buttonBorder.borderRadius : 0
    }, data.buttonText);

    var iconUrl = data.buttonIcon.iconUrl;
    var iconLayout = data.buttonIcon.layout;

    if (hover && ((_a = data.hover) === null || _a === void 0 ? void 0 : _a.open)) {
      style = __assign(__assign(__assign({}, style), {
        backgroundColor: data.hover.content.backgroundColor,
        border: data.hover.buttonBorder.open && data.hover.buttonBorder.borderColor ? "1px solid ".concat(data.hover.buttonBorder.borderColor) : '1px solid transparent',
        borderRadius: data.hover.buttonBorder.open ? data.hover.buttonBorder.borderRadius : 0
      }), data.hover.buttonText);
      iconUrl = data.hover.buttonIcon.iconUrl;
      iconLayout = data.hover.buttonIcon.layout;
    }

    var btnText = /*#__PURE__*/_react["default"].createElement("span", {
      className: "item",
      contentEditable: (0, _coreUtil.isDesignMode)() && !readonly,
      onInput: function onInput(e) {
        var text = e.target.textContent;
        data.text = text;
      },
      suppressContentEditableWarning: true
    }, data.text);

    return /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])(_indexModule["default"].container, className),
      onMouseEnter: function onMouseEnter() {
        return _this.setState({
          hover: true
        });
      },
      onMouseLeave: function onMouseLeave() {
        return _this.setState({
          hover: false
        });
      },
      style: style
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])('btnContent', {
        horizontal: iconLayout === 'left' || iconLayout === 'right'
      })
    }, (iconLayout === 'right' || iconLayout === 'bottom') && btnText, iconUrl && /*#__PURE__*/_react["default"].createElement("img", {
      alt: "",
      className: "item",
      src: iconUrl
    }), (iconLayout === 'left' || iconLayout === 'top') && btnText));
  };

  Button.defaultProps = {
    data: {},
    className: '',
    readonly: false
  };
  Button = __decorate([_decorator.metaDecorator], Button);
  return Button;
}(_react.Component);

var _default = Button;
exports["default"] = _default;