<script lang="ts">
    import { Duration } from 'luxon';

    import type { CostType } from "../types";

    export let cost: CostType;
    export let duration: number | null = null;


    $: prettyDuration = (duration !== null) ? Duration.fromMillis(duration * 1000).toFormat(`mm:ss:SS`) : '';
</script>

<div class="cost">
    <div>
        <img src="/img/icons/wood.png" alt="Wood" />
        { cost.wood }
    </div>
    <div>
        <img src="/img/icons/stone.png" alt="Stone" />
        { cost.stone }
    </div>
    <div>
        <img src="/img/icons/iron.png" alt="Iron" />
        { cost.iron }
    </div>
    <div>
        <img src="/img/icons/food.png" alt="Food" />
        { cost.food }
    </div>
    { #if duration !== null }
    <div>
        <img src="/img/icons/time.png" alt="Duration">
        { prettyDuration }
    </div>
    { /if }
</div>

<style>
    .cost {
        align-items: center;
        display: flex;
        gap: 1em;
        justify-content: center;
    }

    .cost div {
        display: flex;
        align-items: center;
        gap: 0.2em;
    }
</style>
