import { create } from 'zustand'

interface EditProfileState {
    visible: boolean
    initialName: string
    initialAvatar?: string
    onSaveCallback?: (data: { name: string; avatar?: string }) => void
}

interface EditProfileActions {
    open: (params: {
        initialName?: string
        initialAvatar?: string
        onSave?: (data: { name: string; avatar?: string }) => void
    }) => void
    close: () => void
}

type EditProfileStore = EditProfileState & EditProfileActions

export const useEditProfileStore = create<EditProfileStore>((set) => ({
    visible: false,
    initialName: '',
    initialAvatar: undefined,
    onSaveCallback: undefined,

    open: ({ initialName = '', initialAvatar, onSave }) => {
        set({
            visible: true,
            initialName,
            initialAvatar,
            onSaveCallback: onSave,
        })
    },

    close: () => {
        set({
            visible: false,
        })
    },
}))
