"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Autocomplete = _interopRequireDefault(require("@material-ui/lab/Autocomplete"));
var _TextField = _interopRequireDefault(require("@material-ui/core/TextField"));
var _styles = require("@material-ui/core/styles");
var _Icon = _interopRequireDefault(require("../DataDisplay/Icon"));
var _AutocompleteProps = _interopRequireWildcard(require("./AutocompleteProps"));
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 _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); }
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); }
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 {
    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
          }
        }
      }
    },
    icon: {
      width: theme.spacing(1.2),
      color: theme.palette.primary.main
    },
    closeIcon: {
      color: theme.palette.primary.main
    },
    errorText: {
      marginTop: theme.spacing(0.5),
      color: theme.palette.error.main,
      fontSize: theme.typography.fieldLabelSize,
      float: "left"
    },
    disabled: {
      color: theme.palette.text.primary,
      backgroundColor: theme.palette.grey.light,
      border: 0
    },
    inputRoot: {
      paddingRight: theme.spacing(5.2),
      height: "auto",
      boxSizing: "border-box"
    },
    input: {
      border: 0,
      padding: 0,
      boxShadow: "none !important",
      height: "auto"
    },
    popupIndicator: {
      right: theme.spacing(1),
      boxShadow: "none !important",
      backgroundColor: "unset !important"
    },
    clearIndicator: {
      boxShadow: "none !important",
      backgroundColor: "unset !important"
    }
  };
});
var Autocomplete = function Autocomplete(_ref) {
  var _autocompleteProps$ge;
  var id = _ref.id,
    options = _ref.options,
    autocompleteProps = _ref.autocompleteProps;
  if ((0, _AutocompleteProps.isAutocompleteProps)(autocompleteProps) === false) {
    throw new TypeError("autocompleteProps property is not of type AutocompleteProps");
  }
  var classes = useStyles();
  var update = autocompleteProps == null ? void 0 : autocompleteProps.get(_AutocompleteProps.default.propNames.update);
  var value = (_autocompleteProps$ge = autocompleteProps == null ? void 0 : autocompleteProps.get(_AutocompleteProps.default.propNames.value)) != null ? _autocompleteProps$ge : "";
  var disabled = (autocompleteProps == null ? void 0 : autocompleteProps.get(_AutocompleteProps.default.propNames.disabled)) || false;
  var error = autocompleteProps == null ? void 0 : autocompleteProps.get(_AutocompleteProps.default.propNames.error);
  var placeholder = autocompleteProps == null ? void 0 : autocompleteProps.get(_AutocompleteProps.default.propNames.placeholder);
  var onChangeOption = (0, _react.useCallback)(function (event, option) {
    var _option$value;
    return update((_option$value = option == null ? void 0 : option.value) != null ? _option$value : null);
  }, [update]);
  var RenderInput = function RenderInput(params) {
    return /*#__PURE__*/_react.default.createElement(_TextField.default, _extends({}, params, {
      fullWidth: true,
      placeholder: placeholder,
      InputProps: _objectSpread(_objectSpread({}, params.InputProps), {}, {
        disableUnderline: true,
        className: (0, _classnames.default)("MuiInputBase-input", classes.inputRoot),
        classes: _objectSpread(_objectSpread({}, params.InputProps.classes), {}, {
          disabled: classes.disabled
        })
      })
    }));
  };
  var selected = (0, _react.useMemo)(function () {
    var _options$find;
    return (_options$find = options.find(function (o) {
      return o.value === value;
    })) != null ? _options$find : null;
  }, [options, value]);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: classes.container
  }, /*#__PURE__*/_react.default.createElement(_Autocomplete.default, {
    id: id,
    disabled: disabled,
    value: selected,
    options: options,
    getOptionLabel: function getOptionLabel(option) {
      return option.label;
    },
    onChange: onChangeOption,
    openText: null,
    closeText: null,
    clearText: null,
    noOptionsText: null,
    loadingText: null,
    classes: {
      paper: classes.selectPaper,
      popupIndicator: classes.popupIndicator,
      clearIndicator: classes.clearIndicator,
      input: classes.input
    },
    popupIcon: /*#__PURE__*/_react.default.createElement(_Icon.default, {
      id: "dropdown-chevron-down",
      className: classes.icon
    }),
    closeIcon: /*#__PURE__*/_react.default.createElement(_Icon.default, {
      id: "close2",
      className: classes.closeIcon
    }),
    renderInput: RenderInput
  }), error && /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(classes.errorText)
  }, error));
};
__signature__(Autocomplete, "useStyles{classes}\nuseCallback{onChangeOption}\nuseMemo{selected}", function () {
  return [useStyles];
});
__signature__(Autocomplete, "useStyles{classes}\nuseCallback{onChangeOption}\nuseMemo{selected}", function () {
  return [useStyles];
});
var _default = Autocomplete;
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/Autocomplete.js");
  reactHotLoader.register(Autocomplete, "Autocomplete", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Autocomplete.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Autocomplete.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/Autocomplete.js");
  reactHotLoader.register(Autocomplete, "Autocomplete", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Autocomplete.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Autocomplete.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();