<script setup>
/*
 * MelissaCard
 * --------------------------------------------------
 * Card glass do dashboard Melissa.
 *
 * Dois variants:
 *  - default: header (ícone+título+badge opcional) + slot de conteúdo
 *             + botão redondo "+" centralizado na borda inferior que
 *             emite `open` (parent decide o que fazer)
 *  - add:     placeholder tracejado, meia largura, com "+" centralizado;
 *             emite `add` ao clicar
 *
 * Largura é fixa (não estica) — o layout flex no parent define o número
 * de cards visíveis conforme o tamanho da tela.
 */
defineProps({
    variant: {
        type: String,
        default: 'default',
        validator: (v) => ['default', 'add'].includes(v)
    },
    icon: { type: String, default: '' },        // ex.: 'pi pi-user'
    iconColor: { type: String, default: '' },   // classe Tailwind ex.: 'text-emerald-300'
    title: { type: String, default: '' },
    badge: { type: [String, Number, null], default: null },
    badgeColor: { type: String, default: 'bg-red-500/80' }, // classe Tailwind
    actionTitle: { type: String, default: 'Abrir' }
});

defineEmits(['open', 'add']);
</script>

<template>
    <article v-if="variant === 'default'" class="mc-card">
        <div class="mc-card__head">
            <span v-if="icon" class="mc-card__icon">
                <i :class="[icon, iconColor]" />
            </span>
            <span class="mc-card__title">{{ title }}</span>
            <span v-if="badge !== null && badge !== ''" class="mc-card__badge" :class="badgeColor">
                {{ badge }}
            </span>
        </div>
        <div class="mc-card__body">
            <slot />
        </div>
        <button class="mc-card__go" :title="actionTitle" @click="$emit('open')">
            <i class="pi pi-plus text-xs" />
        </button>
    </article>

    <button v-else class="mc-card-add" :title="actionTitle" @click="$emit('add')">
        <i class="pi pi-plus" />
    </button>
</template>

<style scoped>
/* ─── Card padrão ──────────────────────────────────────────── */
.mc-card {
    position: relative; /* ancora o botão "+" */
    flex-shrink: 0;
    width: 210px;
    background: var(--m-bg-soft);
    backdrop-filter: blur(20px) saturate(140%);
    -webkit-backdrop-filter: blur(20px) saturate(140%);
    border: 1px solid var(--m-border);
    border-radius: 14px;
    padding: 14px 16px;
    transition: background-color 160ms ease, transform 160ms ease;
}
.mc-card:hover {
    background: var(--m-bg-soft-hover);
    transform: translateY(-2px);
}

.mc-card__head {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--m-text);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.01em;
}
.mc-card__icon {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: var(--m-bg-soft-hover);
    backdrop-filter: blur(16px) saturate(160%);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    border: 1px solid var(--m-border-strong);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
    flex-shrink: 0;
}
.mc-card__title {
    /* deixa o título absorver o espaço entre ícone e badge */
    flex: 1;
    min-width: 0;
}
.mc-card__badge {
    /* margin-left: auto não precisa mais (title flex:1 empurra o badge) */
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 9999px;
    color: white;
    font-weight: 600;
    flex-shrink: 0;
}

.mc-card__body {
    margin-top: 12px;
    color: white;
}

/* Botão "+" centralizado na borda inferior do card */
.mc-card__go {
    position: absolute;
    bottom: -16px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 32px;
    border-radius: 12px;
    background: rgba(30, 30, 45, 0.85);
    backdrop-filter: blur(20px) saturate(160%);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    border: 1px solid var(--m-border-strong);
    color: white;
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
    transition: background-color 180ms ease, transform 180ms ease, border-color 180ms ease;
    z-index: 5;
}
.mc-card__go:hover {
    background: var(--m-bg-soft-hover);
    border-color: var(--m-border-strong);
    transform: translateX(-50%) scale(1.08);
}
.mc-card__go:active {
    transform: translateX(-50%) scale(0.96);
}

/* ─── Card "Adicionar" (tracejado, meia largura) ──────────── */
/* Sem align-self aqui — o parent (cards-shell) decide se estica
   (linha única) ou mantém intrínseco (wrap). */
.mc-card-add {
    flex-shrink: 0;
    width: 130px; /* metade do card padrão */
    min-height: 100px;
    border: 1.5px dashed var(--m-border-strong);
    border-radius: 14px;
    background: var(--m-bg-soft);
    color: var(--m-text-muted);
    display: grid;
    place-items: center;
    cursor: pointer;
    font-size: 1.5rem;
    transition: all 200ms ease;
}
.mc-card-add:hover {
    background: var(--m-bg-soft);
    border-color: var(--m-text-muted);
    color: white;
    transform: translateY(-2px);
}
.mc-card-add:active {
    transform: translateY(0);
}
</style>
