<script>
    import {getContext} from "svelte";
    import Icon from "../../common/Icon.svelte";
    import Dropdown from "../../common/Dropdown.svelte";
    import StatusSelect from "./StatusSelect.svelte";

    const channel = getContext("channel");
    export let schema;
    export let record;
    export let isCreateMode;
    export let activeContentTab;

    function clone(e) {
        e.preventDefault();
        axios.post(channel.lucentUrl + "/records/clone/" + record.id).then(response => {
            window.location = channel.lucentUrl + "/records/" + response.data.id;
        }).catch(error => {

        });
    }
</script>



<div style="display: flex;align-items: center; gap:10px;">
    {#if !isCreateMode}
        <Dropdown >
            <div slot="button">
                <Icon icon="ellipsis"/>
            </div>
            <h6 class="dropdown-header">Record Actions</h6>
            <a
                    class="dropdown-item"
                    href="{channel.lucentUrl}/records/new?schema={schema.name}"
            >Create new</a
            >
            {#if !isCreateMode}
                <a
                        class="dropdown-item"
                        on:click={clone}
                        href={channel.lucentUrl}
                >
                    Clone
                </a>
            {/if}
            <a
                    on:click|preventDefault={(e) =>
                        (activeContentTab = "_info")}
                    class="dropdown-item"
                    href="{channel.lucentUrl}">Revisions</a
            >
        </Dropdown>
    {/if}

<StatusSelect bind:status={record.status} {record}></StatusSelect>
</div>