const origin='https://cp.dunerealms.com',frame=document.querySelector('#organisation-frame'),tabs=[...document.querySelectorAll('[data-organisation-kind]')],status=document.querySelector('#organisation-status'); const surfaces={clan:{path:'/clan-cp',route:'clan/clan-overview',label:'Clans'},company:{path:'/company-cp',route:'company/overview',label:'Companies'},politics:{path:'/politics-cp',route:'politics/overview',label:'Politics'}}; let active=''; function show(){const raw=location.hash.slice(1),kind=raw.split('/')[0]||'clan',surface=surfaces[kind];if(!surface){location.replace('#clan');return;}active=kind;for(const tab of tabs){tab.setAttribute('aria-current',String(tab.dataset.organisationKind===kind?'page':'false'));}status.textContent='Opening your '+surface.label.toLowerCase()+' workspace…';frame.title=surface.label+' management';const url=new URL(surface.path,origin);for(const key of ['clan','company','office']){const value=new URL(location.href).searchParams.get(key);if(value)url.searchParams.set(key,value);}url.hash=raw.includes('/')?raw:surface.route;if(frame.src!==url.href)frame.src=url.href;} frame.addEventListener('load',()=>{status.textContent='Manage your selected organisation below. Its existing access rules apply.';frame.contentWindow.postMessage({type:'dune-embed-measure'},origin);}); window.addEventListener('message',event=>{if(event.origin!==origin||event.source!==frame.contentWindow)return;const data=event.data;if(data?.type==='dune-embed-size'&&Number.isFinite(data.height))frame.style.height=Math.max(600,Math.min(50000,data.height))+'px'; const clan=data?.type==='dune-clan-route'&&active==='clan',organisation=data?.type==='dune-organisation-context'&&data.kind===active; if((clan||organisation)&&typeof data.page==='string'&&/^[a-z0-9-]+$/.test(data.page)){ const url=new URL(location.href),id=clan?data.accountId:data.id;if(typeof id==='string'&&/^[a-zA-Z0-9_-]{1,120}$/.test(id))url.searchParams.set(({clan:'clan',company:'company',politics:'office'})[active],id);url.hash=active+'/'+data.page;history.replaceState(null,'',url); } }); addEventListener('hashchange',show);show();