import { getRawProperties } from '@/actions/bmv'
import { getAllAreas, getOneVilla } from '@/actions/ttd'
import MainContent from '@/components/sidebar/main-content'
import SidebarApp from '@/components/sidebar/sidebar-app'
import SidebarWrapper from '@/components/sidebar/sidebar-wrapper'
import SiteHeader from '@/components/sidebar/site-header'
import EditForm from '@/components/ttd/villas/edit-form'

export default async function page({params} : { params: Promise<{ id: string }>}) {

    const id = (await params).id

    let error = false;
    const [areaData, villaData, singleData] = await Promise.all([
        getAllAreas(),
        getRawProperties(),
        getOneVilla(id)
    ])
    const areas = areaData.success ? areaData.data : [];
    const villas = villaData.success ? villaData.data : [];
    const data = singleData.success ? singleData.data : null

    if(!areaData.success) error = true;
    if(!villaData.success) error = true;
    if(!singleData.success) error = true;

    return (
        <div className="[--header-height:calc(--spacing(14))]">
            <SidebarWrapper>
                <div className="flex flex-1">
                    <SidebarApp/>
                    <MainContent>
                        <SiteHeader/>
                        <div className="flex flex-1 flex-col gap-6 lg:px-14 px-4 py-8 bg-gundam-gray/30">
                            <EditForm
                                error={error}
                                areas={areas}
                                villas={villas}
                                data={data}
                            />
                        </div>
                    </MainContent>
                </div>
            </SidebarWrapper>
        </div>
    )
}
