<script lang="ts">
    import { generalInfo } from "../../store"
    import { apiBaseURL } from "../../config"

    export let id: string = null
    export let cssClass: string = ""
</script>

{#if id}
    {#each $generalInfo?.media?.mediaFiles || [] as mediaFile}
        {#if mediaFile.id === id && mediaFile.file}
            {#if mediaFile.file.src.includes(";base64,")}
                <img
                    src="{mediaFile.file.src}"
                    alt="{mediaFile.alternateText ? mediaFile.alternateText + ' - ' : ''}"
                    class="{cssClass}"
                />
            {:else}
                <img
                    src="{`${apiBaseURL}general/${$generalInfo?.id}/${mediaFile.file.src}?filter=l`}"
                    alt="{mediaFile.alternateText ? mediaFile.alternateText : mediaFile.file.path}"
                    class="{cssClass}"
                />
            {/if}
        {/if}
    {/each}
{/if}
