// Owner-confirmed schedule, 8 November 2026. GMT is UTC, not local summer time. export const ELECTION_RULES = Object.freeze({ house: Object.freeze({first:'2026-11-15T09:00:00.000Z',weeks:4}), bene: Object.freeze({first:'2026-11-15T15:00:00.000Z',weeks:4}), guild: Object.freeze({first:'2026-11-15T15:00:00.000Z',weeks:4}), clan_delegate: Object.freeze({first:'2026-11-15T15:00:00.000Z',weeks:4}), naib_chair: Object.freeze({first:'2026-11-15T15:00:00.000Z',weeks:4}), imperial: Object.freeze({first:'2026-11-15T15:00:00.000Z',weeks:4}), }); export function electionDates(kind, now=Date.now(), count=4) { const rule=ELECTION_RULES[kind]; if(!rule || !Number.isFinite(now) || !Number.isInteger(count) || count<1 || count>12) throw new Error('Invalid calendar request'); const first=Date.parse(rule.first),period=rule.weeks*7*86400000; const offset=Math.max(0,Math.ceil((now-first)/period)); return Array.from({length:count},(_,i)=>new Date(first+(offset+i)*period).toISOString()); } // Only a verified server-side faction and current office may establish eligibility. export function imperialVoteAllowance({linked=false,faction=null,houseLeader=false}={}) { return linked && faction ? houseLeader===true ? 5 : 1 : 0; } export function electionWindow(kind,start,now=Date.now()) { const rule=ELECTION_RULES[kind],timestamp=Date.parse(start); if(!rule||!Number.isFinite(timestamp)||!Number.isFinite(now))throw Error('Invalid election window'); const first=Date.parse(rule.first),period=rule.weeks*7*86400000; if(timestamp4000||/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(motivation))throw Error('Motivation must contain 20–4000 readable characters'); // Never take faction or office authority from the submitted form. return {kind:input.kind,start:window.votingOpens,faction:electionScope(input.kind,context),motivation}; } export function electionScope(kind,context={}){return kind==='house'?context.faction:({imperial:'imperium',bene:'veiled_concord',guild:'spacing_guild',clan_delegate:'clans',naib_chair:'arrakis'})[kind];} export function voteCapacity(kind,context={}){return kind==='imperial'?imperialVoteAllowance(context):kind==='naib_chair'?(context.naib&&context.clanId?1:0):kind==='clan_delegate'?(context.clanLeader&&context.clanId?1:0):1;}