'use client'

import * as React from 'react'
import { useRouter } from 'next/navigation'
import { Bidding, biddingStatusLabels, contractTypeLabels, biddingTypeLabels } from '@/db/schema'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import {
  ArrowLeft,
  Send,
  RotateCcw,
  XCircle,
  Calendar,
  Building2,
  User,
  Package,
  DollarSign,
  Hash
} from 'lucide-react'

import { formatDate } from '@/lib/utils'
import {
  registerBidding,
  markAsDisposal,
  createRebidding
} from '@/lib/bidding/detail/service'
import { useToast } from '@/hooks/use-toast'
import { useTransition } from 'react'

interface BiddingDetailHeaderProps {
  bidding: Bidding
}

export function BiddingDetailHeader({ bidding }: BiddingDetailHeaderProps) {
  const router = useRouter()
  const { toast } = useToast()
  const [isPending, startTransition] = useTransition()

  const handleGoBack = () => {
    router.push('/evcp/bid')
  }

  return (
    <div className="border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
      <div className="px-6 py-4">
        {/* 헤더 메인 영역 */}
        <div className="flex items-center justify-between mb-4">
          <div className="flex items-center gap-4 flex-1 min-w-0">
            {/* 제목과 배지 */}
            <div className="flex items-center gap-3 flex-1 min-w-0">
              <h1 className="text-xl font-semibold truncate">{bidding.title}</h1>
              <div className="flex items-center gap-2 flex-shrink-0">
                <Badge variant="outline" className="font-mono text-xs">
                  <Hash className="w-3 h-3 mr-1" />
                  {bidding.biddingNumber}
                  {bidding.revision && bidding.revision > 0 && ` Rev.${bidding.revision}`}
                </Badge>
                <Badge variant={
                  bidding.status === 'bidding_disposal' ? 'destructive' :
                  bidding.status === 'vendor_selected' ? 'default' :
                  'secondary'
                } className="text-xs">
                  {biddingStatusLabels[bidding.status]}
                </Badge>
              </div>
            </div>
          </div>
        </div>

        {/* 세부 정보 영역 */}

        {/* 일정 정보 */}
        {/* {(bidding.submissionStartDate || bidding.evaluationDate || bidding.preQuoteDate || bidding.biddingRegistrationDate) && (
          <div className="flex flex-wrap items-center gap-4 mt-3 pt-3 border-t border-border/50">
            <Calendar className="w-4 h-4 text-muted-foreground flex-shrink-0" />
            <div className="flex flex-wrap items-center gap-4 text-sm text-muted-foreground">
              {bidding.submissionStartDate && bidding.submissionEndDate && (
                <div>
                  <span className="font-medium">제출기간:</span> {formatDate(bidding.submissionStartDate, 'KR')} ~ {formatDate(bidding.submissionEndDate, 'KR')}
                </div>
              )}
              {bidding.evaluationDate && (
                <div>
                  <span className="font-medium">평가일:</span> {formatDate(bidding.evaluationDate, 'KR')}
                </div>
              )}
              {bidding.preQuoteDate && (
                <div>
                  <span className="font-medium">사전견적일:</span> {formatDate(bidding.preQuoteDate, 'KR')}
                </div>
              )}
              {bidding.biddingRegistrationDate && (
                <div>
                  <span className="font-medium">입찰등록일:</span> {formatDate(bidding.biddingRegistrationDate, 'KR')}
                </div>
              )}
            </div>
          </div>
        )} */}
      </div>
    </div>
  )
}