<script lang="ts">
    import { type ReportMetadata } from '$lib/analysis.svelte';
    import type { ManifestEntry } from '$lib/manifest.svelte';
    import AnalysisTable from './AnalysisTable.svelte';
    let {
        entry,
    }: {
        entry: ManifestEntry;
    } = $props();
</script>

<div class="container mt-2">
    {#if entry.analysis_report === undefined}
        <p>Report unavailable, try refreshing.</p>
    {:else if typeof entry.analysis_report === 'string'}
        <p>Error getting analysis report: {entry.analysis_report}</p>
    {:else}
        {@const metadata: ReportMetadata = entry.analysis_report.metadata}
        <div class="flex flex-col gap-2">
            {#if entry.analysis_report.rows.length > 0}
                <AnalysisTable report={entry.analysis_report} />
            {:else}
                <p>No warnings to display!</p>
            {/if}
            {#if metadata !== undefined && metadata.rayhunter !== undefined}
                <div>
                    <p class="text-lg underline">Metadata</p>
                    <p>Analysis by Rayhunter version {metadata.rayhunter.rayhunter_version}</p>
                    <p><b>Device system OS:</b> {metadata.rayhunter.system_os}</p>
                </div>
                <div>
                    <p class="text-lg underline">Analyzers</p>
                    {#each metadata.analyzers as analyzer}
                        <p><b>{analyzer.name}:</b> {analyzer.description}</p>
                    {/each}
                </div>
            {:else}
                <p>N/A (analysis generated by an older version of rayhunter)</p>
            {/if}
        </div>
    {/if}
</div>
