const v=new Set(["已回收","已完成","已解决","resolved","done","complete"]),p=new Set(["核心","core","main"]),_=new Set(["装饰","decor","decoration"]);function b(r){if(r==null||r===""||r===!1)return null;const e=Number.parseInt(String(r),10);return Number.isFinite(e)&&e>0?e:null}function d(r,e){for(const t of e){const o=b(r==null?void 0:r[t]);if(o)return o}return null}function x(r){const e=String(r||"").trim();return v.has(e)||v.has(e.toLowerCase())}function T(r){const e=String(r||"").trim(),t=e.toLowerCase();return p.has(e)||p.has(t)?"核心":_.has(e)||_.has(t)?"装饰":"支线"}function R(r){return r==="核心"?3:r==="装饰"?1:2}function E(r,e,t){return t?"resolved":e!==null&&e<0?"overdue":r!==null&&r>=2||e!==null&&e<=5?"urgent":"active"}function y(r){return r==="overdue"?"超期":r==="urgent"?"紧急":r==="resolved"?"已回收":"活跃"}function F(r,e){return e==="overdue"?"critical":r!==null&&r>=3?"high":r!==null&&r>=2?"medium":e==="resolved"?"resolved":"normal"}function L(r){var o,h;const e=Number(((o=r==null?void 0:r.progress)==null?void 0:o.current_chapter)||0);return(Array.isArray((h=r==null?void 0:r.plot_threads)==null?void 0:h.foreshadowing)?r.plot_threads.foreshadowing:[]).map((n,w)=>{const S=x(n==null?void 0:n.status),i=T(n==null?void 0:n.tier),f=R(i),u=d(n,["planted_chapter","added_chapter","source_chapter","start_chapter","chapter"]),s=d(n,["target_chapter","due_chapter","deadline_chapter","resolve_by_chapter","target"]),C=d(n,["resolved_chapter","resolved"]),a=u&&e?Math.max(0,e-u):null,g=s&&e?s-e:null;let l=null;u&&s&&s>u&&a!==null?l=Number((a/(s-u)*f).toFixed(2)):u&&s&&s<=u&&a!==null&&(l=f*2);const c=E(l,g,S);return{id:`${(n==null?void 0:n.content)||"foreshadowing"}-${w}`,content:String((n==null?void 0:n.content)||(n==null?void 0:n.description)||"未命名伏笔"),tier:i,plantedChapter:u,targetChapter:s,resolvedChapter:C,elapsed:a,remaining:g,urgencyScore:l,level:c,statusText:y(c),urgencyText:F(l,c),rawStatus:String((n==null?void 0:n.status)||"")}})}function N(r){return r.reduce((e,t)=>(e.total+=1,t.level==="resolved"?e.resolved+=1:e.active+=1,(t.level==="urgent"||t.level==="overdue")&&(e.attention+=1),e),{total:0,active:0,resolved:0,attention:0})}export{L as b,N as s};
