"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(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 _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); }

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

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,
    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 = _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/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);
})();