<script setup lang="ts">
import type { EditableKuaishouEticketShop } from '../../composables/types'
import type {
  AdminKuaishouEticketConsumeResult,
  AdminKuaishouEticketDetailResult,
  AdminKuaishouEticketShopInfoResult,
} from '@/types/admin'
import AdminKuaishouEticketInfoCard from './AdminKuaishouEticketInfoCard.vue'
import AdminKuaishouEticketShopConfig from './AdminKuaishouEticketShopConfig.vue'
import AdminKuaishouEticketDebug from './AdminKuaishouEticketDebug.vue'
import AdminKuaishouEticketResults from './AdminKuaishouEticketResults.vue'

type KuaishouEticketStats = {
  configuredShopCount: number
  cookieReadyCount: number
  selectedShopReady: boolean
  detailReady: boolean
  consumed: boolean
}

type Props = {
  kuaishouEticketFilePath: string
  kuaishouEticketShops: EditableKuaishouEticketShop[]
  kuaishouEticketForm: {
    baseUrl: string
    selectedShopId: string
    queryTicketCode: string
    eTicketId: string
    oid: string
    formToken: string
    num: number
    storeId: string
  }
  kuaishouEticketSaving: boolean
  kuaishouEticketResolvingShopId: string
  kuaishouEticketDetailing: boolean
  kuaishouEticketConsuming: boolean
  kuaishouEticketResultError: string
  kuaishouEticketShopInfoResult: AdminKuaishouEticketShopInfoResult | null
  kuaishouEticketDetailResult: AdminKuaishouEticketDetailResult | null
  kuaishouEticketConsumeResult: AdminKuaishouEticketConsumeResult | null
  activeKuaishouEticketShop: EditableKuaishouEticketShop | null
  kuaishouEticketStats: KuaishouEticketStats
  addKuaishouEticketShop: () => void
  removeKuaishouEticketShop: (id: string) => void
  isKuaishouEticketShopExpanded: (id: string) => boolean
  toggleKuaishouEticketShop: (id: string) => void
  expandAllKuaishouEticketShops: () => void
  collapseAllKuaishouEticketShops: () => void
  setKuaishouEticketDebugShop: (id: string) => void
  describeKuaishouEticketShop: (shop: EditableKuaishouEticketShop) => string
  getKuaishouEticketShopInitial: (shop: EditableKuaishouEticketShop) => string
  handleKuaishouEticketResolveShopInfo: (shop: EditableKuaishouEticketShop) => void | Promise<void>
  handleKuaishouEticketSaveSource: () => void | Promise<void>
  handleKuaishouEticketQueryDetail: () => void | Promise<void>
  handleKuaishouEticketConsume: () => void | Promise<void>
}

defineProps<Props>()
</script>

<template>
  <div class="platform-section">
    <AdminKuaishouEticketInfoCard :kuaishou-eticket-file-path="kuaishouEticketFilePath" />

    <AdminKuaishouEticketShopConfig
      :kuaishou-eticket-shops="kuaishouEticketShops"
      :kuaishou-eticket-form="kuaishouEticketForm"
      :kuaishou-eticket-saving="kuaishouEticketSaving"
      :kuaishou-eticket-resolving-shop-id="kuaishouEticketResolvingShopId"
      :kuaishou-eticket-result-error="kuaishouEticketResultError"
      :kuaishou-eticket-shop-info-result="kuaishouEticketShopInfoResult"
      :active-kuaishou-eticket-shop="activeKuaishouEticketShop"
      :kuaishou-eticket-stats="kuaishouEticketStats"
      :add-kuaishou-eticket-shop="addKuaishouEticketShop"
      :remove-kuaishou-eticket-shop="removeKuaishouEticketShop"
      :is-kuaishou-eticket-shop-expanded="isKuaishouEticketShopExpanded"
      :toggle-kuaishou-eticket-shop="toggleKuaishouEticketShop"
      :expand-all-kuaishou-eticket-shops="expandAllKuaishouEticketShops"
      :collapse-all-kuaishou-eticket-shops="collapseAllKuaishouEticketShops"
      :set-kuaishou-eticket-debug-shop="setKuaishouEticketDebugShop"
      :describe-kuaishou-eticket-shop="describeKuaishouEticketShop"
      :get-kuaishou-eticket-shop-initial="getKuaishouEticketShopInitial"
      :handle-kuaishou-eticket-resolve-shop-info="handleKuaishouEticketResolveShopInfo"
      :handle-kuaishou-eticket-save-source="handleKuaishouEticketSaveSource"
    />

    <AdminKuaishouEticketDebug
      :kuaishou-eticket-shops="kuaishouEticketShops"
      :kuaishou-eticket-form="kuaishouEticketForm"
      :kuaishou-eticket-detailing="kuaishouEticketDetailing"
      :kuaishou-eticket-consuming="kuaishouEticketConsuming"
      :kuaishou-eticket-detail-result="kuaishouEticketDetailResult"
      :kuaishou-eticket-consume-result="kuaishouEticketConsumeResult"
      :handle-kuaishou-eticket-query-detail="handleKuaishouEticketQueryDetail"
      :handle-kuaishou-eticket-consume="handleKuaishouEticketConsume"
    />

    <AdminKuaishouEticketResults
      :kuaishou-eticket-detail-result="kuaishouEticketDetailResult"
      :kuaishou-eticket-consume-result="kuaishouEticketConsumeResult"
    />
  </div>
</template>

<style scoped>
.platform-section {
  display: grid;
  gap: var(--space-4);
}
</style>
