import { jsx as _jsx } from "react/jsx-runtime";
import React from "react";
import { useFetch } from "../../hooks/common";
import { isValidBody } from "./util";
const EmailServiceContext = React.createContext({
    subscribe: (_) => Promise.reject("Not implemented"),
    sendMessage: (_) => Promise.reject("Not implemented"),
    subscribeGenshiroWL: (_) => Promise.reject("Not implemented"),
    subscribeError: undefined,
    messageError: undefined,
    subscribeGenshiroWLError: undefined,
});
const DEFAULT_HEADERS = new Headers({
    "Content-Type": "application/json",
});
export const useEmailService = () => React.useContext(EmailServiceContext);
export const EmailServiceProvider = ({ baseUrl, children, }) => {
    const { exec: subscribe, error: subscribeError } = useFetch({
        query: `${baseUrl}/emails/subscription`,
        predicate: isValidBody,
        method: "post",
        headers: DEFAULT_HEADERS,
    }, false);
    const { exec: sendMessage, error: messageError } = useFetch({
        query: `${baseUrl}/emails/message`,
        predicate: isValidBody,
        method: "post",
        headers: DEFAULT_HEADERS,
    }, false);
    const { exec: subscribeGenshiroWL, error: subscribeGenshiroWLError } = useFetch({
        query: `${baseUrl}/genshiro/whitelist`,
        predicate: isValidBody,
        method: "post",
        headers: DEFAULT_HEADERS,
    }, false);
    return (_jsx(EmailServiceContext.Provider, { value: {
            subscribe: (payload) => subscribe(JSON.stringify(payload)),
            sendMessage: (payload) => sendMessage(JSON.stringify(payload)),
            subscribeGenshiroWL: (payload) => subscribeGenshiroWL(JSON.stringify(payload)),
            subscribeError,
            messageError,
            subscribeGenshiroWLError,
        }, children: children }));
};
//# sourceMappingURL=context.js.map