<script setup>
import { onMounted, ref } from 'vue';
import { SetupHandle, SetSize, ResetPosition, Top, CreateChildWindow, GetFirstWindowId } from '@/services/Windows';

import WindowHandle from './partials/WindowHandle.vue';
import VersionRender from '../partials/VersionRender.vue';
import EditUserPartial from '../partials/EditUserPartial.vue';
import CampaignEntry from '../partials/CampaignEntry.vue';
import Server from '~/services/Server';

const handle = ref(null);
const wrapper = ref(null);

const props = defineProps(['data']);
const data = props.data;

const campaings = ref([]);

let id = data.id;

function CreateCampaignWindow(){
    CreateChildWindow(GetFirstWindowId('main_menu'), 'create_campaign');
}

function RefreshCampaigns(){
    Server().get('/campaign/list').then((response) => {
        if(response.data.status !== "ok") return;
        response.data.campaigns.forEach((camp) => {
            campaings.value.push(camp);
        });
    });
}

onMounted(() => {
    Top(wrapper);
    SetupHandle(id, handle);
    SetSize(id, {width: 880, height: 760});
    ResetPosition(id, "center");

    RefreshCampaigns();
});
</script>


<template>
    <div class="window-wrapper" :id="'window-wrapper-' + id" ref="wrapper">
        <WindowHandle :window="id" ref="handle"></WindowHandle>

        <div class="two-column">
            <div class="vert-expand secondary">
                <div class="image-container">
                    <img alt="Dragonroll logo" src="/img/logo-splash.png" draggable="false" width="100%">
                </div>
                <div class="patch-notes-container">
                    <h1>Welcome to dragonroll!</h1>
                    <h2>Version 0.1</h2>
                    <p>This is totally under construction. This is a review of how the patch notes will be displayed.</p>
                    <p>There is also a lot of heavy development here.</p>
                </div>
                <VersionRender></VersionRender>
            </div>

            <div class="vert-expand" style="max-width: 450px;">
                <EditUserPartial></EditUserPartial>
                <!-- Body -->
                <div class="vert-expand">
                    <div class="vert top">
                        <h1>{{ $t("main-menu.main-menu")}}</h1>

                        <!-- HERE -->
                        <div class="campaign-list">
                            <CampaignEntry v-for="camp in campaings" :key="camp._id" :data="camp"></CampaignEntry>
                        </div>
                    </div>
                    
                    <div class="vert bot">
                        <div class="button-container">
                            <button class="btn-primary button-expand sound-click" v-on:click="CreateCampaignWindow" ref="campaignButton">{{ $t("main-menu.create-campaign") }}</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>


<style scoped>
h1 {
    margin-top: 20px;
    font-family: MrEavesRemake;
    text-align: center;
}

h2, h3 {
    font-family: MrEavesRemake;
}

.patch-notes-container {
    margin: 10px;
    padding: 10px;
    border-radius: 5px;
    flex-grow: 1;
}

.two-column {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%;
}

.secondary {
    background-color: var(--color-background-soft);
}

.expand {
    width: 100%;
    
    display: flex;
    flex-direction: row;

    > * {
        flex-grow: 1;
    }
}

.vert-expand {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex-grow: 1;
    width: 100%;
}


.button-expand {
    width: 100%;
}

.button-container {
    display: flex;
    margin: 20px;

    flex-direction: column;
}

p {
  user-select: none;
}

.window-wrapper {
    display: flex;
    align-items: center;
    user-select: none;
}

.splash-image {
    width: 600px;
    height: 250px;
    user-select: none;
}
</style>


