import { EventTypes } from "./EventTypes.js";
export const FilesystemEvents = Object.freeze({
    requestSaveFile: async (opts, target = document.body) => {
        const e = new CustomEvent(EventTypes.Filesystem.requestSaveFile, {
            bubbles: true,
            composed: true,
            cancelable: true,
            detail: {
                options: opts,
                result: undefined,
            }
        });
        target.dispatchEvent(e);
        return e.detail.result;
    },
    requestOpenFile: async (opts, target = document.body) => {
        const e = new CustomEvent(EventTypes.Filesystem.requestOpenFile, {
            bubbles: true,
            composed: true,
            cancelable: true,
            detail: {
                options: opts,
                result: undefined,
            }
        });
        target.dispatchEvent(e);
        return e.detail.result;
    },
    writeFile: async (path, contents, opts, target = document.body) => {
        const e = new CustomEvent(EventTypes.Filesystem.writeFile, {
            bubbles: true,
            composed: true,
            cancelable: true,
            detail: {
                path,
                contents,
                options: opts,
                result: undefined,
            }
        });
        target.dispatchEvent(e);
        await e.detail.result;
    },
    readFile: async (path, opts, target = document.body) => {
        const e = new CustomEvent(EventTypes.Filesystem.readFile, {
            bubbles: true,
            composed: true,
            cancelable: true,
            detail: {
                path,
                options: opts,
                result: undefined,
            }
        });
        target.dispatchEvent(e);
        return e.detail.result;
    },
});
//# sourceMappingURL=FilesystemEvents.js.map