"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 _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); }
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: options.hideFooter ? 57 : 66,
      // 整体高度
      width: 58,
      // 整体高度
      iconWrapSize: 44,
      clipAngle: 15,
      footerOuterCircle: {
        width: 10,
        // 宽度
        height: 4 // 高度
      }
    };

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

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

  // 创建图标
  _createClass(_default, [{
    key: "createIcon",
    value: function createIcon() {
      var _this$options = this.options,
        canvasIcon = _this$options.canvasIcon,
        text = _this$options.text,
        hideFooter = _this$options.hideFooter,
        info = _this$options.info,
        status = _this$options.status;
      if (!hideFooter) {
        // 绘制底座外侧椭圆
        this.drawFooterOuterCircle();
      }

      // 绘制信息框
      if (info) {
        this.drawInfo();
      }

      // 绘制图标外侧
      this.drawIconOuterWrap();

      // 绘制图标内侧侧
      this.drawIconInnerWrap();

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

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

    // 绘制信息框
  }, {
    key: "drawInfo",
    value: function drawInfo() {
      var _this$options2 = this.options,
        info = _this$options2.info,
        color = _this$options2.color;
      var iconWrapSize = this.settings.iconWrapSize;
      var width = this.getCanvasWidth(info) + iconWrapSize / 2 + 4;
      var blurSize = (this.settings.width - iconWrapSize) / 2;
      var x = iconWrapSize / 2 + blurSize;
      var y = iconWrapSize / 2 + blurSize;
      var radius = iconWrapSize;

      // 改变 canvas 大小
      this.resize(x + width + radius / 2);
      this.ctx.save();

      // 开始绘制路径
      this.ctx.beginPath();

      // 绘制左侧半圆
      this.ctx.arc(x, y, iconWrapSize / 2, Math.PI / 180 * 90, Math.PI / 180 * 270);
      this.ctx.moveTo(x, y - radius / 2);
      this.ctx.lineTo(x + width, y - radius / 2);

      // 绘制右侧半圆
      this.ctx.arc(x + width, y, radius / 2, Math.PI / 180 * 270, Math.PI / 180 * 90);
      this.ctx.moveTo(x + width, y + radius / 2);
      this.ctx.lineTo(x, y + radius / 2);
      this.ctx.lineTo(x, y - radius / 2);

      // 填充图形
      var grd1 = this.ctx.createLinearGradient(x - radius / 2, y - radius / 2, x + width + radius / 2, y - radius / 2);
      grd1.addColorStop(0.4, this.transformRgb(color, 1));
      grd1.addColorStop(1, this.transformRgb(color, 0.7));
      this.ctx.fillStyle = grd1;
      this.ctx.fill();

      // 绘制文本
      var textHeight = iconWrapSize + 12;
      var textX = iconWrapSize + 10;
      this.renderText(this.ctx, textHeight, info, textX, '#FFF');
    }

    // 绘制文本
  }, {
    key: "drawCanvasText",
    value: function drawCanvasText() {
      var _this$options3 = this.options,
        text = _this$options3.text,
        _this$options3$fontSi = _this$options3.fontSize,
        fontSize = _this$options3$fontSi === void 0 ? 14 : _this$options3$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.settings.width - width * 1.5) / 2;
      var y = (this.settings.width + actualHeight) / 2;
      ctx.font = fontSize + 'px Arial';
      ctx.fillStyle = '#FFF';
      ctx.fillText(text, x, y);
    }

    // 绘制图标外侧
  }, {
    key: "drawIconOuterWrap",
    value: function drawIconOuterWrap() {
      var iconWrapSize = this.settings.iconWrapSize;
      var clipAngle = this.settings.clipAngle;
      var blurSize = (this.settings.width - iconWrapSize) / 2;
      var x = iconWrapSize / 2 + blurSize;
      var y = iconWrapSize / 2 + blurSize;
      var radius = iconWrapSize;
      this.ctx.save();

      // 添加阴影效果
      this.ctx.shadowColor = '#9D9D9D';
      this.ctx.shadowBlur = blurSize;
      this.ctx.shadowOffsetX = 0;
      this.ctx.shadowOffsetY = 0;

      // 开始绘制路径
      this.ctx.beginPath();

      // 绘制圆
      this.ctx.arc(x, y, radius / 2, 0, 2 * Math.PI);
      var y1 = this.settings.height - this.settings.footerOuterCircle.height / 2 - 4;

      // 绘制三角形
      this.ctx.moveTo(x - clipAngle / 2, iconWrapSize);
      this.ctx.lineTo(x + clipAngle / 2, iconWrapSize);
      this.ctx.lineTo(x, y1);
      this.ctx.lineTo(x - clipAngle / 2, iconWrapSize);
      this.ctx.closePath();

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

    // 绘制底座外侧椭圆
  }, {
    key: "drawFooterOuterCircle",
    value: function drawFooterOuterCircle() {
      var color = this.options.color;
      var iconWrapSize = this.settings.iconWrapSize;
      var blurSize = (this.settings.width - iconWrapSize) / 2;
      var x = this.settings.iconWrapSize / 2 + blurSize;
      var y = this.settings.height - this.settings.footerOuterCircle.height / 2 - 1;
      var w = this.settings.footerOuterCircle.width;
      var h = this.settings.footerOuterCircle.height;
      this.ctx.save();
      this.ctx.beginPath();
      this.ellipse(this.ctx, x, y, w, h);
      this.ctx.save();
      this.ctx.globalAlpha = 0.75;
      this.ctx.fillStyle = color;
      this.ctx.fill();
      this.ctx.restore();
      this.ctx.strokeStyle = '#FFF';
      this.ctx.stroke();
      this.ctx.restore();
    }

    // 绘制图标内侧侧
  }, {
    key: "drawIconInnerWrap",
    value: function drawIconInnerWrap() {
      var color = this.options.color;
      var iconWrapSize = this.settings.iconWrapSize;
      var iconInnerWrapSize = iconWrapSize - 5;
      var blurSize = (this.settings.width - iconWrapSize) / 2;
      var x = iconWrapSize / 2 + blurSize;
      var y = iconWrapSize / 2 + blurSize;
      var radius = iconInnerWrapSize;
      this.ctx.save();

      // 开始绘制路径
      this.ctx.beginPath();

      // 绘制圆
      this.ctx.arc(x, y, radius / 2, 0, 2 * Math.PI);

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

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

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

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

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

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

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

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