"use strict";

exports.__esModule = true;
exports.default = exports.Preferences = exports.clickOutsideHandler = exports.createGetUpdater = exports.PrefButton = exports.Footer = exports.PrefForm = exports.Header = exports.Wrapper = exports.PrefPanel = exports.PREFS_NAME = void 0;

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _reactRedux = require("react-redux");

var _utils = require("../../utils");

var _Sidepanel = _interopRequireDefault(require("../Sidepanel"));

var _Button = _interopRequireDefault(require("../Button"));

var _Text = _interopRequireDefault(require("../Text"));

var _Form = require("../Form/Form");

var _FieldElements = _interopRequireDefault(require("../Form/FieldElements"));

var _useViewState3 = _interopRequireDefault(require("../../hooks/useViewState"));

var _view = require("../../actions/view");

var _locale = require("../../actions/locale");

var _applications = require("../../actions/applications");

var _applications2 = require("../../selectors/applications");

var _locale2 = require("../../selectors/locale");

var _settings = require("../../selectors/settings");

var _withClickOutside = _interopRequireDefault(require("../../hocs/withClickOutside"));

var _versionInfo = require("../../actions/versionInfo");

var _sharedMessages = _interopRequireDefault(require("./../../sharedMessages"));

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

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

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 PREFS_NAME = "__prefsDialog";
exports.PREFS_NAME = PREFS_NAME;
var PrefPanel = (0, _styledComponents.default)(_Sidepanel.default).withConfig({
  displayName: "Preferences__PrefPanel",
  componentId: "sc-1fqlcmy-0"
})(["background-color:#f7f7f7;border-left:1px solid ", ";border-top:1px solid ", ";border-top-left-radius:5px;top:40px;box-shadow:-3px 2px 5px 0px rgba(0,0,0,0.2);z-index:9998;"], (0, _utils.getThemeProp)(["colors", "borderLight"], "#cccccc"), (0, _utils.getThemeProp)(["colors", "borderLight"], "#cccccc"));
exports.PrefPanel = PrefPanel;
var Wrapper = (0, _withClickOutside.default)(_styledComponents.default.div.withConfig({
  displayName: "Preferences__Wrapper",
  componentId: "sc-1fqlcmy-1"
})(["display:flex;flex-direction:column;height:100%;"]));
exports.Wrapper = Wrapper;

var Header = _styledComponents.default.div.withConfig({
  displayName: "Preferences__Header",
  componentId: "sc-1fqlcmy-2"
})(["flex:0 0 auto;border-bottom:1px solid ", ";border-top-left-radius:5px;padding:15px 30px;height:18px;font-size:15px;font-family:", ";text-transform:uppercase;color:", ";background-color:#ffffff;"], (0, _utils.getThemeProp)(["colors", "borderLight"], "#cccccc"), (0, _utils.getThemeProp)(["fonts", "header"], "sans-serif"), (0, _utils.getThemeProp)(["colors", "application", "base"], "#ccc"));

exports.Header = Header;

var PrefForm = _styledComponents.default.div.withConfig({
  displayName: "Preferences__PrefForm",
  componentId: "sc-1fqlcmy-3"
})(["flex:1 1 auto;display:flex;flex-direction:column;padding:20px 30px;font-size:12px;"]);

exports.PrefForm = PrefForm;

var Footer = _styledComponents.default.div.withConfig({
  displayName: "Preferences__Footer",
  componentId: "sc-1fqlcmy-4"
})(["flex:0 0 auto;display:flex;align-items:center;justify-content:flex-end;background-color:#ffffff;border-top:1px solid ", ";padding-right:10px;height:60px;"], (0, _utils.getThemeProp)(["colors", "borderLight"], "#cccccc"));

exports.Footer = Footer;
var PrefButton = (0, _styledComponents.default)(_Button.default).withConfig({
  displayName: "Preferences__PrefButton",
  componentId: "sc-1fqlcmy-5"
})(["margin-right:20px;min-width:110px;"]);
exports.PrefButton = PrefButton;
var createGetUpdater = (0, _utils.memoize)(function (update) {
  return (0, _utils.memoize)(function (name) {
    return function (value) {
      return update(name, value);
    };
  });
});
exports.createGetUpdater = createGetUpdater;

var usePreferenceSetup = function usePreferenceSetup() {
  var dispatch = (0, _reactRedux.useDispatch)();

  var _useViewState = (0, _useViewState3.default)(PREFS_NAME),
      _useViewState2 = _slicedToArray(_useViewState, 2),
      viewState = _useViewState2[0],
      updateViewState = _useViewState2[1];

  return {
    show: viewState.show,
    values: _objectSpread({
      language: (0, _reactRedux.useSelector)(_locale2.currentLocaleOrDefault),
      application: (0, _reactRedux.useSelector)(_settings.defaultAppId) || ""
    }, viewState),
    getUpdater: createGetUpdater(updateViewState),
    languageOptions: (0, _utils.unwrapImmutable)((0, _reactRedux.useSelector)(_locale2.cultureOptionList)),
    applicationOptions: (0, _utils.unwrapImmutable)((0, _reactRedux.useSelector)(_applications2.localizedAppOptionSelector)),
    clear: function clear() {
      return dispatch((0, _view.setValue)(PREFS_NAME, {
        show: false
      }));
    },
    save: function save() {
      if (viewState.language) {
        dispatch((0, _locale.changeLocale)(viewState.language));
        dispatch((0, _locale.setDefaultLanguage)(viewState.language));
        dispatch((0, _versionInfo.resetVersionInfo)()); // TODO: reload any language dependent data?
      }

      if (viewState.application) {
        dispatch((0, _applications.setMyApplication)(viewState.application));
      }

      dispatch((0, _view.setValue)(PREFS_NAME, {
        show: false
      }));
    }
  };
};

