import React__default from 'react';
import PropTypes from 'prop-types';
import { DragSource, DropTarget } from 'react-dnd';
import classnames from 'classnames';
import Button from '../../../Button/Button.js';
import { settings } from '../../../../constants/Settings.js';
import { Draggable } from '@carbon/icons-react';

var iotPrefix = 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.createElement(Button, {
    className: classnames('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: Draggable,
    size: "sm",
    ref: function ref(instance) {
      if (!isDisabled) {
        connectDragSource(instance);
        connectDropTarget(instance);
      }
    }
  }, children);
};
ColumnHeaderSelect.propTypes = {
  columnId: PropTypes.string.isRequired,
  isHidden: PropTypes.bool,
  children: PropTypes.oneOfType([PropTypes.array, PropTypes.node]),
  onClick: PropTypes.func.isRequired,
  connectDragSource: PropTypes.func.isRequired,
  connectDropTarget: PropTypes.func.isRequired,
  isDisabled: PropTypes.bool,
  /* these props come from react-dnd */
  index: PropTypes.number.isRequired,
  // eslint-disable-line react/no-unused-prop-types
  isOver: PropTypes.bool.isRequired,
  // eslint-disable-line react/no-unused-prop-types
  moveItem: PropTypes.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 = DragSource('ColumnHeaderSelect', cardSource, function (connect) {
  return {
    connectDragSource: connect.dragSource()
  };
});
var dt = 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));

export { ColumnHeaderSelect as UnconnectedColumnHeaderSelect, ColumnHeaderSelect$1 as default };
