<!--
  -   This file is a part of the SteamWar software.
  -
  -   Copyright (C) 2023 SteamWar.de-Serverteam
  -
  -   This program is free software: you can redistribute it and/or modify
  -   it under the terms of the GNU Affero General Public License as published by
  -   the Free Software Foundation, either version 3 of the License, or
  -   (at your option) any later version.
  -
  -   This program is distributed in the hope that it will be useful,
  -   but WITHOUT ANY WARRANTY; without even the implied warranty of
  -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  -   GNU Affero General Public License for more details.
  -
  -   You should have received a copy of the GNU Affero General Public License
  -   along with this program.  If not, see <https://www.gnu.org/licenses/>.
  -->

<script lang="ts">
    import {astroI18n, t} from "astro-i18n";
    import {CheckSolid, XCircleOutline} from "flowbite-svelte-icons";
    import type {SchematicInfo} from "@type/schem.ts";
    import {createEventDispatcher} from "svelte";
    import type {Player} from "@type/data.ts";
    import dayjs from "dayjs";
    import SWModal from "@components/styled/SWModal.svelte";

    const dispatch = createEventDispatcher();

  interface Props {
    info: SchematicInfo;
    user: Player;
  }

  let { info, user }: Props = $props();
</script>

<SWModal title={info.schem.name} open on:close={() => dispatch("reset")}>
    <p>{t("dashboard.schematic.info.path", {path: info.path})}</p>
    <p class="flex !mt-0">
        {t("dashboard.schematic.info.replaceColor")}
        {#if info.schem.replaceColor}
            <CheckSolid class="text-green-500 ml-2" />
        {:else}
            <XCircleOutline class="text-red-500 ml-2" />
        {/if}
    </p>
    <p class="flex !mt-0">
        {t("dashboard.schematic.info.allowReplay")}
        {#if info.schem.allowReplay}
            <CheckSolid class="text-green-500 ml-2" />
        {:else}
            <XCircleOutline class="text-red-500 ml-2" />
        {/if}
    </p>
    <p class="!mt-0">{t("dashboard.schematic.info.type", {type: info.schem.type ?? t("dashboard.schematic.dir")})}</p>
    <p class="!mt-0">{t("dashboard.schematic.info.updated", {updated: new Intl.DateTimeFormat(astroI18n.locale, {
            hour: "2-digit",
            minute: "2-digit",
            second: "2-digit",
            day: "2-digit",
            month: "2-digit",
            year: "numeric"
        }).format(dayjs(info.schem.lastUpdate).utc(false).toDate())})}</p>
    <p class="!mt-0">{t("dashboard.schematic.info.item", {item: info.schem.item ?? (info.schem.type == null ? "CHEST" : "CAULDRON_ITEM")})}</p>
    {#if info.members.length !== 0}
        <p class="!mt-0">{t("dashboard.schematic.info.members", {members: info.members.map(value => value.name).join(", ")})}</p>
    {/if}
    {#snippet footer()}
    <button  class="btn ml-auto" onclick={() => dispatch("reset")}>{t("dashboard.schematic.info.btn.close")}</button>
  {/snippet}
</SWModal>