import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";

var _templateObject;

import React from "react";
import { Slot } from "nano-slots";
import Dialog from "../../ui/lab/Dialog";
import CssGrid from "../../ui/CssGrid";
import Box from "../../ui/Box";
import styled from "../../ui/styles/styled";
import Rocket from "./Rocket";
import TopbarProgressBar from "./TopbarProgressBar";
import { usePMaxState } from "./context";
import { setStep } from "./reducer";

function PMAXCreationModal(_ref) {
  var open = _ref.open,
      onClose = _ref.onClose,
      children = _ref.children,
      translations = _ref.translations;

  var _usePMaxState = usePMaxState(),
      _usePMaxState2 = _slicedToArray(_usePMaxState, 2),
      state = _usePMaxState2[0],
      dispatch = _usePMaxState2[1];

  var handleClose = function handleClose() {
    onClose();

    if (state.step === "finish") {
      // Reset step state
      setStep(dispatch, "goal");
    }
  };

  return /*#__PURE__*/React.createElement(DialogRelative, {
    globalWidth: "675px",
    open: open,
    onClose: handleClose
  }, state.step !== "finish" && /*#__PURE__*/React.createElement(Dialog.ExtendTopbar, null, /*#__PURE__*/React.createElement(Dialog.Title, null, translations.title), /*#__PURE__*/React.createElement(CssGrid, {
    gridTemplateColumns: "1fr auto",
    alignItems: "center"
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(TopbarProgressBar, {
    translations: translations.progress_bar
  })), /*#__PURE__*/React.createElement(Box, {
    width: "87px",
    position: "relative"
  }, /*#__PURE__*/React.createElement(Box, {
    component: Rocket,
    position: "absolute",
    top: "-48px"
  })))), /*#__PURE__*/React.createElement(Slot, {
    name: "pmax-creation-step-".concat(state.step)
  }), children);
}

var DialogRelative = styled(Dialog)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n  position: relative;\n"])));
export default PMAXCreationModal;