'use client';

import { createContext, useContext, type ReactNode } from 'react';
import type { Customer } from '@/app/lib/customer';

const CustomerContext = createContext<Customer | null>(null);

/** The customer the open conversation is about, for components deep in the message list (a SQL block must send it with its query). */
export function CustomerProvider({ customer, children }: { customer: Customer | null; children: ReactNode }) {
  return <CustomerContext.Provider value={customer}>{children}</CustomerContext.Provider>;
}

export function useCustomer(): Customer | null {
  return useContext(CustomerContext);
}
