import styles from "./styles.module.scss";
import { useNavigate } from "react-router-dom";
import { useUpdateStep } from "@/components/ChatsPath/hooks/useUpdateStep";
import routes from "@/routes";
import { useDispatch } from "react-redux";
import { actions } from "@/store";
import YesNoButtons from "@/components/ChatsPath/components/YesNoButtons";
import { images } from "@/components/ChatsPath/data";
import { useSession } from "@/hooks/session/useSession";
import { ESourceAuthorization } from "@/api/resources/User";
import { useTranslations } from "@/hooks/translations";
import { ELocalesPlacement } from "@/locales";

function ResonateLife() {
  const { translate } = useTranslations(ELocalesPlacement.Chats);
  const { updateSession } = useSession();
  const dispatch = useDispatch();
  useUpdateStep(20);
  const navigate = useNavigate();

  const handleNext = async (answer: "yes" | "no") => {
    await updateSession(
      {
        answers: {
          resonateLife: answer,
        },
      },
      ESourceAuthorization["aura.chats"]
    );
    dispatch(actions.chats.updateAnswers({ resonateLife: answer }));
    navigate(routes.client.chatsQuizResonateFuture());
  };

  return (
    <>
      <h2 className={`chats-answers-title ${styles.title}`}>
        {translate("/quiz/resonateLife.title")}
      </h2>
      <img
        className={styles.image}
        src={images("resonate-2.webp")}
        alt="Image"
      />
      <YesNoButtons onClick={(answer) => handleNext(answer)} />
    </>
  );
}

export default ResonateLife;
