/* Website shell derived from the signed CapGain iOS release, 12 October 2026. */ const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); const asset = name => `native-assets/CapGainHero${name}.webp`; const photos = {cg:'CapitalGains',stamp:'StampDuty',ownership:'DealCost',gst:'GST',emi:'EMI',finance:'LoanEligibility',pmay:'PMAY',rent:'Home',nridesk:'NRI',circle:'CircleRate',land:'LandUnits',builders:'Diligence'}; const svcPhotos = {'cg-review':'AdvisoryCapitalGains',tds:'AdvisoryTDS',docs:'AdvisoryDocuments',verify:'AdvisoryVerify',rera:'AdvisoryRERA',diligence:'AdvisoryDiligence',nri:'AdvisoryNRI',valuation:'AdvisoryValuation',rental:'AdvisoryRental',succession:'AdvisorySuccession',structuring:'AdvisoryStructuring'}; const tabNames = {home:'Home',calculators:'Calculators',advisory:'Advisory',news:'News',knowledge:'Knowledge'}; const calcOrder = ['cg','stamp','ownership','gst','emi','finance','pmay','rent','nridesk','circle','land']; const journeyPhotos = {sell:'JourneySell',buy:'JourneyBuy',nri:'JourneyNRI',inherit:'JourneyInherit'}; let tab = 'home'; let term = ''; const root = document.createElement('div'); root.id = 'cg-native-app'; root.setAttribute('aria-label','CAPGAIN website'); document.body.prepend(root); document.documentElement.classList.add('cg-native-parity'); const accountDialog=document.createElement('dialog'); accountDialog.id='cg-native-account-dialog'; accountDialog.className='cg-native-account-dialog'; document.body.append(accountDialog); function cg() { return window.CG; } function button(text, action, cls = '') { return ``; } function hero(image, eyebrow, title, subtitle) { return `
${esc(eyebrow)}

${esc(title)}

${esc(subtitle)}

`; } function row(title, sub, action, image) { return button(`${esc(title)}${esc(sub)}`, action, 'cg-native-row'); } function section(title, body, action, actionText='See all') { return `

${esc(title)}

${action ? button(esc(actionText)+' ',action,'cg-native-link') : ''}
${body}
`; } function openNativeRoute(route) { document.documentElement.classList.add('cg-native-detail'); try { cg().navigate(route); } catch { cg().go(route.split(':')[0]); } setTimeout(() => { if (document.querySelector('dialog[open]')) document.documentElement.classList.remove('cg-native-detail'); }, 0); window.scrollTo(0,0); } function home() { const journeys = (cg().catalog.journeys || []).map(j => row(j.title,j.sub,`journey:${j.id}`,journeyPhotos[j.id] || 'Home')).join(''); const picks = ['cg','ownership','stamp','emi'].map(key => cg().catalog.calculators.find(c=>c.key===key)).filter(Boolean).map(c=>row(c.title,c.sub,`calc:${c.key}`,photos[c.key])).join(''); const news = newsList(3); return `
${greeting()}
${button('⌕Ask the capital gains book AI→','assistant','cg-native-ask')} ${hero('Estate','YOUR PROPERTY WORKSPACE','A clearer way through every property decision','Tax, due diligence, filing and trusted guidance in one place.')} ${row('TDS & Form 141','Rent or property purchase · JSON, XML and PDF','form','TDS')} ${section('Your journey',`
${journeys}
`)} ${section('Popular calculators',`
${picks}
`,'tab:calculators')} ${section('Your workspace',`
${row('Property workspace','Documents and due diligence','docs','Documents')}${row('Advisory','Get professional help','tab:advisory','Transactions')}
`)} ${section('Property tax news',news,'tab:news')}`; } function greeting() { const h=new Date().getHours(); return h>=5&&h<12?'Good morning':h>=12&&h<17?'Good afternoon':'Good evening'; } function calculators() { const all = calcOrder.map(key=>cg().catalog.calculators.find(c=>c.key===key)).filter(Boolean); const matched=all.filter(c=>(c.title+' '+c.sub).toLowerCase().includes(term.toLowerCase())); return `${hero('Calculator','CALCULATORS','Work out your next move','Clear calculations for buying, selling, financing and tax.')} ${row('TDS & Form 141','Prepare rent or purchase schedules','form','TDS')} ${section('All calculators',matched.length?matched.map(c=>row(c.title,c.sub,c.key==='circle'?'route:circle':`calc:${c.key}`,photos[c.key]||'Calculator')).join(''):'

No matching calculator.

')}`; } function advisory() { const services=(cg().catalog.services||[]).filter(s=>(s.title+' '+(s.what||'')).toLowerCase().includes(term.toLowerCase())); return `${hero('Transactions','ADVISORY','Expert help for your transaction','Choose the right professional for tax, legal review and property decisions.')} ${section('Services',services.length?services.map(s=>row(s.title,s.what||'',`service:${s.key}`,svcPhotos[s.key]||'AdvisoryTransaction')).join(''):'

No matching service.

')} ${section('Your requests',row('My requests','View or continue an advisory request','route:account:requests','AdvisoryTransaction'))}`; } function newsList(limit=12) { let items=[]; try { items=cg().feed.items({limit}); } catch {} return items.length?items.map(item=>{ const link=typeof item.link==='string'&&/^https:\/\//i.test(item.link)?item.link:null; const title=esc(item.title); const desc=esc(item.desc||''); return `
${esc(item.source||'Property tax news')}

${title}

${desc}

${link?`Read original source ↗`:''}
`; }).join(''):'

Headlines are unavailable right now.

'; } function news() { return `${hero('News','NEWS','Real Estate Transactions Tax News','Capital gains · Income tax · TDS · GST. Read each update at its original source.')}${section('Latest updates',newsList())}`; } function knowledge() { const topics = [ ['Capital gains','Income tax on a property sale','knowledge:topic:capital-gains','CapitalGains'],['RERA','Projects, registration and buyer remedies','knowledge:topic:rera','RERA'],['GST on property','Construction, rent and reverse charge','knowledge:topic:gst','GST'],['NRI property rules','Tax, TDS and repatriation','knowledge:topic:nri','NRI'] ]; const matched=topics.filter(t=>(t[0]+' '+t[1]).toLowerCase().includes(term.toLowerCase())); return `${hero('Knowledge','KNOWLEDGE','Property law and tax, in plain words','RERA, land records, capital gains, GST and NRI rules, with tools to act on them.')} ${row('Ask the 2026 capital gains book','Answers grounded in cited reader pages','book','Knowledge')} ${section('Explore the library',matched.length?matched.map(t=>row(t[0],t[1],`route:${t[2]}`,t[3])).join(''):'

No matching topic.

')} ${section('Market and property data',row('Circle rates','Government values by city and zone','route:circle','CircleRate')+row('Builder grade','Developer records and ratings','route:builders','Diligence'))}`; } function render() { const content={home,calculators,advisory,news,knowledge}[tab](); root.innerHTML=`
${button('','account','cg-native-account')}
${content}
CAPGAIN · Redefining Real Estate
`; } root.addEventListener('click', event=>{ const target=event.target.closest('[data-native-action]'); if(!target)return; const action=target.dataset.nativeAction; if(action.startsWith('tab:')) { tab=action.slice(4); term=''; document.documentElement.classList.remove('cg-native-detail'); render(); window.scrollTo(0,0); return; } if(action==='book') return window.CapGainBook?.open(); if(action==='form') return window.CapGainRelease?.openForm(); if(action==='docs') return window.CapGainRelease?.openDocs(); if(action==='account') { const user=cg().auth.current(); if(!user) return cg().auth.openSignIn(); accountDialog.innerHTML=`

Your account

${esc(user.emailMasked||'Signed in')}

Signed in with ${esc(user.provider||user.method||'CAPGAIN')}

`; accountDialog.showModal(); return; } if(action==='assistant') return window.CapGainBook?.open(); if(action.startsWith('calc:')) return openNativeRoute('calculators:'+action.slice(5)); if(action.startsWith('service:')) return openNativeRoute('advisory:'+action.slice(8)); if(action.startsWith('journey:')) return openNativeRoute('journey:'+action.slice(8)); if(action.startsWith('route:')) return openNativeRoute(action.slice(6)); }); root.addEventListener('click',event=>{ if(event.target.id==='cg-native-back'){try{cg().sheet.close();}catch{}document.documentElement.classList.remove('cg-native-detail');render();window.scrollTo(0,0);} }); root.addEventListener('input',event=>{ if(event.target.id==='cg-native-filter'){const pos=event.target.selectionStart; term=event.target.value; render(); const input=root.querySelector('#cg-native-filter');input?.focus();input?.setSelectionRange(pos,pos);} }); accountDialog.addEventListener('click',event=>{ if(event.target.matches('[data-account-close]')||event.target===accountDialog) accountDialog.close(); if(event.target.matches('[data-account-signout]')) { cg().auth.signOut(); accountDialog.close(); render(); } }); const startup=setInterval(()=>{if(cg()?.catalog&&cg()?.feed){clearInterval(startup);render();}},25); setTimeout(()=>clearInterval(startup),15000);