<script setup>
import { ref, watch } from 'vue';

const $props = defineProps({
    id: { type: Number, default: null },
    isSelected: { type: Boolean, default: false },
    title: { type: String, default: null },
});
const checkSelect = ref(false);

watch(
    () => $props.isSelected,
    (value, prevValue) => {
        checkSelect.value = value;
    }
);
</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">
                        <div class="title text-primary text-weight-bold text-h5">
                            {{ $props.title }}
                        </div>
                        <QChip outline color="grey" size="sm">
                            ID: {{ $props.id }}
                        </QChip>
                    </div>
                    <QCheckbox v-model="checkSelect" />
                </div>
            </slot>
            <div class="card-list-body">
                <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;
}

.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>
