<script setup>
import { useI18n } from 'vue-i18n';

const { t } = useI18n();

const $props = defineProps({
    element: { type: Object, default: null },
    id: { type: Number, default: null },
    isSelected: { type: Boolean, default: false },
    title: { type: String, default: null },
    showCheckbox: { type: Boolean, default: false },
    hasInfoIcons: { type: Boolean, default: false },
});

const emit = defineEmits(['toggleCardCheck']);

const toggleCardCheck = (item) => {
    emit('toggleCardCheck', item);
};
</script>

<template>
    <QCard class="card q-mb-md cursor-pointer q-hoverable bg-white-7 q-pa-lg">
        <div>
            <slot name="title">
                <div class="flex justify-between">
                    <div class="flex items-center">
                        <div class="title text-primary text-weight-bold text-h5">
                            {{ $props.title }}
                        </div>
                        <QChip class="q-chip-color" outline size="sm">
                            {{ t('ID') }}: {{ $props.id }}
                        </QChip>
                    </div>
                    <QCheckbox
                        v-if="showCheckbox"
                        :model-value="isSelected"
                        @click="toggleCardCheck($props.element)"
                    />
                </div>
            </slot>
            <div class="card-list-body">
                <div v-if="hasInfoIcons" class="column q-mr-md q-gutter-y-xs">
                    <slot name="info-icons" />
                </div>
                <div class="list-items row flex-wrap-wrap">
                    <slot name="list-items" />
                </div>

                <div class="actions">
                    <slot name="actions" />
                </div>
            </div>
        </div>
    </QCard>
</template>

<style lang="scss">
.title {
    margin-right: 25px;
}

.q-chip-color {
    color: var(--vn-label);
}

.card-list-body {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    .vn-label-value {
        display: flex;
        justify-content: flex-start;
        gap: 2%;
        width: 50%;
        .label {
            width: 35%;
            color: var(--vn-label);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .value {
            width: 65%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
    }
    .actions {
        display: flex;
        flex-direction: column;
        justify-content: center;
        width: 25%;
    }
}

@media (max-width: $breakpoint-xs) {
    .card-list-body {
        flex-wrap: wrap;
        justify-content: center;
        .vn-label-value {
            width: 100%;
        }
        .actions {
            width: 100%;
            margin-top: 15px;
            padding: 0 15%;
            justify-content: center;
        }
    }
}
</style>

<style lang="scss" scoped>
.card {
    transition: background-color 0.2s;
}
.card:hover {
    background-color: var(--vn-gray);
}
.list-items {
    width: 75%;
}
</style>

<i18n>
    es:
        ID: ID
</i18n>
