<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="typescript">
    import { onMount, createEventDispatcher, getContext } from "svelte";
    import { nightModeKey } from "components/contextKeys";

    export let id: string | undefined = undefined;
    let className = "";
    export { className as class };

    export let selected = false;
    export let active = false;

    const nightMode = getContext<boolean>(nightModeKey);
    const dispatch = createEventDispatcher();

    let buttonRef: HTMLButtonElement;

    onMount(() => dispatch("mount", { button: buttonRef }));
</script>

<button
    {id}
    tabindex="-1"
    bind:this={buttonRef}
    class={`btn ${className}`}
    class:btn-day={!nightMode}
    class:btn-night={nightMode}
    class:selected
    class:active
    on:mouseup
    on:mouseenter
    on:mousedown|preventDefault
>
    <slot />
</button>

<style lang="scss">
    @use 'ts/sass/button_mixins' as button;

    button {
        display: flex;
        justify-content: space-between;

        font-size: calc(var(--buttons-size) / 2.3);

        background: none;
        box-shadow: none !important;
        border: none;

        &.active {
            background-color: button.$focus-color;
            color: white;
        }
    }

    /* reset global CSS from buttons.scss */
    :global(.nightMode) button:hover {
        background-color: inherit;
    }

    /* extra specificity bc of global CSS reset above */
    button.btn-day {
        color: black;

        &.selected {
            background-color: #e9ecef;
            border-color: #e9ecef;
        }
    }

    button.btn-night {
        color: white;

        &.selected {
            @include button.btn-night-base;
        }
    }
</style>
