"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(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

(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(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, 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 = 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"
  }));
};

exports.SelectIconButton = SelectIconButton;

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

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

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 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;
    });
  }

  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 _classNames;

    var clss = option != null && option.level ? classes["level" + option.level] : "";
    var appliedClasses = (0, _classnames.default)(classes.baseItem, clss);
    var labelClss = (0, _classnames.default)((_classNames = {}, _defineProperty(_classNames, classes.label, true), _defineProperty(_classNames, classes.emptyLabel, option.value === "" || option.value === "~~#~~"), _classNames));
    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,
    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 = _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/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(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(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);
})();