import { defineStore } from "pinia";
import { timestampToDate } from "~/utils/helper";

export const useUserInfoStore = defineStore("userInfoStore", () => {
    const getUserInfoStore = ref<any>([])
    const setUserInfoStore = (data: any) => {
        // const userInfo: any[] =
        // {
        //     user_name: data?.access_token_payload?.preferred_username,
        //     type_user: data?.access_token_payload?.type_user,
        //     role_access: data?.access_token_payload?.resource_access[data?.access_token_payload.azp],
        //     userInfo: [
        //         {
        //             id: data?.user?.id,
        //             fullname: data?.access_token_payload?.name,
        //             given_name: data?.access_token_payload?.given_name || '-',
        //             family_name: data?.access_token_payload?.family_name || '-',
        //             email: data?.access_token_payload?.email || '- ',
        //             group: data?.access_token_payload?.group,
        //         }
        //     ],
        //     expires_in: [
        //         {
        //             timestamps: data?.expires_at,
        //             date: timestampToDate(data?.expires_at, 'id-ID'),
        //         }
        //     ],
        // };
        // console.log(data)
        getUserInfoStore.value = data;
    }

    const getSessionUserStore = ref<any>([])
    const setSessionUserStore = (data: any) => {
        getSessionUserStore.value=data
    }


    return { setUserInfoStore,setSessionUserStore, getUserInfoStore,getSessionUserStore }
})