"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _config = _interopRequireDefault(require("./config"));
var _Canvas2 = _interopRequireDefault(require("./Canvas"));
var _getIconConfig = require("../_util/getIconConfig");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /* eslint-disable */
var _default = exports["default"] = /*#__PURE__*/function (_Canvas) {
  _inherits(_default, _Canvas);
  var _super = _createSuper(_default);
  function _default(options) {
    var _this;
    _classCallCheck(this, _default);
    _this = _super.call(this);
    _this.options = options || {};
    _this.options.color = (0, _getIconConfig.getColor)(_this.options);
    _this.settings = {
      height: 51,
      // 高度
      width: 44,
      // 宽度
      shadow: 5 // 阴影大小
    };

    _this.width = _this.settings.width + _this.settings.shadow * 2;
    _this.height = _this.settings.height + _this.settings.shadow * 2;

    // 初始化框高
    _this.setWidth(_this.width);
    _this.setHeight(_this.height);

    // 创建图标
    _this.createIcon();
    return _this;
  }

  // 创建图标
  _createClass(_default, [{
    key: "createIcon",
    value: function createIcon() {
      // 绘制外侧
      this.drawIconOuterWrap();

      // 绘制图标内侧
      this.drawIconInnerWrap();
      var _this$options = this.options,
        canvasIcon = _this$options.canvasIcon,
        text = _this$options.text,
        status = _this$options.status;

      // 绘制图标
      if (canvasIcon) {
        this.drawCanvasIcon();
      }

      // 绘制文本
      if (text) {
        this.drawCanvasText();
      }
      if (status) {
        this.drawStatusIcon(status, {
          width: 40,
          height: 40
        });
      }
    }

    // 绘制文本
  }, {
    key: "drawCanvasText",
    value: function drawCanvasText() {
      var _this$options2 = this.options,
        text = _this$options2.text,
        _this$options2$fontSi = _this$options2.fontSize,
        fontSize = _this$options2$fontSi === void 0 ? 14 : _this$options2$fontSi;
      var ctx = this.ctx;
      var _ctx$measureText = ctx.measureText(text),
        width = _ctx$measureText.width,
        actualBoundingBoxAscent = _ctx$measureText.actualBoundingBoxAscent,
        actualBoundingBoxDescent = _ctx$measureText.actualBoundingBoxDescent;
      var actualHeight = actualBoundingBoxAscent + actualBoundingBoxDescent;
      var x = (this.width - width * 1.5) / 2;
      var y = (this.height + actualHeight - 6) / 2;
      ctx.font = fontSize + 'px Arial';
      ctx.fillStyle = '#FFF';
      ctx.fillText(text, x, y);
    }

    // 绘制图标外侧
  }, {
    key: "drawIconOuterWrap",
    value: function drawIconOuterWrap() {
      var shadow = this.settings.shadow;
      this.ctx.save();

      // 添加阴影效果
      this.ctx.shadowColor = '#9D9D9D';
      this.ctx.shadowBlur = shadow;
      this.ctx.shadowOffsetX = 0;
      this.ctx.shadowOffsetY = 0;
      var x = this.width / 2;
      var y = this.height - shadow;
      var w = this.settings.width;
      var h = this.settings.height;
      this.waterDrop(this.ctx, x, y, w, h);
      this.ctx.closePath();

      // 填充图形
      this.ctx.fillStyle = 'white';
      this.ctx.fill();
      this.ctx.restore();
    }

    // 绘制图标内侧侧
  }, {
    key: "drawIconInnerWrap",
    value: function drawIconInnerWrap() {
      var shadow = this.settings.shadow;
      this.ctx.save();
      var x = this.width / 2;
      var y = this.height - shadow;
      var w = this.settings.width;
      var h = this.settings.height;
      this.ctx.translate(2.5, 2.5);
      this.ctx.scale(0.9, 0.9);
      this.waterDrop(this.ctx, x, y, w, h);
      this.ctx.closePath();

      // 填充图形
      this.ctx.fillStyle = this.options.color;
      this.ctx.fill();
      this.ctx.restore();
    }

    // 水滴
  }, {
    key: "waterDrop",
    value: function waterDrop(ctx, x, y, w, h) {
      ctx.beginPath();
      var leftBottom = [x - w / 2 - 16, y - (h - w / 2) + 8];
      var leftTop = [x - w / 2, y - h];
      var rightBottom = [x + w / 2 + 16, y - (h - w / 2) + 8];
      var rightTop = [x + w / 2, y - h];

      // 左侧
      ctx.moveTo(x, y);
      ctx.bezierCurveTo.apply(ctx, leftBottom.concat(leftTop, [x, y - h]));

      // 右侧
      ctx.bezierCurveTo.apply(ctx, rightTop.concat(rightBottom, [x, y]));
    }

    // 绘制canvas图标
  }, {
    key: "drawCanvasIcon",
    value: function drawCanvasIcon() {
      var _ref = (0, _getIconConfig.getIcon)(this.options) || {},
        size = _ref.size,
        draw = _ref.draw;

      // 起始位置
      var x = this.width / 2 - size / 2;
      var y = this.width / 2 - size / 2;

      // 保存状态
      this.ctx.save();

      // 偏移中心点
      this.ctx.translate(x, y);

      // 绘制颜色
      this.ctx.fillStyle = '#FFF';

      // 绘制图标
      draw(this.ctx);

      // 恢复状态
      this.ctx.restore();
    }
  }]);
  return _default;
}(_Canvas2["default"]);
//# sourceMappingURL=CommonIcon3.js.map
