import {
  EGender,
  ERelationshipStatus,
  ESourceAuthorization,
} from "@/api/resources/User";
import { useSession } from "@/hooks/session/useSession";
import { selectors } from "@/store";
import { useEffect } from "react";
import { useSelector } from "react-redux";
import { Outlet } from "react-router-dom";

function LayoutSession() {
  const { updateSession } = useSession();
  const { flowChoice, partnerGender } = useSelector(
    selectors.selectQuestionnaire
  );

  useEffect(() => {
    if (flowChoice?.length) {
      updateSession(
        {
          profile: {
            relationship_status:
              ERelationshipStatus[flowChoice as ERelationshipStatus],
          },
        },
        ESourceAuthorization["aura.main.new"]
      );
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [flowChoice]);

  useEffect(() => {
    if (partnerGender?.length) {
      updateSession(
        {
          partner: {
            gender: EGender[partnerGender as EGender],
          },
        },
        ESourceAuthorization["aura.main.new"]
      );
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [partnerGender]);

  return (
    <>
      <Outlet />
    </>
  );
}

export default LayoutSession;
