<script setup lang="ts">
import { Sparkles } from '@lucide/vue'

import AdminReviewDecisionPanel from '../../components/admin/AdminReviewDecisionPanel.vue'
import AdminPageHeader from '../../components/admin/AdminPageHeader.vue'
import AdminReviewsHistorySection from '../../components/admin/AdminReviewsHistorySection.vue'
import AdminReviewsQueueHeader from '../../components/admin/AdminReviewsQueueHeader.vue'
import AdminReviewsQueueList from '../../components/admin/AdminReviewsQueueList.vue'
import AdminSeasonToolbar from '../../components/admin/AdminSeasonToolbar.vue'
import Card from '../../components/ui/Card.vue'
import { useAdminReviewsManager } from '../../components/admin/useAdminReviewsManager'
import { watchAdminToast } from '../../composables/useAdminToast'

const {
  reviewSaving,
  adminMessage,
  adminError,
  reviewForms,
  seasonDetail,
  reviewFilter,
  categoryFilter,
  selectedNominationId,
  candidatePlatformOptions,
  filteredNominations,
  selectedNomination,
  reviewStats,
  reviewedNominations,
  categoryOptions,
  selectedCandidateCollision,
  canApproveSelected,
  approveNomination,
  rejectNomination,
  selectedPlatformValue,
  handlePlatformSelection,
} = useAdminReviewsManager()

watchAdminToast(adminMessage, adminError)
</script>

<template>
  <div class="space-y-6">
    <AdminPageHeader
      eyebrow="Reviews"
      description="Freitext-Nominierungen annehmen, in Kandidaten umwandeln oder verwerfen."
      :icon="Sparkles"
    />

    <AdminSeasonToolbar />

    <Card class="overflow-hidden">
      <AdminReviewsQueueHeader
        v-model:review-filter="reviewFilter"
        v-model:category-filter="categoryFilter"
        :total-pending="seasonDetail.pendingNominations.length"
        :visible-count="filteredNominations.length"
        :review-stats="reviewStats"
        :category-options="categoryOptions"
      />

      <div class="space-y-4 p-6">
        <div class="grid gap-5 xl:grid-cols-[minmax(320px,0.85fr)_minmax(0,1.15fr)]">
          <AdminReviewsQueueList
            :nominations="filteredNominations"
            :total-pending="seasonDetail.pendingNominations.length"
            :selected-nomination-id="selectedNominationId"
            @select="selectedNominationId = $event"
          />

          <AdminReviewDecisionPanel
            :nomination="selectedNomination"
            :review-saving="reviewSaving"
            :review-form="selectedNomination ? reviewForms[selectedNomination.id] : null"
            :candidate-platform-options="candidatePlatformOptions"
            :selected-candidate-collision="selectedCandidateCollision"
            :can-approve-selected="canApproveSelected"
            :selected-platform-value="selectedPlatformValue"
            @platform-change="handlePlatformSelection"
            @approve="approveNomination"
            @reject="rejectNomination"
          />
        </div>

        <AdminReviewsHistorySection
          :reviewed-nominations="reviewedNominations"
          :reviewed-total="seasonDetail.reviewedNominations.length"
        />
      </div>
    </Card>
  </div>
</template>
