'use client'

import * as React from 'react'
import { Bidding } from '@/db/schema'
import { QuotationDetails } from '@/lib/bidding/detail/service'
import { getBiddingCompanies } from '../service'

import { BiddingPreQuoteVendorTableContent } from './bidding-pre-quote-vendor-table'

interface BiddingPreQuoteContentProps {
  bidding: Bidding
  quotationDetails: QuotationDetails | null
  biddingCompanies: any[]
  prItems: any[]
}

export function BiddingPreQuoteContent({
  bidding,
  quotationDetails,
  biddingCompanies: initialBiddingCompanies,
  prItems
}: BiddingPreQuoteContentProps) {
  const [biddingCompanies, setBiddingCompanies] = React.useState(initialBiddingCompanies)
  const [refreshTrigger, setRefreshTrigger] = React.useState(0)

  const handleRefresh = React.useCallback(async () => {
    try {
      const result = await getBiddingCompanies(bidding.id)
      if (result.success && result.data) {
        setBiddingCompanies(result.data)
      }
      setRefreshTrigger(prev => prev + 1)
    } catch (error) {
      console.error('Failed to refresh bidding companies:', error)
    }
  }, [bidding.id])

  return (
    <div className="space-y-6">
      <BiddingPreQuoteVendorTableContent
        biddingId={bidding.id}
        bidding={bidding}
        biddingCompanies={biddingCompanies}
        onRefresh={handleRefresh}
        onOpenItemsDialog={() => {}}
        onOpenTargetPriceDialog={() => {}}
        onOpenSelectionReasonDialog={() => {}}
      />
    </div>
  )
}
