import type { Store } from './store.js';
export const PALETTE:readonly string[]=['🦊','🐼','🐸','🦁','🐙','🦉','🦄','🐢','🦋','🐝','🐳','🦖','🦔','🐘','🦜','🐺','🐨','🐰','🍄','🚀','⚓','🎸','🔭','🧩','🪁','🛶','🏺','🎻','🪐','🗿','🧸','🪄','🛸','🧭','🔑','🪴','🦀','🐌','🦩','🐲'];
function hash(s:string){let h=0x811c9dc5;for(const c of s){h^=c.charCodeAt(0);h=Math.imul(h,0x01000193)}return h>>>0}
export function resolveSessionMark(sessionId:string,store:Store,now:number):string {const old=store.getMark(sessionId);if(old){store.touchMark(sessionId,now);return old.emoji}const all=store.listMarks(), live=all.filter(x=>x.lastSeenAt>now-86400000), used=new Set(live.map(x=>x.emoji));let emoji:string|undefined;for(let i=0;i<PALETTE.length;i++){const candidate=PALETTE[(hash(sessionId)+i)%PALETTE.length]!;if(!used.has(candidate)){emoji=candidate;break}}if(!emoji) emoji=all.reduce((a,b)=>a.lastSeenAt<=b.lastSeenAt?a:b).emoji;store.setMark(sessionId,emoji,now);return emoji}
