/**
 * Copyright (c) Microsoft Corporation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// @ts-ignore
import * as zipImport from '@zip.js/zip.js/lib/zip-no-worker-inflate.js';
import * as React from 'react';
import * as ReactDOM from 'react-dom/client';
import './colors.css';
import { ReportView } from './reportView';
// @ts-ignore
const zipjs = zipImport;
import logo from '@web/assets/playwright-logo.svg';
import { SearchParamsProvider } from './links';
import { applyTheme } from '@web/theme';
const link = document.createElement('link');
link.rel = 'shortcut icon';
link.href = logo;
document.head.appendChild(link);
const ReportLoader = () => {
    const [report, setReport] = React.useState();
    React.useEffect(() => {
        const zipReport = new ZipReport();
        zipReport.load().then(() => {
            // Drop node after consumption
            document.getElementById('playwrightReportBase64')?.remove();
            setReport(zipReport);
        });
    }, []);
    return <SearchParamsProvider>
    <ReportView report={report}/>
  </SearchParamsProvider>;
};
window.onload = () => {
    applyTheme();
    ReactDOM.createRoot(document.querySelector('#root')).render(<ReportLoader />);
};
class ZipReport {
    _entries = new Map();
    _json;
    async load() {
        const zipURI = document.getElementById('playwrightReportBase64').content.textContent;
        const zipReader = new zipjs.ZipReader(new zipjs.Data64URIReader(zipURI), { useWebWorkers: false });
        for (const entry of await zipReader.getEntries())
            this._entries.set(entry.filename, entry);
        this._json = await this.entry('report.json');
    }
    json() {
        return this._json;
    }
    async entry(name) {
        const reportEntry = this._entries.get(name);
        const writer = new zipjs.TextWriter();
        await reportEntry.getData(writer);
        return JSON.parse(await writer.getData());
    }
}
//# sourceMappingURL=index.js.map