import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import { makeStyles } from '@material-ui/core/styles';
import { Alert } from '@material-ui/lab';
import { useIntl } from 'react-intl';
import Markdown from '../Markdown';
import { PrintButton } from '../PrintButton';
import Field from './Field';
import { useEffect, useState } from 'react';
import FormControlLabel from '@mui/material/FormControlLabel';
import Checkbox from '@mui/material/Checkbox';
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var useStyles = 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'
    },
    noPrint: {
      '& > *': {
        '@media print': {
          display: 'none'
        }
      }
    }
  };
});
export default function Review(props) {
  var _props$reviewProps, _props$reviewProps2, _config$elements, _props$reviewProps$hi, _props$reviewProps3, _props$config, _props$reviewProps4, _props$customMessages, _props$customMessages2, _props$reviewProps5, _props$reviewProps6;

  var classes = useStyles();
  var intl = 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';
  });

  var _useState = useState((_props$reviewProps$hi = (_props$reviewProps3 = props.reviewProps) === null || _props$reviewProps3 === void 0 ? void 0 : _props$reviewProps3.hideNotAnswered) !== null && _props$reviewProps$hi !== void 0 ? _props$reviewProps$hi : false),
      _useState2 = _slicedToArray(_useState, 2),
      hideNotAnswered = _useState2[0],
      setHideNotAnswered = _useState2[1];

  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__*/_jsxs("div", {
      className: classes.successTextBox,
      children: [/*#__PURE__*/_jsx(Markdown, {
        className: classes.successText,
        children: props.config.successText
      }), summaries && /*#__PURE__*/_jsx(_Fragment, {
        children: summaries === null || summaries === void 0 ? void 0 : summaries.map(function (summary) {
          return /*#__PURE__*/_jsx(Markdown, {
            className: classes.successText,
            children: summary.content
          });
        })
      }), " "]
    }) : /*#__PURE__*/_jsxs("div", {
      children: [/*#__PURE__*/_jsx(Markdown, {
        children: props.config.successText
      }), summaries && /*#__PURE__*/_jsx(_Fragment, {
        children: summaries === null || summaries === void 0 ? void 0 : summaries.map(function (summary) {
          return /*#__PURE__*/_jsx(Markdown, {
            children: summary.content
          });
        })
      }), " "]
    });
  }

  return /*#__PURE__*/_jsxs(_Fragment, {
    children: [((_props$reviewProps4 = props.reviewProps) === null || _props$reviewProps4 === void 0 ? void 0 : _props$reviewProps4.showSuccessText) !== false && /*#__PURE__*/_jsx(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__*/_jsx(_Fragment, {}), ((_props$reviewProps5 = props.reviewProps) === null || _props$reviewProps5 === void 0 ? void 0 : _props$reviewProps5.hideNotAnswered) ? /*#__PURE__*/_jsx(FormControlLabel, {
      className: classes.noPrint,
      checked: hideNotAnswered,
      onChange: function onChange(props) {
        return setHideNotAnswered(props.target.checked);
      },
      control: /*#__PURE__*/_jsx(Checkbox, {
        sx: {
          '& > *': {
            '@media print': {
              display: 'none'
            }
          }
        }
      }),
      label: intl.formatMessage({
        id: "THV8yf",
        defaultMessage: [{
          "type": 0,
          "value": "Piilota vastaamattomat kysymykset"
        }]
      })
    }) : /*#__PURE__*/_jsx(_Fragment, {}), /*#__PURE__*/_jsx(Field, _objectSpread(_objectSpread({
      root: true
    }, props), {}, {
      pageTitles: pageTitlesArray,
      hideNotAnswered: hideNotAnswered
    })), showSuccessText && !(config === null || config === void 0 ? void 0 : config.showSuccessTextOnTop) ? checkSuccessHighlight() : /*#__PURE__*/_jsx(_Fragment, {}), /*#__PURE__*/_jsxs("div", {
      className: classes.buttonContainer,
      children: [(_props$reviewProps6 = props.reviewProps) === null || _props$reviewProps6 === void 0 ? void 0 : _props$reviewProps6.actions, /*#__PURE__*/_jsx(PrintButton, {})]
    })]
  });
}
export var empty = '–';
//# sourceMappingURL=index.js.map