function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React from "react";
import styled from "styled-components";
import Flex from "../../../templates/flex";
import { useTableState } from "../../provider";
var rerenderSelector = function rerenderSelector(state) {
  var _state$columnSizingIn;
  return (_state$columnSizingIn = state.columnSizingInfo) == null ? void 0 : _state$columnSizingIn.deltaPercentage;
};
export var Handler = styled(Flex).attrs({
  position: "absolute",
  top: "2px",
  right: 0,
  bottom: "2px"
}).withConfig({
  displayName: "resizeHandler__Handler",
  componentId: "sc-13d4ex1-0"
})([""]);
var ResizeHandler = function ResizeHandler(_ref) {
  var header = _ref.header,
    table = _ref.table;
  useTableState(rerenderSelector);
  if (!header.column.getCanResize()) return null;
  var resizingProps = header.column.getIsResizing() ? {
    transform: "translateX(" + table.getState().columnSizingInfo.deltaOffset + "px)"
  } : {};
  return /*#__PURE__*/React.createElement(Handler, {
    border: {
      side: "right",
      size: "1px",
      color: "borderSecondary"
    },
    _hover: {
      border: {
        side: "right",
        size: "3px",
        color: "resizerLine"
      }
    },
    _active: {
      border: {
        side: "right",
        size: "3px",
        color: "resizerLine"
      }
    },
    width: "8px",
    sx: _extends({
      userSelect: "none",
      touchAction: "none",
      cursor: "col-resize"
    }, resizingProps),
    onMouseDown: header.getResizeHandler(),
    onTouchStart: header.getResizeHandler()
  });
};
export default ResizeHandler;