<script>
    import Avatar from "../account/Avatar.svelte";
    import {fly} from "svelte/transition";
    import {createEventDispatcher} from "svelte";

    const dispatch = createEventDispatcher();
    export let member;
    export let roles;

    function update(e, newRole) {
        e.preventDefault();
        dispatch("update", {
            user: member.id,
            role: newRole,
        });
    }


</script>

<div
    transition:fly={{ duration: 200 }}
    class="d-flex justify-content-between align-items-center mb-3 "
>
    <div class="d-flex align-items-center status-{member.role}">
        <Avatar name={member.name ?? "" } side="32"/>
        <div class="ms-3 ">
            <div>
                <span class="fs-5">
                            {member.name}
                        </span>
            </div>
            {member.email}
        </div>
    </div>
    <div>
        <div class="dropdown dropdown-center">
            <button
                class="  dropdown-toggle btn btn-light"
                type="button"
                data-bs-toggle="dropdown"
                aria-expanded="false"
            >
                {member.role}
            </button>
            <div class="dropdown-menu">
                {#each roles as role}
                    {#if member.role !== role}
                        <button
                            class="dropdown-item"
                            on:click={(e) => update(e,role)}
                        >
                            Convert to {role}
                        </button>
                    {/if}
                {/each}

            </div>
        </div>

    </div>
</div>
<style>
    .status-removed {
        opacity: .5;
    }


</style>
