<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
    import * as tr from "@generated/ftl";

    import ButtonGroup from "$lib/components/ButtonGroup.svelte";
    import ButtonGroupItem, {
        createProps,
        setSlotHostContext,
        updatePropsList,
    } from "$lib/components/ButtonGroupItem.svelte";
    import DynamicallySlottable from "$lib/components/DynamicallySlottable.svelte";
    import Icon from "$lib/components/Icon.svelte";
    import IconButton from "$lib/components/IconButton.svelte";
    import { mdiTableRefresh, mdiViewDashboard } from "$lib/components/icons";

    import {
        ioImageLoadedStore,
        ioMaskEditorVisible,
    } from "../../routes/image-occlusion/store";

    export let api = {};
</script>

<ButtonGroup>
    <DynamicallySlottable
        slotHost={ButtonGroupItem}
        {createProps}
        {updatePropsList}
        {setSlotHostContext}
        {api}
    >
        <ButtonGroupItem>
            <IconButton
                id="io-mask-btn"
                class={$ioMaskEditorVisible ? "active-io-btn" : ""}
                on:click={() => {
                    $ioMaskEditorVisible = !$ioMaskEditorVisible;
                }}
                tooltip={tr.editingImageOcclusionToggleMaskEditor()}
            >
                <Icon icon={mdiViewDashboard} />
            </IconButton>
        </ButtonGroupItem>
        <ButtonGroupItem>
            <IconButton
                id="io-reset-btn"
                disabled={!$ioImageLoadedStore}
                on:click={() => {
                    if (confirm(tr.editingImageOcclusionConfirmReset())) {
                        globalThis.resetIOImageLoaded();
                    } else {
                        return;
                    }
                }}
                tooltip={tr.editingImageOcclusionReset()}
            >
                <Icon icon={mdiTableRefresh} />
            </IconButton>
        </ButtonGroupItem>
    </DynamicallySlottable>
</ButtonGroup>

<style>
    :global(.active-io-btn) {
        background: var(--button-primary-bg) !important;
        color: white !important;
    }
</style>
