web/website/control-panel/public/bank-dashboard.mjs

25 lines
6 KiB
JavaScript

const el=(tag,text)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;return n;},host=document.getElementById('dashboard'),views={};
function box(title,copy){const b=el('article');b.className='imperial-account-card bank-loan-card';const ornament=el('span','◆');ornament.className='bank-loan-ornament';ornament.setAttribute('aria-hidden','true');b.append(ornament);b.append(el('h3',title),el('p',copy));return b;}
for(const[id,title]of [['bank-dashboard','Bank Dashboard'],['loan-centre','Loan Centre'],['loan-administration','Loan Administration']]){const root=el('section');root.id=id;root.className='bank-workspace';root.hidden=true;const brand=el('img');brand.src='/assets/imperial-postbank-v2.png';brand.alt='Imperial Postbank · Part of Corrino Group';brand.className='imperial-bank-brand';brand.width=480;const hero=el('header');hero.className='bank-loan-hero';const copy=el('div');copy.append(el('p','IMPERIAL POSTBANK · CREDIT SERVICES'),el('h2',title),el('p','Clear terms. Recorded decisions. A treasury-backed commitment.'));hero.append(brand,copy);root.append(hero);const intro=el('p','LOAN SERVICES PREVIEW · Applications, approvals and transfers are not connected yet. Nothing entered here is submitted.');intro.className='bank-instructions bank-loan-preview';root.append(intro);const links=el('nav');links.className='bank-dashboard-links';for(const[label,hash]of [['My accounts','personal-bank'],['Loan Centre','loan-centre'],['Corrino Group','https://www.dunerealms.com/corrino-group.html']]){const a=el('a',label);a.href=hash.startsWith('https:')?hash:'#'+hash;links.append(a);}root.append(links);const grid=el('div');grid.className='bank-balance-grid bank-loan-grid';root.append(grid);host?.append(root);views[id]={root,grid};}
views['bank-dashboard'].grid.append(box('Accounts & statements','Your personal account and eligible shared treasuries use permanent Imperial account numbers. Open My accounts to see your verified balance.'),box('Credit terms','5% one-time interest · 28 days from payout · no compound interest or automatic penalties.'),box('Loan overview','Outstanding principal, repayments and due dates will appear here once lending is connected. No illustrative amount is presented as your balance.'));
const request=box('Request a Loan','Choose an amount and explain its purpose. Staff approval and your acceptance are required before payout.');const form=el('form');const amountLabel=el('label','Amount · Dunemarks'),amount=el('input');amount.type='number';amount.min='1';amount.step='1';amount.placeholder='1000';amountLabel.append(amount);const reasonLabel=el('label','Purpose of the loan'),reason=el('textarea');reason.maxLength=2000;reasonLabel.append(reason);const quote=el('p','Example: 1,000 DM borrowed → 1,050 DM repayable.');quote.className='bank-loan-quote';amount.addEventListener('input',()=>{const n=Number(amount.value);quote.textContent=Number.isFinite(n)&&n>0?'Illustrative total repayment: '+(Math.ceil(n*105)/100).toFixed(2)+' DM · within 28 days':'Enter an amount to preview repayment.';});const confirm=el('label'),check=el('input');check.type='checkbox';confirm.append(check,el('span','I understand the 5% interest and 28-day term.'));const submit=el('button','Applications opening soon');submit.type='button';submit.disabled=true;form.addEventListener('submit',e=>e.preventDefault());form.append(amountLabel,reasonLabel,quote,confirm,submit);request.append(form);
request.classList.add('bank-loan-request');views['loan-centre'].grid.append(request,box('My Applications','Application status and staff decisions will appear here. Connection pending.'),box('Current Loans','Your principal, interest, outstanding balance and due date. Connection pending.'),box('Make a Repayment','Partial and full repayments will be recorded against your loan. Payments are currently disabled.'),box('Loan History','Completed loans and their payment records. Connection pending.'));
views['loan-administration'].grid.append(box('Application Review','Staff-only review queue. Approval does not automatically transfer funds.'),box('Payouts & repayments','Audited disbursement and repayment controls will appear here after transaction testing.'),box('Overdue accounts','Overdue status will be recorded without automatic fines. No collection actions are enabled.'));
function session(user){for(const[id,v]of Object.entries(views)){const allowed=user?.permissions?.includes(id==='loan-administration'?'web.bank.staff.manage':'web.bank.personal.view');v.root.hidden=!allowed;} }window.addEventListener('dune:session',e=>session(e.detail));fetch('/api/auth/session',{cache:'no-store'}).then(r=>r.ok?r.json():null).then(d=>session(d?.user)).catch(()=>session(null));
// Update only company presentation; mailbox content and permissions remain untouched.
function linkCorrinoMarks(){
for(const img of document.querySelectorAll('img[alt="Corrino Group"]')){
if(!img.src.endsWith('/assets/corrino-group-v4.png'))img.src='/assets/corrino-group-v4.png';
img.width=150;img.height=50;
if(img.closest('a'))continue;
const a=el('a');a.href='https://www.dunerealms.com/corrino-group.html';a.setAttribute('aria-label','About Corrino Group');img.replaceWith(a);a.append(img);
}
for(const img of document.querySelectorAll('img[alt="Spost"],img[alt="SpicePost"]')){img.src='/assets/spost-logo-v1.svg';img.alt='Spost · Part of Corrino Group';img.width=240;img.height=80;}
const inventory=document.getElementById('planetary-inventory');
if(inventory&&!inventory.querySelector('.inventory-company-endorsement')){
const footer=el('div');footer.className='inventory-company-endorsement';
const a=el('a');a.href='https://www.dunerealms.com/corrino-group.html#vaerkring';a.setAttribute('aria-label','Vaerkring · Part of Corrino Group');
const img=el('img');img.src='/assets/vaerkring-company-v1.png';img.alt='Vaerkring · Part of Corrino Group';img.width=300;img.height=100;a.append(img);footer.append(a);inventory.append(footer);
}
}
linkCorrinoMarks();new MutationObserver(linkCorrinoMarks).observe(document.body,{childList:true,subtree:true});