import { Job } from '@blockeditor/store';
import { HtmlAdapter } from '../adapters/index.js';
import { createAssetsArchive, download } from './utils.js';
export async function exportPage(page) {
    const job = new Job({ workspace: page.workspace });
    const snapshot = await job.pageToSnapshot(page);
    const adapter = new HtmlAdapter();
    const htmlResult = await adapter.fromPageSnapshot({
        snapshot,
        assets: job.assetsManager,
    });
    let downloadBlob;
    const pageTitle = page.meta.title || 'Untitled';
    let name;
    const contentBlob = new Blob([htmlResult.file], { type: 'plain/text' });
    if (htmlResult.assetsIds.length > 0) {
        const zip = createAssetsArchive(job.assets, htmlResult.assetsIds);
        zip.file('index.html', contentBlob);
        downloadBlob = await zip.generateAsync({ type: 'blob' });
        name = `${pageTitle}.zip`;
    }
    else {
        downloadBlob = contentBlob;
        name = `${pageTitle}.html`;
    }
    download(downloadBlob, name);
}
//# sourceMappingURL=html.js.map