<script lang="typescript">
    import type { Buttons } from "./types";

    export let buttons: Buttons;
</script>

<style lang="scss">
    ul {
        display: flex;
        /* flex-flow: nowrap for a scrollable toolbar */
        flex-flow: wrap;
        overflow: scroll;

        padding-inline-start: 0;
        margin-bottom: 0;

        & :global(button) {
            margin-left: -1px;
        }
    }

    li {
        display: inline-block;
        margin-bottom: 2px;

        &:nth-child(1) {
            margin-left: 0.25rem;

            & > :global(button) {
                border-top-left-radius: 0.25rem;
                border-bottom-left-radius: 0.25rem;
            }
        }

        &:nth-last-child(1) {
            margin-right: 0.25rem;

            & > :global(button) {
                border-top-right-radius: 0.25rem;
                border-bottom-right-radius: 0.25rem;
            }
        }
    }
</style>

<ul>
    {#each buttons as button}
        <li>
            {#if Array.isArray(button)}
                <svelte:self buttons={button} />
            {:else}
                <svelte:component this={button.component} {...button} />
            {/if}
        </li>
    {/each}
</ul>
