<script lang="ts">
    import {t} from "astro-i18n"
    import {createEventDispatcher} from "svelte";
    import {schemRepo} from "../repo/repo.ts";
    import {Modal, Spinner} from "flowbite-svelte";
    import {astroI18n} from "astro-i18n";
    import moment from "moment/moment";
    import {CheckSolid, XCircleOutline} from "flowbite-svelte-icons";
    import SchematicInfoModal from "./SchematicInfoModal.svelte";

    const dispatch = createEventDispatcher();

    export let schematicId: number;

    let schemInfo = getSchematicInfo(schematicId);

    function getSchematicInfo(id: number) {
        return $schemRepo.getSchematicInfo(id);
    }
</script>

{#await schemInfo}
    <Modal title="Loading" open on:close={() => dispatch("reset")}>
        <Spinner />
    </Modal>
{:then info}
    <SchematicInfoModal {info} on:reset />
{:catch e}
    <Modal title="Error" open on:close={() => dispatch("reset")}>
        <p>{e.message}</p>
        <button class="btn !ml-auto" slot="footer" on:click={() => dispatch("reset")}>Close</button>
    </Modal>
{/await}