import "./PlanComponent.css";
import logo from "./Aivaz.svg";

import { useState } from "react";

import * as moment from "moment";
import "moment/locale/ru";
import { motion, AnimatePresence } from "framer-motion";

import { CalendarComponent } from "./CalendarComponent/CalendarComponent";
import { TimepickerComponent } from "./TimepickerComponent/TimepickerComponent";
import { Form } from "./Form/Form";

import { Finish } from "./Finish/Finish";
import { useAppSelector } from "hooks/redux";
import { popupAnimation } from "utils/animationProps";

export const PlanComponent: React.FC<any> = () => {
  const { isDone, isCalendar, isTimepicker, isForm, time, currTime } = useAppSelector(
    (state) => state.planReducer
  );

  return (
    <div className="content-container-plan">
      <div className="plan-logo-container">
        <img style={{ width: "158px" }} src={logo}></img>
      </div>
      <div className="calendar-position">
        <AnimatePresence mode="wait">
          {isCalendar && (
            <motion.div
              key={1}
              variants={popupAnimation}
              initial={"hidden"}
              animate={"show"}
              exit={"hidden"}
            >
              <CalendarComponent time={time}></CalendarComponent>
            </motion.div>
          )}
          {isTimepicker && (
            <motion.div
              key={2}
              variants={popupAnimation}
              initial={"hidden"}
              animate={"show"}
              exit={"hidden"}
            >
              <TimepickerComponent time={currTime}></TimepickerComponent>
            </motion.div>
          )}
          {isForm && (
            <motion.div
              key={3}
              variants={popupAnimation}
              initial={"hidden"}
              animate={"show"}
              exit={"hidden"}
            >
              <Form time={currTime}></Form>
            </motion.div>
          )}
          {isDone && (
            <motion.div
              key={4}
              variants={popupAnimation}
              initial={"hidden"}
              animate={"show"}
              exit={"hidden"}
            >
              <Finish></Finish>
            </motion.div>
          )}
        </AnimatePresence>
        {!isDone && (
          <>
            <div className="line line-calendar"></div>
            <button style={{ height: '32px' }} className="button button-type-small">
              На сайт жилого комплекса
            </button>
          </>
        )}
      </div>
    </div>
  );
};
