<template>
    <TableComponent :loading="secrets == null" v-for="secrets in [repo.get().value]">
        <div class="resource-container secret-container">
            <div class="header">
                <div class="left-center">
                    <p>Name</p>
                    <UiButton v-if="false" icon="add" class="extra-small" reverse @click="() => secretAddComponent.open()">Add</UiButton>
                </div>
                <p>Namespace</p>
                <p>Age</p>
                <p>Type</p>
                <p>Entries</p>
                <p>Actions</p>
            </div>
            <SecretComponent v-for="(secret, index) in secrets" :secret="secret" class="resource" :class="{ even: index % 2 }"></SecretComponent>
        </div>
    </TableComponent>
</template>

<script setup lang="ts">
import { ResourceRepo } from '~/classes/repo/ResourceRepo';
import type { Secret } from '~/classes/Secret';
import SecretComponent from '~/components/secrets/SecretComponent.vue';

const repo = ResourceRepo.init<Secret>();

onMounted(() => {
    repo.listen("secrets");
});
onUnmounted(() => {
    repo.clear();
});

const secretAddComponent = ref();
</script>

<style scoped>
.secret-container {
    display: grid;
    grid-template-columns: auto auto auto auto 1fr auto;
}
</style>