"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = Review;
exports.empty = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _styles = require("@material-ui/core/styles");

var _lab = require("@material-ui/lab");

var _reactIntl = require("react-intl");

var _Markdown = _interopRequireDefault(require("../Markdown"));

var _PrintButton = require("../PrintButton");

var _Field = _interopRequireDefault(require("./Field"));

var _react = require("react");

var _jsxRuntime = require("react/jsx-runtime");

var useStyles = (0, _styles.makeStyles)(function (theme) {
  return {
    buttonContainer: {
      '& > *': {
        marginRight: theme.spacing(1),
        marginTop: theme.spacing(1),
        '@media print': {
          display: 'none'
        }
      }
    },
    successTextBox: {
      marginBottom: theme.spacing(3),
      marginTop: theme.spacing(3),
      color: theme.palette.primary,
      borderStyle: 'solid',
      borderRadius: '3px',
      borderSpacing: '15px'
    },
    successText: {
      padding: '5px',
      paddingLeft: '20px',
      paddingRight: '20px',
      color: theme.palette.primary,
      fontWeight: 'bold',
      fontSize: '1.1em'
    }
  };
});

function Review(props) {
  var _props$reviewProps, _props$reviewProps2, _config$elements, _props$config, _props$reviewProps3, _props$customMessages, _props$customMessages2, _props$reviewProps4;

  var classes = useStyles();
  var intl = (0, _reactIntl.useIntl)();
  var config = props.config;
  var showSuccessText = ((_props$reviewProps = props.reviewProps) === null || _props$reviewProps === void 0 ? void 0 : _props$reviewProps.showSuccessText) !== false;
  var highlightSuccessText = (_props$reviewProps2 = props.reviewProps) === null || _props$reviewProps2 === void 0 ? void 0 : _props$reviewProps2.highlightSuccessText;
  var summaries = config === null || config === void 0 ? void 0 : (_config$elements = config.elements) === null || _config$elements === void 0 ? void 0 : _config$elements.filter(function (element) {
    return element.type === 'summary';
  });
  (0, _react.useEffect)(function () {
    window.scrollTo(0, 0);
  }, []);
  var pageTitlesArray = props === null || props === void 0 ? void 0 : (_props$config = props.config) === null || _props$config === void 0 ? void 0 : _props$config.elements.filter(function (x) {
    return x.type === 'pageTitle' && x.content;
  });

  function checkSuccessHighlight() {
    return highlightSuccessText === true ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: classes.successTextBox,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Markdown["default"], {
        className: classes.successText,
        children: props.config.successText
      }), summaries && /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
        children: summaries === null || summaries === void 0 ? void 0 : summaries.map(function (summary) {
          return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Markdown["default"], {
            className: classes.successText,
            children: summary.content
          });
        })
      }), " "]
    }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Markdown["default"], {
        children: props.config.successText
      }), summaries && /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
        children: summaries === null || summaries === void 0 ? void 0 : summaries.map(function (summary) {
          return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Markdown["default"], {
            children: summary.content
          });
        })
      }), " "]
    });
  }

  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [((_props$reviewProps3 = props.reviewProps) === null || _props$reviewProps3 === void 0 ? void 0 : _props$reviewProps3.showSuccessText) !== false && /*#__PURE__*/(0, _jsxRuntime.jsx)(_lab.Alert, {
      severity: "success",
      children: (_props$customMessages = (_props$customMessages2 = props.customMessages) === null || _props$customMessages2 === void 0 ? void 0 : _props$customMessages2.reviewSubmitConfirmation) !== null && _props$customMessages !== void 0 ? _props$customMessages : intl.formatMessage({
        id: "J+zUnM",
        defaultMessage: [{
          "type": 0,
          "value": "Lomake lähetetty!"
        }]
      })
    }), showSuccessText && (config === null || config === void 0 ? void 0 : config.showSuccessTextOnTop) ? checkSuccessHighlight() : /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Field["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
      root: true
    }, props), {}, {
      pageTitles: pageTitlesArray
    })), showSuccessText && !(config === null || config === void 0 ? void 0 : config.showSuccessTextOnTop) ? checkSuccessHighlight() : /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: classes.buttonContainer,
      children: [(_props$reviewProps4 = props.reviewProps) === null || _props$reviewProps4 === void 0 ? void 0 : _props$reviewProps4.actions, /*#__PURE__*/(0, _jsxRuntime.jsx)(_PrintButton.PrintButton, {})]
    })]
  });
}

var empty = '–';
exports.empty = empty;
//# sourceMappingURL=index.cjs.map