"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactIntl = require("react-intl");
var _classnames = _interopRequireDefault(require("classnames"));
var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
var _styles = require("@material-ui/core/styles");
var _Modal = _interopRequireDefault(require("../Modal"));
var _modalProps = _interopRequireDefault(require("../modalProps"));
var _sharedMessages = _interopRequireDefault(require("./../../../../sharedMessages"));
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 _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; }
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 {
    actionPanel: {
      display: "flex",
      marginLeft: "auto",
      flex: "1 1 0",
      justifyContent: "space-between"
    },
    rightAction: {
      display: "flex",
      justifyContent: "flex-end"
    },
    leftAction: {
      display: "flex",
      justifyContent: "flex-start"
    },
    container: {
      width: "100%",
      wordWrap: "normal"
    },
    fullHeight: {
      height: theme.spacing(56)
    },
    step: {
      position: "relative",
      display: "inline-block",
      fontFamily: theme.typography.button.fontFamily,
      fontSize: theme.typography.h3Size,
      letterSpacing: "0",
      lineHeight: theme.spacing(2),
      textTransform: theme.typography.button.textTransform,
      padding: theme.spacing(1, 0),
      marginRight: theme.spacing(0.4),
      "&:not(:first-child)": {
        backgroundColor: theme.palette.grey.borders,
        color: "#FFF",
        width: "auto",
        paddingLeft: "".concat(theme.spacing(3), " !important")
      },
      "&:last-child": {
        paddingRight: theme.spacing(2.4),
        borderRadius: theme.spacing(0, 0.8, 0, 0)
      },
      "&:not(:first-child):not(:last-child):after, &:not(:last-child):before": {
        content: "' '",
        width: 0,
        height: 0,
        position: "absolute",
        top: 0,
        zIndex: 2,
        border: "".concat(theme.spacing(2), " solid transparent"),
        borderLeft: "".concat(theme.spacing(2), " solid ").concat(theme.palette.grey.borders),
        borderRightWidth: 0
      },
      "&:not(:last-child):before": {
        zIndex: 1,
        left: "100%",
        borderLeft: "".concat(theme.spacing(2), " solid ").concat(theme.palette.grey.lighter),
        transform: "translateX(".concat(theme.spacing(0.4), ")")
      }
    },
    active: {
      backgroundColor: "".concat(theme.palette.primary.dark, " !important"),
      boxShadow: "inset 10px 0 10px 1px rgba(0,0,0,0.18)",
      "&:after": {
        borderLeftColor: "".concat(theme.palette.primary.dark, " !important")
      }
    },
    done: {
      backgroundColor: "".concat(theme.palette.primary.main, " !important"),
      boxShadow: "0 1px 1px 0 rgba(0,0,0,0.1)",
      "&:after": {
        borderLeftColor: "".concat(theme.palette.primary.main, " !important")
      }
    }
  };
});
var StepperModal = function StepperModal(_ref) {
  var _steps$currentStep, _steps$currentStep$fu, _steps$currentStep2, _steps$currentStep3, _steps$currentStep4;
  var _ref$steps = _ref.steps,
    steps = _ref$steps === void 0 ? [] : _ref$steps,
    _ref$title = _ref.title,
    title = _ref$title === void 0 ? "" : _ref$title,
    open = _ref.open,
    closeCallback = _ref.closeCallback,
    confirmCallback = _ref.confirmCallback,
    backdropCallback = _ref.backdropCallback,
    confirmTitle = _ref.confirmTitle,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? "wide" : _ref$type;
  var classes = useStyles();
  var _useState = (0, _react.useState)(0),
    _useState2 = _slicedToArray(_useState, 2),
    currentStep = _useState2[0],
    changeCurrentStep = _useState2[1];
  (0, _react.useEffect)(function () {
    if (open) {
      changeCurrentStep(0);
    }
  }, [open]);
  var modalProps = new _modalProps.default();
  var titleComponent = /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
    className: classes.step
  }, title), steps.map(function (_ref2, index) {
    var title = _ref2.title;
    return /*#__PURE__*/_react.default.createElement("div", {
      key: index,
      className: (0, _classnames.default)(classes.step, index < currentStep && classes.done, index === currentStep && classes.active)
    }, title);
  }));
  var nextDisabledFunction = (_steps$currentStep = steps[currentStep]) == null ? void 0 : _steps$currentStep.nextDisabled;
  var isFullHeight = (_steps$currentStep$fu = (_steps$currentStep2 = steps[currentStep]) == null ? void 0 : _steps$currentStep2.fullHeight) != null ? _steps$currentStep$fu : true;
  var nextDisabled = nextDisabledFunction ? !!nextDisabledFunction() : false;
  var contentComponent = /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(classes.container, isFullHeight && classes.fullHeight)
  }, (_steps$currentStep3 = steps[currentStep]) == null ? void 0 : _steps$currentStep3.content);
  modalProps.set(_modalProps.default.propNames.title, titleComponent);
  modalProps.set(_modalProps.default.propNames.open, open);
  modalProps.set(_modalProps.default.propNames.backdropClickCallback, backdropCallback != null ? backdropCallback : closeCallback);
  modalProps.set(_modalProps.default.propNames.type, type);
  var nextClick = (0, _react.useCallback)(function (customHandler) {
    if (customHandler) {
      customHandler();
    }
    changeCurrentStep(function (step) {
      return step + 1;
    });
  }, []);
  var backClick = (0, _react.useCallback)(function () {
    return changeCurrentStep(function (step) {
      return step - 1;
    });
  }, []);
  var actionPanel = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
    className: classes.actionPanel
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: classes.leftAction
  }, !!currentStep && /*#__PURE__*/_react.default.createElement(_Button.default, {
    variant: "contained",
    color: "primary",
    onClick: backClick,
    disableElevation: true
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, _sharedMessages.default.back))), /*#__PURE__*/_react.default.createElement("div", {
    className: classes.rightAction
  }, /*#__PURE__*/_react.default.createElement(_Button.default, {
    variant: "outlined",
    onClick: closeCallback
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, _sharedMessages.default.cancel)), currentStep < steps.length - 1 && (((_steps$currentStep4 = steps[currentStep]) == null || (_steps$currentStep4 = _steps$currentStep4.actions) == null ? void 0 : _steps$currentStep4.length) > 0 ? steps[currentStep].actions.map(function (action) {
    return /*#__PURE__*/_react.default.createElement(_Button.default, {
      key: action.value,
      variant: "contained",
      color: "primary",
      disabled: nextDisabled,
      onClick: function onClick() {
        return nextClick(action.handler);
      },
      disableElevation: true
    }, action.label);
  }) : /*#__PURE__*/_react.default.createElement(_Button.default, {
    variant: "contained",
    color: "primary",
    disabled: nextDisabled,
    onClick: function onClick() {
      return nextClick();
    },
    disableElevation: true
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, _sharedMessages.default.next))), currentStep === steps.length - 1 && /*#__PURE__*/_react.default.createElement(_Button.default, {
    variant: "contained",
    color: "primary",
    disabled: nextDisabled,
    onClick: confirmCallback,
    disableElevation: true
  }, confirmTitle || /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, _sharedMessages.default.applyChanges)))));
  modalProps.set(_modalProps.default.propNames.actionPanel, actionPanel);
  return /*#__PURE__*/_react.default.createElement(_Modal.default, {
    message: contentComponent,
    modalProps: modalProps
  });
};
__signature__(StepperModal, "useStyles{classes}\nuseState{[currentStep, changeCurrentStep](0)}\nuseEffect{}\nuseCallback{nextClick}\nuseCallback{backClick}", function () {
  return [useStyles];
});
__signature__(StepperModal, "useStyles{classes}\nuseState{[currentStep, changeCurrentStep](0)}\nuseEffect{}\nuseCallback{nextClick}\nuseCallback{backClick}", function () {
  return [useStyles];
});
var _default = StepperModal;
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/DataDisplay/PredefinedElements/StepperModal.js");
  reactHotLoader.register(StepperModal, "StepperModal", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.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/DataDisplay/PredefinedElements/StepperModal.js");
  reactHotLoader.register(StepperModal, "StepperModal", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();