<template>
    <div class="project">
        <div class="project-header">
            <div class="project-title">
                <h2>{{ projectName }}</h2>
                <p>Projet mis le: {{ creationDate }}</p>
            </div>
            <div class="project-buttons">
                <button id="accept" @click="acceptProject">Accepter</button>
                <button id="refus" @click="refuseProject">Refuser</button>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { defineProps } from "vue";
import { addNewMessage, color } from "@/services/popupDisplayer";
import { decidePendingProject } from "@/services/Apis/Admin";
import ProjectDecision from "@/ApiClasses/ProjectDecision";

const props = defineProps<{
    projectId?: number;
    projectName: string;
    creationDate: string;
    adminId?: number;
}>();

const sendDecision = (isAccepted: boolean) => {
    const decision = new ProjectDecision({
        projectId: props.projectId,
        adminId: props.adminId,
        isAccepted,
    });

    decidePendingProject(
        decision,
        () => {
            addNewMessage(
                `Projet ${props.projectName} ${isAccepted ? "accepté" : "refusé"}`,
                color.Green
            );
        },
        (err) => {
            addNewMessage(`Erreur lors de la décision`, color.Red);
            console.error(err);
        }
    );
};

const acceptProject = () => sendDecision(true);
const refuseProject = () => sendDecision(false);
</script>

<style scoped>
.project {
    background: linear-gradient(to right, #f8f9fb, #ffffff);
    border: 1px solid #e0e0e0;
    border-radius: 16px;
    padding: 1.5rem;
    margin: 1.5rem 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    font-family: Arial, sans-serif;
    transition: box-shadow 0.3s ease;
}

.project:hover {
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.project-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.project-title {
    display: flex;
    flex-direction: column;
}

.project-title h2 {
    font-size: 1.25rem;
    color: #222;
    margin: 0;
    font-weight: 600;
}

.project-title p {
    font-size: 0.9rem;
    color: #666;
    margin-top: 0.25rem;
}

.project-buttons {
    display: flex;
    gap: 0.75rem;
}

button {
    padding: 0.5rem 1.1rem;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition:
        background-color 0.2s ease,
        transform 0.2s ease;
}

#accept {
    background-color: #4caf50;
}

#accept:hover {
    background-color: #3e8e41;
    transform: translateY(-2px);
}

#refus {
    background-color: #e74c3c;
}

#refus:hover {
    background-color: #c0392b;
    transform: translateY(-2px);
}
</style>
