"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _Icon = _interopRequireDefault(require("./Icon"));

var _styles = require("@material-ui/core/styles");

var _reactIntl = require("react-intl");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var useStyles = (0, _styles.makeStyles)(function (theme) {
  return {
    headerContainer: {
      display: "flex",
      alignItems: "center",
      cursor: "pointer"
    },
    sortIcon: {
      stroke: "none",
      width: theme.spacing(0.8),
      marginLeft: theme.spacing(1)
    }
  };
});

var TableHeaderCell = function TableHeaderCell(_ref) {
  var columnDefinition = _ref.columnDefinition;
  var classes = useStyles();
  var label = typeof columnDefinition.label === "object" ? /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, columnDefinition.label) : columnDefinition.label;

  if (columnDefinition.sortOptions == null) {
    return label;
  }

  var direction = columnDefinition.sortOptions.direction;
  var propertyName = columnDefinition.sortOptions.propertyName;
  var sortCallback = columnDefinition.sortCallback;
  var sortField = columnDefinition.sortOptions.sortField;

  if (direction !== "Descending" && direction !== "Ascending") {
    throw new Error("Direction could only have one of next 2 values: Ascending/Descending");
  }

  if (propertyName == null) {
    throw new Error("Property name is required for sorting correct work");
  }

  if (sortCallback == null) {
    throw new Error("Sort callback is required for sorting correct work");
  }

  var iconId = direction === "Descending" ? "caret-down" : "caret-up";
  var iconColor = sortField ? "primary" : "disabled";

  var icon = /*#__PURE__*/_react.default.createElement(_Icon.default, {
    id: iconId,
    className: classes.sortIcon,
    color: iconColor
  });

  var clickHandler = function clickHandler() {
    columnDefinition.sortCallback(columnDefinition.sortOptions.propertyName);
  };

  var sortableColumnHeader = /*#__PURE__*/_react.default.createElement("div", {
    className: classes.headerContainer,
    onClick: function onClick() {
      return clickHandler();
    }
  }, label, icon);

  return sortableColumnHeader;
};

__signature__(TableHeaderCell, "useStyles{classes}", function () {
  return [useStyles];
});

__signature__(TableHeaderCell, "useStyles{classes}", function () {
  return [useStyles];
});

var _default = TableHeaderCell;
var _default2 = _default;
var _default3 = _default2;
exports.default = _default3;
;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/TableHeaderCell.js");
  reactHotLoader.register(TableHeaderCell, "TableHeaderCell", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/TableHeaderCell.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/TableHeaderCell.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();

;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/TableHeaderCell.js");
  reactHotLoader.register(TableHeaderCell, "TableHeaderCell", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/TableHeaderCell.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/TableHeaderCell.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();