/* Main app entry — Shoppes at San Felipe (JAL-JCP) */
const { useState: aS, useEffect: aE } = React;

function App(){
  const [tweaks, setTweaks] = aS(window.__TWEAKS__ || {
    palette:'institutional', fontScale:1.0, calculatorDefault:250000
  });
  const [tweaksOpen, setTweaksOpen] = aS(false);
  const [modalOpen, setModalOpen] = aS(false);

  aE(()=>{ applyPalette(tweaks.palette); }, [tweaks.palette]);
  aE(()=>{ document.documentElement.style.fontSize = (16 * tweaks.fontScale) + 'px'; }, [tweaks.fontScale]);

  aE(()=>{
    const onMsg = (e) => {
      if(!e.data || typeof e.data !== 'object') return;
      if(e.data.type === '__activate_edit_mode') setTweaksOpen(true);
      if(e.data.type === '__deactivate_edit_mode') setTweaksOpen(false);
    };
    window.addEventListener('message', onMsg);
    window.parent?.postMessage({type:'__edit_mode_available'}, '*');
    return ()=>window.removeEventListener('message', onMsg);
  },[]);

  const openModal = () => {
    const subject = encodeURIComponent('Shoppes at San Felipe — Investor Package Request');
    const body = encodeURIComponent(
      "Justin and James,\n\n" +
      "I'd like to receive the full investor package for Shoppes at San Felipe (JAL-JCP, April 2026).\n\n" +
      "Name:\nFirm / Entity:\nTicket size:\nAccredited: Yes / No\nBest phone:\n\nThanks."
    );
    window.location.href =
      'mailto:jlevine@jalstrategies.com,jcp@jcpinv.com?subject=' + subject + '&body=' + body;
  };

  return <>
    <Nav onCTA={openModal}/>
    <Hero onCTA={openModal}/>
    <Snapshot/>
    <Property/>
    <RentRoll/>
    <Thesis/>
    <LandComps/>
    <Appreciation/>
    <Financials/>
    <Returns/>
    <ExitVision/>
    <Risks/>
    <Sponsor/>
    <CTA onCTA={openModal}/>
    <Footer/>
    <TweaksPanel open={tweaksOpen} tweaks={tweaks} setTweaks={setTweaks}
      onClose={()=>setTweaksOpen(false)}/>
    <RequestModal open={modalOpen} onClose={()=>setModalOpen(false)}/>
  </>;
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App/>);
