"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 _color = require("../utils/color");

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 = 'Line';
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 ? 0xFFFFFF : _newProps$fill,
        _newProps$fillAlpha = newProps.fillAlpha,
        fillAlpha = _newProps$fillAlpha === void 0 ? 0 : _newProps$fillAlpha,
        _newProps$lineWidth = newProps.lineWidth,
        lineWidth = _newProps$lineWidth === void 0 ? 0 : _newProps$lineWidth,
        _newProps$lineColor = newProps.lineColor,
        lineColor = _newProps$lineColor === void 0 ? 0xFFFFFF : _newProps$lineColor,
        _newProps$lineAlpha = newProps.lineAlpha,
        lineAlpha = _newProps$lineAlpha === void 0 ? 1 : _newProps$lineAlpha,
        _newProps$lineAlignme = newProps.lineAlignment,
        lineAlignment = _newProps$lineAlignme === void 0 ? 0 : _newProps$lineAlignme,
        _newProps$points = newProps.points,
        points = _newProps$points === void 0 ? [] : _newProps$points,
        _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$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;
    instance.clear();

    if (points.length < 2) {
      return;
    }

    var _points$ = points[0],
        x0 = _points$.x,
        y0 = _points$.y;
    var _points$2 = points[1],
        x1 = _points$2.x,
        y1 = _points$2.y;
    instance.lineStyle(lineWidth, (0, _color.colorToHexNumber)(lineColor), lineAlpha, lineAlignment);
    instance.beginFill(fill, fillAlpha);

    if (dottedWidth) {
      (0, _drawDashed.drawDashLine)(instance, x0, y0, x1, y1, dottedWidth, gap);
    } else {
      instance.moveTo(x0, y0);
      instance.lineTo(x1, y1);
    }

    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
    });
  }
};
exports.behavior = behavior;

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

exports.default = _default;