import { getServerApi } from '@garage/api/server'
import { EstimateGeneralInfo } from '@/modules/estimates/estimate-general-info'
import { EstimateServicesSection } from '@/modules/estimates/estimate-services-section'
import { EstimatePartsSection } from '@/modules/estimates/estimate-parts-section'
import { EstimateExpenseItemsSection } from '@/modules/estimates/estimate-expense-items-section'
import { EstimateTotalsSummary } from '@/modules/estimates/estimate-totals-summary'
import DashboardPage from '@/base/components/layout/dashboard/dashboard-page'

export default async function page(props: { params: Promise<{ id: string }> }) {
    const { id } = await props.params
    const api = await getServerApi()
    const estimate = await api.estimates.show(id)

    const estimateData = estimate?.data

    if (!estimateData) {
        return <div className="text-muted-foreground p-4">Estimate not found.</div>
    }

    return (
        <DashboardPage header={null}>
            <div className="grid gap-6">
                <EstimateGeneralInfo estimate={estimateData} />
                <EstimateServicesSection estimateId={id} />
                <EstimatePartsSection estimateId={id} />
                <EstimateExpenseItemsSection estimateId={id} />
                <EstimateTotalsSummary />
            </div>
        </DashboardPage>
    )
}

