"use strict";

exports.__esModule = true;
exports.default = exports.SelectIconButton = void 0;
var _react = _interopRequireWildcard(require("react"));
var _MenuItem = _interopRequireDefault(require("@material-ui/core/MenuItem"));
var _Select = _interopRequireDefault(require("@material-ui/core/Select"));
var _styles = require("@material-ui/core/styles");
var _SelectProps = _interopRequireWildcard(require("./SelectProps"));
var _classnames = _interopRequireDefault(require("classnames"));
var _TooltippedTypography = _interopRequireDefault(require("./../DataDisplay/TooltippedElements/TooltippedTypography"));
var _Icon = _interopRequireDefault(require("./../DataDisplay/Icon"));
var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));
var _core = require("@material-ui/core");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
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); }
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 {
    baseItem: {
      maxWidth: theme.spacing(35)
    },
    level0: {},
    level1: {
      paddingLeft: theme.spacing(theme.indent)
    },
    level2: {
      paddingLeft: theme.spacing(theme.indent * 2)
    },
    level3: {
      paddingLeft: theme.spacing(theme.indent * 3)
    },
    level4: {
      paddingLeft: theme.spacing(theme.indent * 4)
    },
    level5: {
      paddingLeft: theme.spacing(theme.indent * 5)
    },
    level6: {
      paddingLeft: theme.spacing(theme.indent * 6)
    },
    level7: {
      paddingLeft: theme.spacing(theme.indent * 7)
    },
    level8: {
      paddingLeft: theme.spacing(theme.indent * 8)
    },
    container: {
      display: "flex",
      flexDirection: "column"
    },
    selectPaper: {
      border: "1px solid ".concat(theme.palette.grey.borders),
      minWidth: "auto !important",
      width: "auto !important",
      "& ul": {
        minWidth: theme.spacing(17.5),
        maxHeight: theme.spacing(30),
        paddingTop: 0,
        paddingBottom: 0
      },
      "& li": {
        fontSize: theme.typography.fontSize,
        fontFamily: theme.typography.fontFamily,
        textTransform: "none",
        color: theme.palette.grey.dark,
        paddingTop: theme.spacing(1),
        paddingBottom: theme.spacing(1),
        borderRadius: 0,
        whiteSpace: "normal",
        "&:hover": {
          backgroundColor: theme.palette.primary.light
        },
        "&:focus, &:active": {
          borderRadius: 0,
          "&:hover": {
            backgroundColor: theme.palette.primary.light
          }
        }
      }
    },
    label: {
      fontSize: theme.typography.fontSize,
      color: theme.palette.grey.dark,
      fontFamily: theme.typography.fontFamily,
      ".Mui-disabled &": {
        color: theme.palette.grey.borders
      }
    },
    emptyLabel: {
      fontStyle: "italic"
    },
    icon: {
      right: theme.spacing(1),
      width: theme.spacing(1.2),
      padding: "".concat(theme.spacing(0.5), " 0"),
      color: theme.palette.primary.main,
      zIndex: 999
    },
    errorText: {
      marginTop: theme.spacing(0.5),
      color: theme.palette.error.main,
      fontSize: theme.typography.fieldLabelSize,
      float: "left"
    },
    displayNone: {
      display: "none"
    },
    disabled: {
      color: theme.palette.text.primary,
      backgroundColor: theme.palette.grey.light,
      border: 0
    }
  };
});
var MenuProps = {
  getContentAnchorEl: null,
  anchorOrigin: {
    vertical: "bottom",
    horizontal: "right"
  },
  transformOrigin: {
    vertical: "top",
    horizontal: "right"
  }
};
var getIconButtonMenuProps = function getIconButtonMenuProps(anchorRef) {
  return {
    getContentAnchorEl: null,
    anchorEl: anchorRef,
    anchorOrigin: {
      vertical: "bottom",
      horizontal: "right"
    },
    transformOrigin: {
      vertical: "top",
      horizontal: "right"
    }
  };
};
var SelectIcon = function SelectIcon(props) {
  return /*#__PURE__*/_react.default.createElement(_Icon.default, _extends({
    id: "dropdown-chevron-down"
  }, props));
};
var SelectIconButton = exports.SelectIconButton = function SelectIconButton(props) {
  var classes = useStyles();
  return /*#__PURE__*/_react.default.createElement(_IconButton.default, {
    className: classes.iconButton,
    variant: "outlined",
    onClick: props.clickHandler
  }, /*#__PURE__*/_react.default.createElement(_Icon.default, {
    id: "arrow-more"
  }));
};
__signature__(SelectIconButton, "useStyles{classes}", function () {
  return [useStyles];
});
__signature__(SelectIconButton, "useStyles{classes}", function () {
  return [useStyles];
});
var selectEmptyValue = "~~#~~";
var Select = function Select(_ref) {
  var _selectProps$get;
  var options = _ref.options,
    selectProps = _ref.selectProps,
    children = _ref.children;
  if ((0, _SelectProps.isSelectProps)(selectProps) === false) {
    throw new TypeError("selectProps property is not of type SelectProps");
  }
  var _useState = (0, _react.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    open = _useState2[0],
    setOpen = _useState2[1];
  var ref = (0, _react.useRef)(null);
  var classes = useStyles();
  var update = selectProps == null ? void 0 : selectProps.get(_SelectProps.default.propNames.update);
  var value = (_selectProps$get = selectProps == null ? void 0 : selectProps.get(_SelectProps.default.propNames.value)) != null ? _selectProps$get : "";
  var sortType = (selectProps == null ? void 0 : selectProps.get(_SelectProps.default.propNames.sortType)) || _SelectProps.sortTypeEnum.none;
  var showAllValue = selectProps == null ? void 0 : selectProps.get(_SelectProps.default.propNames.showAllValue);
  var showAllLabel = selectProps == null ? void 0 : selectProps.get(_SelectProps.default.propNames.showAllLabel);
  var positionOverride = (selectProps == null ? void 0 : selectProps.get(_SelectProps.default.propNames.positionOverride)) || {};
  var isIconSelect = (selectProps == null ? void 0 : selectProps.get(_SelectProps.default.propNames.iconSelect)) || false;
  var disabled = (selectProps == null ? void 0 : selectProps.get(_SelectProps.default.propNames.disabled)) || false;
  var error = selectProps == null ? void 0 : selectProps.get(_SelectProps.default.propNames.error);
  var native = selectProps == null ? void 0 : selectProps.get(_SelectProps.default.propNames.native);
  var onClose = selectProps == null ? void 0 : selectProps.get(_SelectProps.default.propNames.onClose);
  var inputProps = selectProps == null ? void 0 : selectProps.get(_SelectProps.default.propNames.inputProps);
  var hasError = !!error;
  if (sortType === _SelectProps.sortTypeEnum.numeric) {
    options.sort(function (a, b) {
      return a.sortOrder.localeCompare(b.sortOrder, undefined, {
        numeric: true,
        sensitivity: "base"
      });
    });
  } else if (sortType === _SelectProps.sortTypeEnum.default) {
    options.sort(function (a, b) {
      return a.sortOrder > b.sortOrder ? 1 : -1;
    });
  } else if (sortType === _SelectProps.sortTypeEnum.alphabetical) {
    options.sort(function (a, b) {
      if (a.value === selectEmptyValue) {
        return -1;
      }
      if (b.value === selectEmptyValue) {
        return 1;
      }
      return a.label.localeCompare(b.label);
    });
  }
  if (showAllValue && showAllLabel) {
    options.unshift({
      value: showAllValue,
      label: showAllLabel
    });
  }
  var handleChange = function handleChange(event) {
    update(event.target.value);
  };
  var defaultMenuProps = _objectSpread(_objectSpread({
    classes: {
      paper: (0, _classnames.default)(classes.selectPaper, selectProps == null ? void 0 : selectProps.getStyle(_SelectProps.default.ruleNames.paper))
    }
  }, MenuProps), positionOverride);
  var iconSelectMenuProps = _objectSpread(_objectSpread({
    classes: {
      paper: (0, _classnames.default)(classes.selectPaper, selectProps == null ? void 0 : selectProps.getStyle(_SelectProps.default.ruleNames.paper))
    }
  }, positionOverride), getIconButtonMenuProps(ref.current));
  var items = options == null ? void 0 : options.map(function (option) {
    var clss = option != null && option.level ? classes["level" + option.level] : "";
    var appliedClasses = (0, _classnames.default)(classes.baseItem, clss);
    var labelClss = (0, _classnames.default)(_defineProperty(_defineProperty({}, classes.label, true), classes.emptyLabel, option.value === "" || option.value === selectEmptyValue));
    var disabled = !!option.disabled;
    var groupHeader = !!option.isGroupHeader;
    if (groupHeader) {
      return /*#__PURE__*/_react.default.createElement(_core.ListSubheader, {
        key: option.value,
        className: appliedClasses
      }, option.label);
    } else {
      return /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
        key: option.value,
        value: option.value,
        className: appliedClasses,
        disabled: disabled
      }, /*#__PURE__*/_react.default.createElement(_TooltippedTypography.default, {
        noWrap: true,
        className: labelClss,
        children: option.label,
        titleValue: option.label
      }));
    }
  });
  var defaultSelect = /*#__PURE__*/_react.default.createElement(_Select.default, {
    value: value,
    onChange: handleChange,
    onClose: onClose,
    disableUnderline: true,
    IconComponent: SelectIcon,
    MenuProps: defaultMenuProps,
    disabled: disabled,
    error: hasError,
    native: native,
    inputProps: inputProps,
    classes: {
      icon: classes.icon,
      root: selectProps == null ? void 0 : selectProps.getStyle(_SelectProps.default.ruleNames.root),
      disabled: classes.disabled
    }
  }, native ? children : items);
  var iconSelect = /*#__PURE__*/_react.default.createElement(_Select.default, {
    open: open,
    value: value,
    ref: ref,
    onChange: handleChange,
    disableUnderline: true,
    IconComponent: SelectIconButton,
    MenuProps: iconSelectMenuProps,
    disabled: disabled,
    error: hasError,
    native: native,
    inputProps: inputProps,
    classes: {
      icon: classes.icon,
      root: selectProps == null ? void 0 : selectProps.getStyle(_SelectProps.default.ruleNames.root),
      select: classes.displayNone,
      disabled: classes.disabled
    },
    onClick: function onClick() {
      return setOpen(!open);
    }
  }, native ? children : items);
  var select = isIconSelect ? iconSelect : defaultSelect;
  return error && /*#__PURE__*/_react.default.createElement("div", {
    className: classes.container
  }, select, /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(classes.errorText)
  }, error)) || select;
};
__signature__(Select, "useState{[open, setOpen](false)}\nuseRef{ref}\nuseStyles{classes}", function () {
  return [useStyles];
});
__signature__(Select, "useState{[open, setOpen](false)}\nuseRef{ref}\nuseStyles{classes}", function () {
  return [useStyles];
});
var _default = Select;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(MenuProps, "MenuProps", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(getIconButtonMenuProps, "getIconButtonMenuProps", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(SelectIcon, "SelectIcon", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(SelectIconButton, "SelectIconButton", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(selectEmptyValue, "selectEmptyValue", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(Select, "Select", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.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/Inputs/Select.js");
  reactHotLoader.register(MenuProps, "MenuProps", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(getIconButtonMenuProps, "getIconButtonMenuProps", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(SelectIcon, "SelectIcon", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(SelectIconButton, "SelectIconButton", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(selectEmptyValue, "selectEmptyValue", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(Select, "Select", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();