'use client'

import { useCallback, useEffect, useState } from 'react';
import { Profile } from '../../types/profile';
import { getPersonalData } from '../profile';
import { useLocalStorage } from '../../hooks/useLocalStorage';
import { AUTH_TOKEN_KEY } from '../../constants/common';

export const useProfileSettings = (locale: string) => {
    const [jwt] = useLocalStorage(AUTH_TOKEN_KEY, '');
    const [profileSettings, setProfileSettings] = useState<Profile | undefined>();
    const [fetchLoading, setFetchLoading] = useState<boolean>(false);
    const [saveLoading, setSaveLoading] = useState<boolean>(false);

    useEffect(() => {
        if (jwt) {
            getPersonalData(locale, jwt)
                .then(({ data }) => {
                    setProfileSettings(data);
                })
                .catch((err) => {

                })
                .finally(() => {
                    setFetchLoading(false);
                });
        }
    }, []);

    const save = useCallback(() => {

    }, []);

    return {
        fetchLoading,
        save,
        saveLoading,
        profileSettings
    };
};
