'use client';

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

export type RankConfigContextValue = {
	items: RankConfigItem[];
	loading: boolean;
	saving: boolean;
	setSaving: Dispatch<SetStateAction<boolean>>;
	fetchList: () => void;
};

export const RankConfigContext = createContext<RankConfigContextValue|null>(null);

export function useRankConfigContext(): RankConfigContextValue {
	const ctx = useContext(RankConfigContext);
	if (!ctx) {
		throw new Error('useRankConfigContext must be used within RankConfigProvider');
	}
	return ctx;
}