import {notFound} from 'next/navigation';
import type {Metadata} from 'next';
import {env} from 'cloudflare:workers';
import {langs,navPages,pageTitle,company,text,industries,type Lang} from '../../lib/content';
import {markets} from '../../lib/markets';
import {publicContent} from '../../lib/server';
import {seoCopy,availableLanguages,pageUrl} from '../../lib/seo';
import {Shell,HomePage,StandardPage,MarketPage,PageHero,CTA} from '../../components/site';
import {WorkforceCatalogue,EnquiryForm} from '../../components/client';
export const dynamic='force-dynamic';
type Props={params:Promise<{lang:string;slug?:string[]}>};
export async function generateMetadata({params}:Props):Promise<Metadata>{
 const p=await params;const l=langs.includes(p.lang as Lang)?p.lang as Lang:'en';const path=(p.slug||[]).join('/');const content=await publicContent().catch(()=>[]);const {title,description}=seoCopy(path,l,content);const base=env.SITE_URL||company.url;const available=availableLanguages(path,content);const canonical=pageUrl(base,l,path);return {title:`${title} | AL MURIS INTERNATIONAL`,description,alternates:{canonical,languages:Object.fromEntries([...available.map(x=>[x,pageUrl(base,x,path)]),...(available.includes('en')?[['x-default',pageUrl(base,'en',path)]]:[])])},robots:{index:env.PUBLIC_INDEXING==='true',follow:env.PUBLIC_INDEXING==='true'},openGraph:{title,description,url:canonical,images:[`${base}/images/workforce-hero.webp`],siteName:company.name,type:'website'},verification:{google:env.GOOGLE_SITE_VERIFICATION,other:env.BING_SITE_VERIFICATION?{'msvalidate.01':env.BING_SITE_VERIFICATION}:undefined}};
}
export default async function Page({params}:Props){const p=await params;if(!langs.includes(p.lang as Lang))notFound();const l=p.lang as Lang;const parts=p.slug||[];const path=parts.join('/');const content=await publicContent().catch(()=>[]);let body;
 if(!parts.length)body=<HomePage l={l} content={content}/>;
 else if(parts[0]==='markets'&&parts.length===2){const m=markets.find(x=>x.slug===parts[1]);const custom=content.find(c=>c.kind==='market'&&c.slug===parts[1]&&c.locale===l);if(m)body=<MarketPage l={l} market={m} custom={custom}/>;else if(custom)body=<><PageHero l={l} title={custom.title} subtitle={custom.summary}/><section className="wrap section"><p className="preline">{custom.body}</p><p>{text.marketNote[l]}</p><EnquiryForm l={l} country={custom.title}/></section></>;else notFound();}
 else if(parts[0]==='industries'&&parts.length===2){const i=industries.find(x=>x.id===parts[1]);if(!i)notFound();body=<><PageHero l={l} title={i.name[l]} subtitle={i.desc[l]}/><section className="wrap section"><WorkforceCatalogue l={l} only={i.id} extra={content}/></section><CTA l={l}/></>;}
 else if(parts.length===1&&(navPages.includes(path)||content.some(c=>c.kind==='page'&&c.slug===path&&c.locale===l)))body=<StandardPage l={l} slug={path} content={content}/>;else notFound();
 const schema={'@context':'https://schema.org','@type':'Organization',name:company.name,url:company.url,email:company.email,telephone:company.phone,address:{'@type':'PostalAddress',addressLocality:'Dhaka',addressCountry:'BD'},contactPoint:{'@type':'ContactPoint',telephone:company.phone,contactType:'customer service',availableLanguage:['English','Bengali','Arabic']}};
 return <Shell l={l} path={path} gaId={env.GA_MEASUREMENT_ID}>{body}<script type="application/ld+json" dangerouslySetInnerHTML={{__html:JSON.stringify(schema).replaceAll('<','\\u003c')}}/></Shell>;
}
