<script setup>
defineProps({
    cv: {
        type: Object,
        required: true,
    },
    cvInfo: {
        type: Object,
        required: true,
    },
});
</script>

<template>
    <InertiaHead title="Szczegóły CV" />
    <div class="p-4">
        <header class="flex justify-between items-center pb-4">
            <div class="flex items-center gap-2">
                <InertiaLink
                    as="button"
                    href="/dashboard/cv"
                    class="px-2 text-xl text-gray-700 hover:text-black"
                    title="Wróć do listy CV"><FontAwesomeIcon :icon="['fas', 'caret-left']" /></InertiaLink>
                <h1 class="text-3xl font-roboto font-light">Szczegóły CV</h1>
            </div>
            <div class="flex gap-2">
                <a
                    class="px-2 py-1 text-blue-600 hover:text-blue-800"
                    :href="`https://cv.kamilcraft.com/show/${cv.token}`"
                    target="_blank"
                    rel="noopener noreferrer"
                    title="Przekieruj do CV"><FontAwesomeIcon :icon="['fas', 'arrow-up-right-from-square']" /></a>
                <InertiaLink
                    as="button"
                    :href="`/dashboard/cv/${cv.token}/edit`"
                    class="flex items-center gap-2 px-2 py-1 text-lime-600 hover:text-white hover:bg-lime-600 rounded-md"
                    title="Usuń CV"
                    ><FontAwesomeIcon :icon="['fas', 'pen-to-square']" />Edytuj</InertiaLink>
                <InertiaLink
                    as="button"
                    :href="`/dashboard/cv/${cv.token}/delete`"
                    class="flex items-center gap-2 px-2 py-1 text-red-600 hover:text-white hover:bg-red-600 rounded-md"
                    title="Usuń CV"
                    ><FontAwesomeIcon :icon="['fas', 'trash']" />Usuń</InertiaLink>
            </div>
        </header>
        <div class="mb-4">
            <header>
                <h2 class="text-2xl font-roboto font-light pb-3">Podstawowe informacje</h2>
            </header>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <div>
                    <div class="text-gray-500 pb-0.5">Token</div>
                    <p class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white whitespace-nowrap overflow-hidden overflow-ellipsis">{{ cv.token }}</p>
                </div>
                <div>
                    <div class="text-gray-500 pb-0.5">Firma</div>
                    <p class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">{{ cv.recipient }}</p>
                </div>
                <div>
                    <div class="text-gray-500 pb-0.5">Stanowisko</div>
                    <p class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">{{ cv.position ?? '[Wartość domyślna]' }}</p>
                </div>
                <div>
                    <div class="text-gray-500 pb-0.5">E-mail</div>
                    <p class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">{{ cv.email }}</p>
                </div>
                <div>
                    <div class="text-gray-500 pb-0.5">Numer telefonu</div>
                    <p class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">{{ cv.phone.formattedNumber }}</p>
                </div>
                <div>
                    <div class="text-gray-500 pb-0.5">Lokalizacje</div>
                    <p class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">{{ cv.locations.join(' / ') }}</p>
                </div>
                <div>
                    <div class="text-gray-500 pb-0.5">Zachowane wyświetlenia</div>
                    <p class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">{{ cv.views }}</p>
                </div>
                <div>
                    <div class="text-gray-500 pb-0.5">Łączne wyświetlenia</div>
                    <p class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">{{ cv.registeredViews }}</p>
                </div>
            </div>
        </div>
        <div class="mb-4">
            <header>
                <h2 class="text-2xl font-roboto font-light pb-3">Opisy</h2>
            </header>
            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                <div>
                    <div class="text-gray-500 pb-0.5">Misja</div>
                    <div v-if="cv.mission.length > 0 && cv.mission[0] !== ''" class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">
                        <p
                            v-for="(mission, key) in cv.mission"
                            :key="key">{{ mission }}</p>
                    </div>
                    <p v-else class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">[Wartość domyślna]</p>
                </div>
                <div>
                    <div class="text-gray-500 pb-0.5">RODO</div>
                    <p class="w-full min-w-full max-w-full px-2.5 py-2 border-b-2 rounded-md bg-white">{{ cv.rodo ?? '[Wartość domyślna]' }}</p>
                </div>
            </div>
        </div>
        <div>
            <header>
                <h2 class="text-2xl font-roboto font-light pb-3">Lista wejść</h2>
            </header>
            <ul v-if="cvInfo.data.length" class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-2">
                <li
                    v-for="(info, key) in cvInfo.data"
                    :key="key"
                    class="flex flex-col px-3 py-2 bg-white rounded-md">
                    <span>#{{ info.id }} {{ info.ip }}</span>
                    <span class="text-xs">{{ info.created_at }}</span>
                </li>
            </ul>
            <div v-else>
                Brak wyświetleń
            </div>
        </div>
    </div>
</template>
