'use client';

import { createContext, type PropsWithChildren, useMemo, useState } from 'react';

export type FilterType = 'all' | 'invited' | 'invitedBy';

type ContextType = { filter: FilterType; setFilter: (filter: FilterType) => void };

export const ContactsContext = createContext<ContextType>({} as ContextType);

export function ContactsContextProvider({ children }: Readonly<PropsWithChildren>) {
  const [filter, setFilter] = useState<FilterType>('all');

  const value = useMemo(() => ({ filter, setFilter }), [filter, setFilter]);

  return <ContactsContext value={value}>{children}</ContactsContext>;
}
