<script lang="ts">
    import { spaLink } from "../../actions"
    import MedialibFile from "./MedialibFile.svelte"

    export let links: BlockLink[] = []

    const resolveClass = (style?: string) => {
        if (!style) return "cta"
        return `cta btn-${style}`
    }
</script>

{#each links || [] as link (link.text)}
    {#if link.url}
        <a
            use:spaLink
            href={link.url}
            class={resolveClass(link.style)}
            target={link.target || "_self"}
        >
            {link.text}
        </a>
    {:else if link.file}
        <MedialibFile id={link.file} let:src>
            <a
                href={src}
                class={resolveClass(link.style)}
                target={link.target || "_blank"}
            >
                {link.text}
            </a>
        </MedialibFile>
    {/if}
{/each}
