"use strict";

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

var _noop2 = _interopRequireDefault(require("lodash/noop"));

var _reactPixiFiber = require("react-pixi-fiber");

var PIXI = _interopRequireWildcard(require("pixi.js"));

var _drawDashed = require("../utils/draw-dashed");

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

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

var TYPE = 'Rect';
var behavior = {
  customDisplayObject: function customDisplayObject(props) {
    return new PIXI.Graphics();
  },
  customApplyProps: function customApplyProps(instance, oldProps, newProps) {
    var _newProps$fill = newProps.fill,
        fill = _newProps$fill === void 0 ? 0x000000 : _newProps$fill,
        _newProps$fillAlpha = newProps.fillAlpha,
        fillAlpha = _newProps$fillAlpha === void 0 ? 0 : _newProps$fillAlpha,
        _newProps$x = newProps.x,
        x = _newProps$x === void 0 ? 0 : _newProps$x,
        _newProps$y = newProps.y,
        y = _newProps$y === void 0 ? 0 : _newProps$y,
        _newProps$lineWidth = newProps.lineWidth,
        lineWidth = _newProps$lineWidth === void 0 ? 0 : _newProps$lineWidth,
        _newProps$lineColor = newProps.lineColor,
        lineColor = _newProps$lineColor === void 0 ? 0x000000 : _newProps$lineColor,
        _newProps$lineAlpha = newProps.lineAlpha,
        lineAlpha = _newProps$lineAlpha === void 0 ? 1 : _newProps$lineAlpha,
        _newProps$width = newProps.width,
        width = _newProps$width === void 0 ? 0 : _newProps$width,
        _newProps$height = newProps.height,
        height = _newProps$height === void 0 ? 0 : _newProps$height,
        _newProps$dottedWidth = newProps.dottedWidth,
        dottedWidth = _newProps$dottedWidth === void 0 ? 0 : _newProps$dottedWidth,
        _newProps$gap = newProps.gap,
        gap = _newProps$gap === void 0 ? 3 : _newProps$gap,
        cursor = newProps.cursor,
        _newProps$radius = newProps.radius,
        radius = _newProps$radius === void 0 ? 0 : _newProps$radius,
        _newProps$buttonMode = newProps.buttonMode,
        buttonMode = _newProps$buttonMode === void 0 ? true : _newProps$buttonMode,
        _newProps$interactive = newProps.interactive,
        interactive = _newProps$interactive === void 0 ? true : _newProps$interactive,
        _newProps$visible = newProps.visible,
        visible = _newProps$visible === void 0 ? true : _newProps$visible,
        _newProps$hitArea = newProps.hitArea,
        hitArea = _newProps$hitArea === void 0 ? null : _newProps$hitArea,
        _newProps$pointerdown = newProps.pointerdown,
        pointerdown = _newProps$pointerdown === void 0 ? _noop2.default : _newProps$pointerdown,
        _newProps$pointermove = newProps.pointermove,
        pointermove = _newProps$pointermove === void 0 ? _noop2.default : _newProps$pointermove,
        _newProps$pointerup = newProps.pointerup,
        pointerup = _newProps$pointerup === void 0 ? _noop2.default : _newProps$pointerup,
        _newProps$pointerupou = newProps.pointerupoutside,
        pointerupoutside = _newProps$pointerupou === void 0 ? _noop2.default : _newProps$pointerupou,
        _newProps$rotation = newProps.rotation,
        rotation = _newProps$rotation === void 0 ? 0 : _newProps$rotation,
        filters = newProps.filters;
    var _newProps$lineAlignme = newProps.lineAlignment,
        lineAlignment = _newProps$lineAlignme === void 0 ? 0 : _newProps$lineAlignme;
    instance.clear(); // drawRoundedRect 当 width / height 为 0 时也会绘制

    if (!width && !height) {
      return;
    } // NOTE: 出现过圆角矩形 lineAlignment 内外描边是反的情况
    // if (radius) {
    //     lineAlignment = lineAlignment ? 0 : 1;
    // }


    instance.lineStyle(lineWidth, lineColor, lineAlpha, lineAlignment); // draw dash rect width path:Array<Point>

    if (dottedWidth) {
      var polygon = [{
        x: x,
        y: y
      }, {
        y: y,
        x: x + width
      }, {
        x: x + width,
        y: y + height
      }, {
        x: x,
        y: y + height
      }];
      (0, _drawDashed.drawDashedPolygon)(instance, polygon, 0, 0, 0, dottedWidth, gap, 0);
    } else {
      instance.beginFill(fill, fillAlpha);

      if (radius) {
        instance.drawRoundedRect(x, y, width, height, radius);
      } else {
        instance.drawRect(x, y, width, height);
      }

      instance.endFill();
    }

    Object.assign(instance, {
      buttonMode: buttonMode,
      cursor: cursor,
      interactive: interactive,
      visible: visible,
      hitArea: hitArea,
      pointerdown: pointerdown,
      pointermove: pointermove,
      pointerup: pointerup,
      pointerupoutside: pointerupoutside,
      rotation: rotation,
      filters: filters
    });
  }
};
exports.behavior = behavior;

var _default = (0, _reactPixiFiber.CustomPIXIComponent)(behavior, TYPE);

exports.default = _default;