import { createSlice, createSelector } from "@reduxjs/toolkit";
import type { PayloadAction } from "@reduxjs/toolkit";

export interface IQuestionnaire {
  // profile
  gender: string;
  flowChoice: string;
  goal: string;
  parent: string;
  astrologyKnowledge: string;
  birthdate: string;
  isBirthTime: string;
  birthtime: string;
  birthPlace: string;
  problems: string;
  // personality traits
  relateToStatement: string;
  notice: string;
  sensitive: string;
  tendToOverthink: string;
  mostImportant: string;
  emotionalControl: string;
  attitude: string;
  want: string;
  relaxing: string;
  // partner
  partnerGender: string;
  partnerBirthdate: string;
  partnerIsBirthTime: string;
  partnerBirthtime: string;
  partnerBirthPlace: string;
  // relationships
  issueTogether: string;
  currentlyAffecting: string;
  partnerPriority: string;
  satisfied: string;
  emotionalConnection: string;
  bigPicture: string;
  introvertOrExtravert: string;
  irritated: string;
  conflict: string;
  aboutGoals: string;
  appreciated: string;
  decisions: string;
  // relationship_pattern
  priority: string;
  comfortable: string;
  goodEnough: string;
  angry: string;
  innerSelf: string;
  aboutPeople: string;
  idealDate: string;
  futurePartner: string;
  idealPartner: string;
  relationshipGoal: string;
  // aboutUs
  aboutUs: string;
}

const initialState: IQuestionnaire = {
  gender: "",
  flowChoice: "",
  goal: "",
  parent: "",
  astrologyKnowledge: "",
  birthdate: "",
  isBirthTime: "",
  birthtime: "12:00",
  birthPlace: "",
  problems: "",
  partnerGender: "",
  partnerBirthdate: "",
  partnerBirthtime: "12:00",
  partnerBirthPlace: "",
  issueTogether: "",
  partnerPriority: "",
  satisfied: "",
  emotionalConnection: "",
  bigPicture: "",
  introvertOrExtravert: "",
  irritated: "",
  conflict: "",
  aboutGoals: "",
  appreciated: "",
  decisions: "",
  relateToStatement: "",
  notice: "",
  sensitive: "",
  tendToOverthink: "",
  mostImportant: "",
  emotionalControl: "",
  attitude: "",
  want: "",
  relaxing: "",
  partnerIsBirthTime: "",
  currentlyAffecting: "",
  aboutUs: "",
  priority: "",
  comfortable: "",
  goodEnough: "",
  angry: "",
  innerSelf: "",
  aboutPeople: "",
  idealDate: "",
  futurePartner: "",
  idealPartner: "",
  relationshipGoal: ""
};

const questionnaireSlice = createSlice({
  name: "questionnaire",
  initialState,
  reducers: {
    update(state, action: PayloadAction<Partial<IQuestionnaire>>) {
      return { ...state, ...action.payload };
    },
  },
  extraReducers: (builder) => builder.addCase("reset", () => initialState),
});

export const { actions } = questionnaireSlice;
export const selectQuestionnaire = createSelector(
  (state: { questionnaire: IQuestionnaire }) => state.questionnaire,
  (questionnaire) => questionnaire
);
export default questionnaireSlice.reducer;
