<script setup>
    import { onMounted, toRef, watch } from 'vue';
    import { initFlowbite } from 'flowbite';

    onMounted(() => {
        initFlowbite();
    });

    const props = defineProps({
        block: { type: Object, required: true }
    });

    const emit = defineEmits(['update:block']);
    const local = toRef(props, 'block');

    watch(local, (val) => emit('update:block', val), { deep: true });
	
	const sponsors = [
		{ name: 'Greenleaf Organics A/S', type: 'Sponsor' },
		{ name: 'Futuretech Robotics AS', type: 'Sponsor' },
		{ name: 'EcoInnovate Solutions AS', type: 'Sponsor' },
		{ name: 'Nordic Nest A/S', type: 'Sponsor' },
		{ name: 'Bright Mind AS', type: 'Sponsor' },
		{ name: 'Globetrotter Travel Co AS', type: 'Samarbeidspartner' },
		{ name: 'Aurora Health & Wellness A/S', type: 'Samarbeidspartner' },
		{ name: 'Artisinal Brews AS', type: 'Samarbeidspartner' }
	];
</script>

<template>
    <section class="relative block w-full h-screen overflow-hidden">
        <div class="absolute inset-0 bg-cover" :style="{ backgroundImage: `url('${block.image}')` }"></div>
        <div class="absolute inset-0 bg-black opacity-80"></div>
        <div class="absolute p-12 w-full overflow-auto" style="top: 0; bottom: 0;">
            <div class="flex-row justify-center items-center">
                <h1 class="text-center text-white font-arctic text-2xl md:text-4xl">{{ block.title || 'Tittel' }}</h1>
            </div>

            <div class="mx-auto max-w-[1280px]">
                <div class="col-6 d-flex flex-column sponsor-container">

                    <p v-if="block.showtext" class="text-gray-200 mt-6">
                        {{ block.text || 'Intro tekst' }}
                    </p>

                    <div class="grid gap-4 grid-cols-1 md:grid-cols-2 lg:grid-cols-3 p-4 font-arctic text-xl md:text-2xl">
                        <!-- Sponsoroppføring -->
                         <template v-for="(sponsor, index) in sponsors" :key="index">
                            <a v-if="sponsor.type == 'Sponsor'" href="#" class="anchor sponsor-label text-gray-500 hover:text-gray-400 no-underline hover:underline">
                                <span>{{ sponsor.name }}</span>
                            </a>
                         </template>
                    </div>

                    <p v-if="block.showpartnertext" class="text-gray-200 mt-2">
                        {{ block.partnertext || 'Partner intro tekst' }}
                    </p>

                    <div class="grid gap-4 grid-cols-1 md:grid-cols-2 lg:grid-cols-3 p-4 font-arctic text-xl md:text-2xl">
                        <!-- Partneroppføring -->
                         <template v-for="(partner, index) in sponsors" :key="index" href="#">
                            <a v-if="partner.type == 'Samarbeidspartner'" class="anchor sponsor-label text-gray-500 hover:text-gray-400 no-underline hover:underline">
                                <span>{{ partner.name }}</span>
                            </a>
                         </template>
                    </div>                    
                </div>
            </div>
        </div>
    </section>
</template>