export const example={references:[{source:'https://example.com/film?utm_source=test#shot',intents:['lighting'],shotIds:['s01']},{source:'Mood note: restrained motion',intents:['motion']}]}; const normalize=s=>{try{const u=new URL(s);if(u.protocol!=='https:')return null;if(u.username||u.password)return'credential';u.hash='';for(const k of [...u.searchParams.keys()])if(/^utm_|^(gclid|fbclid)$/i.test(k))u.searchParams.delete(k);u.searchParams.sort();return u.href}catch{return String(s).trim()}}; export function evaluate(x){const errors=[],warnings=[],rows=[],seen=new Set;if(!Array.isArray(x?.references))return{valid:false,errors:[{code:'INPUT'}],warnings,rows};x.references.forEach((r,i)=>{if(!String(r.source??'').trim())errors.push({code:'SOURCE',index:i});if(!Array.isArray(r.intents)||!r.intents.length)warnings.push({code:'UNCLASSIFIED',index:i});const n=normalize(r.source);if(n==='credential')errors.push({code:'CREDENTIAL_URL',index:i});else if(n===null)errors.push({code:'HTTPS_REQUIRED',index:i});else if(seen.has(n))errors.push({code:'DUPLICATE',index:i});else seen.add(n);rows.push({...r,normalizedSource:n})});return{valid:errors.length===0,errors,warnings,rows}}