<template>
    <div>
        <p class="grid-element pointer" v-if="pod.metadata" @click="() => showViewPopup = true">{{ pod.metadata.name }}</p>
        <p class="grid-element" v-if="pod.metadata">{{ pod.metadata.namespace }}</p>
        <p class="grid-element no-wrap" v-if="pod.metadata">{{ calcAge(pod.metadata.creationTimestamp) }}</p>
        <p class="grid-element" v-if="pod.spec">{{ pod.spec.nodeName }}</p>
        <p class="grid-element">{{ pod.spec.containers.length }}</p>
        <p class="grid-element">{{ pod.status.containerStatuses.map(s => s.restartCount).reduce((total, value) => total = total + value) }}</p>
        <div class="grid-element">
            <PhaseComponent v-if="pod.status" :phase="pod.status.phase"></PhaseComponent>
        </div>
        <div class="grid-element action-buttons">
            <ActionButton @click="showLogPopup = true">text_snippet</ActionButton>
            <ActionButton @click="showDeletePopup = true">delete</ActionButton>
        </div>
        <PodDeletePopup v-if="showDeletePopup" :pod="pod" @close="showDeletePopup = false"></PodDeletePopup>
        <PodLogPopup v-if="showLogPopup" :pod="pod" @close="showLogPopup = false"></PodLogPopup>
        <PodViewPopup v-if="showViewPopup" :pod="pod" @close="showViewPopup = false"></PodViewPopup>
    </div>
</template>

<script setup lang="ts">
import type { Pod } from '~/classes/Pod';
import { calcAge } from '~/classes/Pod';
import PodDeletePopup from './view/PodDeletePopup.vue';
import PodLogPopup from "~/components/inspect/logs/PodLogPopup.vue";

defineProps<{
    pod: Pod
}>();

const showDeletePopup = ref(false);
const showLogPopup = ref(false);
const showViewPopup = ref(false);
</script>