'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useState, useCallback } from 'react';
const PlaygroundContext = /*#__PURE__*/ createContext(null);
export function PlaygroundProvider({ children }) {
    const [pendingPrefill, setPendingPrefill] = useState(null);
    const [currentRequestPayload, setCurrentRequestPayloadState] = useState(null);
    const [triggerSend, setTriggerSend] = useState(false);
    const setPrefill = useCallback((data)=>{
        setPendingPrefill(data);
    }, []);
    const clearPrefill = useCallback(()=>{
        setPendingPrefill(null);
    }, []);
    const setCurrentRequestPayload = useCallback((payload)=>{
        setCurrentRequestPayloadState(payload);
    }, []);
    const requestSend = useCallback(()=>{
        setTriggerSend(true);
    }, []);
    const clearSendTrigger = useCallback(()=>{
        setTriggerSend(false);
    }, []);
    return /*#__PURE__*/ _jsx(PlaygroundContext.Provider, {
        value: {
            pendingPrefill,
            setPrefill,
            clearPrefill,
            currentRequestPayload,
            setCurrentRequestPayload,
            triggerSend,
            requestSend,
            clearSendTrigger
        },
        children: children
    });
}
export function usePlaygroundPrefill() {
    const context = useContext(PlaygroundContext);
    if (!context) {
        throw new Error('usePlaygroundPrefill must be used within a PlaygroundProvider');
    }
    return context;
}
export function useCurrentRequestPayload() {
    const context = useContext(PlaygroundContext);
    if (!context) {
        throw new Error('useCurrentRequestPayload must be used within a PlaygroundProvider');
    }
    return {
        currentRequestPayload: context.currentRequestPayload,
        setCurrentRequestPayload: context.setCurrentRequestPayload
    };
}
export function useSendTrigger() {
    const context = useContext(PlaygroundContext);
    if (!context) {
        throw new Error('useSendTrigger must be used within a PlaygroundProvider');
    }
    return {
        triggerSend: context.triggerSend,
        requestSend: context.requestSend,
        clearSendTrigger: context.clearSendTrigger
    };
}
