'use client';

import { createContext, useContext } from 'react';
import type { Dispatch, SetStateAction } from 'react';
import type { AlertConfigItem } from '@/types/response/donation/alertConfig';

export type AlertConfigContextValue = {
	items: AlertConfigItem[];
	widgetToken: string|null;
	loading: boolean;
	saving: boolean;
	setSaving: Dispatch<SetStateAction<boolean>>;
	fetchList: () => void;
};

export const AlertConfigContext = createContext<AlertConfigContextValue|null>(null);

export function useAlertConfigContext(): AlertConfigContextValue {
	const ctx = useContext(AlertConfigContext);
	if (!ctx) {
		throw new Error('useAlertConfigContext must be used within AlertConfigProvider');
	}
	return ctx;
}