'use strict';

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

var React = require('react');
var PropTypes = require('prop-types');
var reactDnd = require('react-dnd');
var classnames = require('classnames');
var Button = require('../../../Button/Button.js');
var Settings = require('../../../../constants/Settings.js');
var iconsReact = require('@carbon/icons-react');

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

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

var iotPrefix = Settings.settings.iotPrefix;
var ColumnHeaderSelect = function ColumnHeaderSelect(_ref) {
  var connectDragSource = _ref.connectDragSource,
    connectDropTarget = _ref.connectDropTarget,
    columnId = _ref.columnId,
    isHidden = _ref.isHidden,
    children = _ref.children,
    _onClick = _ref.onClick,
    isOver = _ref.isOver,
    isDisabled = _ref.isDisabled;
  return /*#__PURE__*/React__default.default.createElement(Button, {
    className: classnames__default.default('column-header__btn', "".concat(iotPrefix, "--column-header"), 'column-header__select', {
      'column-header__select--hidden': isHidden,
      'column-header__select--isOver': isOver
    }),
    disabled: isDisabled,
    kind: "secondary",
    key: columnId,
    onClick: function onClick() {
      return _onClick();
    },
    role: "button",
    "data-ishidden": isHidden,
    renderIcon: iconsReact.Draggable,
    size: "sm",
    ref: function ref(instance) {
      if (!isDisabled) {
        connectDragSource(instance);
        connectDropTarget(instance);
      }
    }
  }, children);
};
ColumnHeaderSelect.propTypes = {
  columnId: PropTypes__default.default.string.isRequired,
  isHidden: PropTypes__default.default.bool,
  children: PropTypes__default.default.oneOfType([PropTypes__default.default.array, PropTypes__default.default.node]),
  onClick: PropTypes__default.default.func.isRequired,
  connectDragSource: PropTypes__default.default.func.isRequired,
  connectDropTarget: PropTypes__default.default.func.isRequired,
  isDisabled: PropTypes__default.default.bool,
  /* these props come from react-dnd */
  index: PropTypes__default.default.number.isRequired,
  // eslint-disable-line react/no-unused-prop-types
  isOver: PropTypes__default.default.bool.isRequired,
  // eslint-disable-line react/no-unused-prop-types
  moveItem: PropTypes__default.default.func.isRequired // eslint-disable-line react/no-unused-prop-types
};
ColumnHeaderSelect.defaultProps = {
  isHidden: false,
  isDisabled: false,
  children: []
};
var cardSource = {
  /**
   * Implements the drag source contract.
   */
  beginDrag: function beginDrag(props) {
    return {
      id: props.columnId,
      index: props.index
    };
  }
};
var cardTarget = {
  drop: function drop(props, monitor) {
    var dragIndex = monitor.getItem().index;
    var hoverIndex = props.index;
    // Don't replace items with themselves
    if (dragIndex === hoverIndex) {
      return;
    }
    props.moveItem(dragIndex, hoverIndex);
    monitor.getItem().index = hoverIndex; // eslint-disable-line no-param-reassign
  }
};
var ds = reactDnd.DragSource('ColumnHeaderSelect', cardSource, function (connect) {
  return {
    connectDragSource: connect.dragSource()
  };
});
var dt = reactDnd.DropTarget('ColumnHeaderSelect', cardTarget, function (connect, monitor) {
  return {
    connectDropTarget: connect.dropTarget(),
    isOver: monitor.isOver()
  };
});
ColumnHeaderSelect.displayName = 'ColumnHeaderSelect';
ColumnHeaderSelect.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "ColumnHeaderSelect",
  "props": {
    "isHidden": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "isDisabled": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "children": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "union",
        "value": [{
          "name": "array"
        }, {
          "name": "node"
        }]
      },
      "required": false
    },
    "columnId": {
      "description": "",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "onClick": {
      "description": "",
      "type": {
        "name": "func"
      },
      "required": true
    },
    "connectDragSource": {
      "description": "",
      "type": {
        "name": "func"
      },
      "required": true
    },
    "connectDropTarget": {
      "description": "",
      "type": {
        "name": "func"
      },
      "required": true
    },
    "index": {
      "description": "",
      "type": {
        "name": "number"
      },
      "required": true
    },
    "isOver": {
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": true
    },
    "moveItem": {
      "description": "",
      "type": {
        "name": "func"
      },
      "required": true
    }
  }
};
var ColumnHeaderSelect$1 = ds(dt(ColumnHeaderSelect));

exports.UnconnectedColumnHeaderSelect = ColumnHeaderSelect;
exports.default = ColumnHeaderSelect$1;
