import React, { ReactNode } from 'react';
import { useProfile } from 'hooks/profile';
import { MessageFragment, MyProfileFragment } from 'expo-schema';

export const ProfileContext = React.createContext<ProfileContextType>({
  profile: undefined,
  drafts: [],
  removeDraft: () => {},
  refetchDrafts: () => {},
});

export const ProfileProvider: React.FC<ProfileProps> = ({ children }) => {
  const { profile, drafts, removeDraft, refetchDrafts } = useProfile();
  return (
    <ProfileContext.Provider value={{ profile, drafts, removeDraft, refetchDrafts }}>
      {children}
    </ProfileContext.Provider>
  );
};

export interface ProfileContextType {
  profile: MyProfileFragment | undefined | null;
  drafts: MessageFragment[];
  removeDraft: (draftId: string) => void;
  refetchDrafts: () => void;
}

interface ProfileProps {
  children?: ReactNode;
}
