<script lang="ts">
    import { createEventDispatcher } from 'svelte';

    const dispatch = createEventDispatcher();

    function onClick() {
        dispatch('click');
    }
</script>

<style>
    .sliding-card {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        flex-wrap: wrap;
        flex: 2 1 15em;
        padding: 0.5em 2.5em 2em 2.5em;
        background: var(--bg-secondary);
        border-radius: 0.5em;
        scroll-snap-align: start;
        transition: all 0.3s ease-in-out;
        overflow: hidden;
        position: relative;
    }

    .sliding-card:hover {
        box-shadow: .5em .5em .5em var(--hover);
    }

    .sliding-card .sliding-card-header :global(div) {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 0em;
    }

    .content-wrapper {
        position: relative;
        width: 100%;
        overflow: hidden; /* Ensure smooth sliding */
    }

    .sliding-card-content {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        max-width: 100%;
        flex-grow: 1;
        z-index: 1; /* Keep it below the sliding content */
    }

    .sliding-content {
        position: absolute; /* Now it sits on top */
        top: 0;
        left: 0;
        width: 100%;
        height: 100%; /* Cover entire content */
        background: var(--bg-secondary);
        transform: translateY(100%); /* Start hidden */
        transition: transform 0.3s ease-in-out;
        z-index: 2; /* Now above main content */
    }

    .sliding-card:hover .sliding-content {
        transform: translateY(0);
    }

    .sliding-card .sliding-card-footer :global(div){
        margin-bottom: 1em;
        display: flex;
        gap: 1em;
        max-width: 100%;
        justify-content: space-between;
    }
</style>

<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div class="sliding-card" on:click={onClick}>
    <div class="sliding-card-header">
        <slot name="header"></slot>
    </div>
    <hr />
    
    <!-- Wrapper to stack sliding-card-content and sliding-content -->
    <div class="content-wrapper">
        <div class="sliding-card-content">
            <slot name="content"></slot>
        </div>
        <div class="sliding-content">
            <slot name="sliding-content"></slot>
        </div>
    </div>

    <hr class="not-required"/>
    <div class="sliding-card-footer">
        <slot name="footer"></slot>
    </div>
</div>