__signature__(usePreferenceSetup, "useDispatch{dispatch}\nuseViewState{[viewState, updateViewState]}\nuseSelector{}\nuseSelector{}\nuseSelector{}\nuseSelector{}", function () {
  return [_reactRedux.useDispatch, _useViewState3.default, _reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector];
});

__signature__(usePreferenceSetup, "useDispatch{dispatch}\nuseViewState{[viewState, updateViewState]}\nuseSelector{}\nuseSelector{}\nuseSelector{}\nuseSelector{}", function () {
  return [_reactRedux.useDispatch, _useViewState3.default, _reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector];
});

var clickOutsideHandler = function clickOutsideHandler(e) {
  e.preventDefault();
  e.stopPropagation();
};

exports.clickOutsideHandler = clickOutsideHandler;

var Preferences = function Preferences() {
  var _usePreferenceSetup = usePreferenceSetup(),
      show = _usePreferenceSetup.show,
      getUpdater = _usePreferenceSetup.getUpdater,
      save = _usePreferenceSetup.save,
      clear = _usePreferenceSetup.clear,
      languageOptions = _usePreferenceSetup.languageOptions,
      applicationOptions = _usePreferenceSetup.applicationOptions,
      values = _usePreferenceSetup.values;

  return /*#__PURE__*/_react.default.createElement(PrefPanel, {
    in: show,
    width: "380px",
    timeout: 400
  }, /*#__PURE__*/_react.default.createElement(Wrapper, {
    onClickOutside: clickOutsideHandler
  }, /*#__PURE__*/_react.default.createElement(Header, null, /*#__PURE__*/_react.default.createElement(_Text.default, {
    message: _sharedMessages.default.preferences
  })), /*#__PURE__*/_react.default.createElement(PrefForm, null, /*#__PURE__*/_react.default.createElement(_Form.FormContext.Provider, {
    value: {
      values: values
    }
  }, /*#__PURE__*/_react.default.createElement(_FieldElements.default, {
    fields: [{
      label: _sharedMessages.default.displayLanguage,
      type: "Selector",
      name: "language",
      options: languageOptions
    }, {
      label: _sharedMessages.default.defaultApp,
      type: "Selector",
      name: "application",
      options: applicationOptions
    }],
    getUpdater: getUpdater
  }))), /*#__PURE__*/_react.default.createElement(Footer, null, /*#__PURE__*/_react.default.createElement(PrefButton, {
    id: "cancelPrefs",
    onClick: clear
  }, /*#__PURE__*/_react.default.createElement(_Text.default, {
    message: _sharedMessages.default.cancel
  })), /*#__PURE__*/_react.default.createElement(PrefButton, {
    id: "savePrefs",
    primary: true,
    onClick: save
  }, /*#__PURE__*/_react.default.createElement(_Text.default, {
    message: _sharedMessages.default.save
  })))));
};

exports.Preferences = Preferences;

__signature__(Preferences, "usePreferenceSetup{{ show, getUpdater, save, clear, languageOptions, applicationOptions, values }}", function () {
  return [usePreferenceSetup];
});

__signature__(Preferences, "usePreferenceSetup{{ show, getUpdater, save, clear, languageOptions, applicationOptions, values }}", function () {
  return [usePreferenceSetup];
});

var _default = Preferences;
var _default2 = _default;
var _default3 = _default2;
exports.default = _default3;
;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(PREFS_NAME, "PREFS_NAME", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(PrefPanel, "PrefPanel", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(Wrapper, "Wrapper", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(Header, "Header", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(PrefForm, "PrefForm", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(Footer, "Footer", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(PrefButton, "PrefButton", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(createGetUpdater, "createGetUpdater", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(usePreferenceSetup, "usePreferenceSetup", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(clickOutsideHandler, "clickOutsideHandler", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(Preferences, "Preferences", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.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(PREFS_NAME, "PREFS_NAME", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(PrefPanel, "PrefPanel", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(Wrapper, "Wrapper", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(Header, "Header", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(PrefForm, "PrefForm", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(Footer, "Footer", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(PrefButton, "PrefButton", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(createGetUpdater, "createGetUpdater", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(usePreferenceSetup, "usePreferenceSetup", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(clickOutsideHandler, "clickOutsideHandler", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(Preferences, "Preferences", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/AppFrame/Preferences.js");
})();

;

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