"use strict";

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

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

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

var _List = _interopRequireDefault(require("@material-ui/core/List"));

var _ListItem = _interopRequireDefault(require("@material-ui/core/ListItem"));

var _ListItemText = _interopRequireDefault(require("@material-ui/core/ListItemText"));

var _Paper = _interopRequireDefault(require("@material-ui/core/Paper"));

var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));

var _classnames = _interopRequireDefault(require("classnames"));

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 {
    paper: {
      overflow: "auto",
      height: function height(props) {
        return theme.spacing(props.height);
      },
      border: "".concat(theme.spacing(0.1), " solid ").concat(theme.palette.primary.light),
      borderRadius: theme.spacing(0.5),
      boxShadow: "none",
      "&::-webkit-scrollbar": {
        width: theme.spacing(1.5)
      },
      "&::-webkit-scrollbar-thumb": {
        background: theme.palette.grey.borders,
        border: "".concat(theme.spacing(0.5), " white solid"),
        backgroundClip: "padding-box",
        borderRadius: theme.spacing(1.5)
      }
    },
    item: {
      fontSize: theme.spacing(1.3),
      color: theme.palette.text.primary,
      fontFamily: theme.typography.fontFamily,
      padding: theme.spacing(0.4, 1.6),
      cursor: "pointer"
    },
    selectedItem: {
      backgroundColor: theme.palette.primary.light
    },
    itemTitle: {
      fontWeight: theme.typography.fontWeightSemiBold,
      marginBottom: theme.spacing(0.4)
    }
  };
});

var ListItem = function ListItem(_ref) {
  var isChecked = _ref.isChecked,
      item = _ref.item,
      onChange = _ref.onChange,
      listItemFormatter = _ref.listItemFormatter,
      classes = _ref.classes;
  return /*#__PURE__*/_react.default.createElement(_ListItem.default, {
    className: (0, _classnames.default)(classes.item, isChecked && classes.selectedItem),
    role: "listitem",
    onClick: !item.disabled ? function () {
      return onChange([item]);
    } : function () {
      return null;
    },
    disabled: item.disabled
  }, listItemFormatter ? listItemFormatter(item) : /*#__PURE__*/_react.default.createElement(_ListItemText.default, {
    key: "list-item-".concat(item.id),
    primary: /*#__PURE__*/_react.default.createElement(_Typography.default, {
      className: classes.itemTitle
    }, item.title),
    secondary: /*#__PURE__*/_react.default.createElement(_Typography.default, null, item.subtitle)
  }));
};

var compareListItem = function compareListItem(prev, next) {
  return prev.item.id === next.item.id && prev.isChecked === next.isChecked && prev.item.subtitle === next.item.subtitle && prev.item.title === next.item.title;
};

exports.compareListItem = compareListItem;

var MemoListItemMui = _react.default.memo(ListItem, compareListItem);

var ScrollableList = _react.default.forwardRef(function (props, ref) {
  var scrollEvent = function scrollEvent(evt) {
    if (!props.onScroll) return;

    if (evt.target.scrollHeight - (evt.target.scrollTop + evt.target.offsetHeight) < 50 && props.currentTotal === props.currentPage * props.pageSize) {
      props.onScroll(props.currentPage + 1);
    }
  };

  return /*#__PURE__*/_react.default.createElement(_Paper.default, {
    ref: ref,
    onScroll: scrollEvent,
    className: props.classes.paper
  }, /*#__PURE__*/_react.default.createElement(_List.default, {
    component: "div",
    role: "list"
  }, props.items.map(function (item) {
    return /*#__PURE__*/_react.default.createElement(MemoListItemMui, {
      key: item.id,
      isChecked: props.selected.includes(item.id),
      item: item,
      listItemFormatter: props.listItemFormatter,
      classes: props.classes,
      onChange: props.onChange
    });
  })));
});

exports.ScrollableList = ScrollableList;

var List = function List(_ref2) {
  var onChange = _ref2.onChange,
      items = _ref2.items,
      _ref2$selected = _ref2.selected,
      selected = _ref2$selected === void 0 ? [] : _ref2$selected,
      listItemFormatter = _ref2.listItemFormatter,
      onScroll = _ref2.onScroll,
      currentTotal = _ref2.currentTotal,
      _ref2$currentPage = _ref2.currentPage,
      currentPage = _ref2$currentPage === void 0 ? 1 : _ref2$currentPage,
      _ref2$pageSize = _ref2.pageSize,
      pageSize = _ref2$pageSize === void 0 ? 20 : _ref2$pageSize,
      _ref2$height = _ref2.height,
      height = _ref2$height === void 0 ? 48 : _ref2$height;
  var classes = useStyles({
    height: height
  });

  var refScrollableList = _react.default.useRef();

  return /*#__PURE__*/_react.default.createElement(ScrollableList, {
    ref: refScrollableList,
    onChange: onChange,
    onScroll: onScroll,
    currentPage: currentPage,
    currentTotal: currentTotal,
    pageSize: pageSize,
    classes: classes,
    items: items,
    selected: selected,
    listItemFormatter: listItemFormatter
  });
};

__signature__(List, "useStyles{classes}\nuseRef{refScrollableList}", function () {
  return [useStyles];
});

__signature__(List, "useStyles{classes}\nuseRef{refScrollableList}", function () {
  return [useStyles];
});

var _default = List;
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/List.js");
  reactHotLoader.register(ListItem, "ListItem", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/List.js");
  reactHotLoader.register(compareListItem, "compareListItem", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/List.js");
  reactHotLoader.register(MemoListItemMui, "MemoListItemMui", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/List.js");
  reactHotLoader.register(ScrollableList, "ScrollableList", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/List.js");
  reactHotLoader.register(List, "List", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/List.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/List.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/List.js");
  reactHotLoader.register(ListItem, "ListItem", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/List.js");
  reactHotLoader.register(compareListItem, "compareListItem", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/List.js");
  reactHotLoader.register(MemoListItemMui, "MemoListItemMui", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/List.js");
  reactHotLoader.register(ScrollableList, "ScrollableList", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/List.js");
  reactHotLoader.register(List, "List", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/List.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/List.js");
})();

;

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