<script>
    export let field;
    export let value;
    export let search;

    function select(e, option) {
        e.preventDefault();
        value = option;
        search = "";
    }


</script>

{#if field.selectOptions}
    {#if Array.isArray(field.selectOptions)}
        {#each field.selectOptions as suggestion (suggestion)}
            <div
                    on:click={(e) => select(e, suggestion)}
                    on:keypress={(e) => select(e, suggestion)}
            >
            <span class="dropdown-item">
               {suggestion}
            </span>
            </div>
        {/each}
    {:else}
        {#each Object.entries(field.selectOptions) as [k, v] (k)}
            <div
                    on:click={(e) => select(e, k)}
                    on:keypress={(e) => select(e, k)}
            >
            <span class="dropdown-item">
               {v}
            </span>
            </div>
        {/each}
    {/if}
{/if}
