"use strict";

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

var _darwAvatar = _interopRequireDefault(require("../common-painter/darwAvatar"));

var _images = require("./images");

var _setSize = _interopRequireDefault(require("../common-painter/setSize"));

var _utils = require("../common-painter/utils");

var _drawUserName = _interopRequireDefault(require("./drawUserName"));

var _drawDepartmentName = _interopRequireDefault(require("./drawDepartmentName"));

var _drawQuote = _interopRequireDefault(require("./drawQuote"));

var _drawOKrName = _interopRequireDefault(require("./drawOKrName"));

var _drawKrs = _interopRequireDefault(require("./drawKrs"));

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

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var pinkCardwidth = 375;
exports.pinkCardwidth = pinkCardwidth;
var pinkCardMinHeight = 668;
var pinkCardMaxHeight = pinkCardMinHeight * 3;

function drawPinkCard(_x, _x2) {
  return _drawPinkCard.apply(this, arguments);
}

function _drawPinkCard() {
  _drawPinkCard = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(shareData, avatar) {
    var canvas, ctx, y, height, data, dataUrl;
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            if (window.WWOpenData && window.WWOpenData.initCanvas) {
              window.WWOpenData.initCanvas();
            }

            canvas = document.createElement('canvas');
            ctx = canvas.getContext('2d');
            (0, _setSize["default"])(canvas, ctx, pinkCardwidth, pinkCardMaxHeight);
            ctx.beginPath();
            ctx.rect(0, 0, pinkCardwidth, pinkCardMaxHeight);
            ctx.fillStyle = '#FFF3ED';
            ctx.fill();
            ctx.closePath();
            y = 54;
            _context.next = 12;
            return (0, _utils.drawImage)(ctx, _images.lines, 175, 20, 180, 215);

          case 12:
            _context.next = 14;
            return (0, _darwAvatar["default"])(ctx, {
              width: 50,
              height: 50,
              x: (pinkCardwidth - 50) / 2,
              y: y,
              url: avatar,
              name: shareData.user.name,
              id: shareData.user.userId,
              color: shareData.user.avatar.color
            });

          case 14:
            y = _context.sent;
            _context.next = 17;
            return (0, _drawUserName["default"])(ctx, y, shareData.user.name, shareData.user.userId);

          case 17:
            y = _context.sent;
            _context.next = 20;
            return (0, _drawDepartmentName["default"])(ctx, y, shareData.user.departmentName, shareData.user.departmentId);

          case 20:
            y = _context.sent;
            _context.next = 23;
            return (0, _drawQuote["default"])(ctx, y, 'left');

          case 23:
            y = _context.sent;
            _context.next = 26;
            return (0, _drawOKrName["default"])(ctx, shareData.okrName, y);

          case 26:
            y = _context.sent;
            _context.next = 29;
            return (0, _drawQuote["default"])(ctx, y, 'right');

          case 29:
            y = _context.sent;
            _context.next = 32;
            return (0, _drawKrs["default"])(ctx, shareData.krs, y);

          case 32:
            y = _context.sent;
            height = Math.min(Math.max(y + 143, pinkCardMinHeight), pinkCardMaxHeight);
            data = ctx.getImageData(0, 0, pinkCardwidth, height);
            (0, _setSize["default"])(canvas, ctx, pinkCardwidth, height);
            ctx.putImageData(data, 0, 0);
            _context.next = 39;
            return (0, _utils.drawImage)(ctx, _images.bottom, 0, height - 128, pinkCardwidth, 128);

          case 39:
            dataUrl = canvas.toDataURL();
            return _context.abrupt("return", dataUrl);

          case 41:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _drawPinkCard.apply(this, arguments);
}