<script>
    import {getContext} from "svelte";
    import Icon from "../common/Icon.svelte";
    import {previewTitle} from "./Preview";

    const channel = getContext("channel");
    export let schema;
    export let graph;
    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>

<h3 class="header-normal mt-5 mb-0">
    <a
        class="text-muted d-block text-decoration-none fs-6 mb-1"
        href="{channel.lucentUrl}/content/{schema.name}"
    >{schema.label.toUpperCase()}</a
    >

    <span class="text-dark d-block">
        {#if !isCreateMode}
            {previewTitle(channel.schemas, record, graph)}
        {:else}
            New Record
        {/if}
    </span>
    {#if !isCreateMode}
        <div class="dropdown d-inline-block">
            <button
                class="btn btn-link btn-sm"
                type="button"
                data-bs-toggle="dropdown"
                aria-expanded="false"
            >
                <Icon icon="ellipsis"/>
            </button>
            <div class="dropdown-menu">

                <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
                >
            </div>
        </div>
    {/if}
</h3>
