'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
require('core-js/modules/es.array.concat.js');
var React = require('react');
var reactDnd = require('react-dnd');
var classnames = require('classnames');
var PropTypes = require('prop-types');
var Settings = require('../../../constants/Settings.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var React__default = /*#__PURE__*/_interopDefault(React);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);

var iotPrefix = Settings.settings.iotPrefix;
var TargetSize = {
  Third: 'third',
  Half: 'half',
  Full: 'full'
};
var ListTargetPropTypes = {
  connectDropTarget: PropTypes__default.default.func.isRequired,
  isOver: PropTypes__default.default.bool,
  targetPosition: PropTypes__default.default.string.isRequired,
  targetSize: PropTypes__default.default.oneOf([TargetSize.Third, TargetSize.Half, TargetSize.Full]),
  // eslint-disable-next-line react/no-unused-prop-types
  targetOverride: PropTypes__default.default.string // eslint flags this as unused though it is used in react-dnd's drop effect
};
var ListTargetDefaultProps = {
  isOver: false,
  targetSize: TargetSize.Third,
  targetOverride: null
};
var ListTarget = function ListTarget(_ref) {
  var connectDropTarget = _ref.connectDropTarget,
    targetPosition = _ref.targetPosition,
    targetSize = _ref.targetSize,
    isOver = _ref.isOver;
  var height = 33; // defaults to TargetSize.Third

  if (targetSize === TargetSize.Full) {
    height = 100;
  } else if (targetSize === TargetSize.Half) {
    height = 50;
  }
  return /*#__PURE__*/React__default.default.createElement("div", {
    "data-testid": "list-target",
    className: classnames__default.default("".concat(iotPrefix, "--list-item-editable--drop-target-").concat(targetPosition), _defineProperty__default.default({}, "".concat(iotPrefix, "--list-item-editable--drop-target-").concat(targetPosition, "__over"), isOver)),
    style: {
      height: "".concat(height, "%")
    },
    ref: function ref(instance) {
      /* istanbul ignore else */
      if (connectDropTarget) {
        connectDropTarget(instance);
      }
    }
  });
};
var rowTarget = {
  drop: function drop(hoverProps, monitor) {
    var _hoverProps$targetOve;
    var hoverId = hoverProps.id;
    var dragId = monitor.getItem().id;
    var target = (_hoverProps$targetOve = hoverProps.targetOverride) !== null && _hoverProps$targetOve !== void 0 ? _hoverProps$targetOve : hoverProps.targetPosition;

    // Check if drop is allowed
    if (hoverProps.itemWillMove(dragId, hoverId, target)) {
      hoverProps.onItemMoved(dragId, hoverId, target);
    }
  }
};
var dt = reactDnd.DropTarget('ListItem', rowTarget, function (connect, monitor) {
  return {
    connectDropTarget: connect.dropTarget(),
    isOver: monitor.isOver({
      shallow: true
    })
  };
});
ListTarget.propTypes = ListTargetPropTypes;
ListTarget.defaultProps = ListTargetDefaultProps;
ListTarget.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "ListTarget",
  "props": {
    "isOver": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "targetSize": {
      "defaultValue": {
        "value": "'third'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'third'",
          "computed": false
        }, {
          "value": "'half'",
          "computed": false
        }, {
          "value": "'full'",
          "computed": false
        }]
      },
      "required": false
    },
    "targetOverride": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "connectDropTarget": {
      "description": "",
      "type": {
        "name": "func"
      },
      "required": true
    },
    "targetPosition": {
      "description": "",
      "type": {
        "name": "string"
      },
      "required": true
    }
  }
};
var ListTarget$1 = dt(ListTarget);

exports.TargetSize = TargetSize;
exports.default = ListTarget$1;
