import { useAsync } from "@wp2/helpers/dist/client";
const generateStructure = async (message) => {
    const res = await fetch("/api/ai/structure", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ message }),
    });
    const json = await res.json();
    return json.data;
};
export const useGenerateStructure = (onSuccess) => {
    return useAsync(generateStructure, { onSuccess });
};
const generateBlock = async ({ prompt, name }) => {
    const res = await fetch("/api/ai/block", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ prompt, name }),
    });
    const json = await res.json();
    return json.data;
};
export const useGenerateBlock = (onSuccess) => {
    return useAsync(generateBlock, { onSuccess });
};
const editBlock = async ({ block, name, message }) => {
    const res = await fetch("/api/ai/edit", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ block, name, message }),
    });
    const json = await res.json();
    return json.data;
};
export const useEditBlock = (onSuccess) => {
    return useAsync(editBlock, { onSuccess });
};
