function a(r){const e=Number(r);return Number.isFinite(e)&&e>0?e:null}function i(r){const e=String(r||"").trim();if(!e.includes("-"))return null;const[s,u]=e.split("-",2),n=a(s),t=a(u);return!n||!t||n>t?null:{start:n,end:t}}function m(r){var e;return a((e=r==null?void 0:r.progress)==null?void 0:e.current_chapter)||1}function c(r,e){var n;const s=a(e);if(!s)return null;const u=Array.isArray((n=r==null?void 0:r.progress)==null?void 0:n.volumes_planned)?r.progress.volumes_planned:[];for(const t of u){const o=a(t==null?void 0:t.volume),l=i(t==null?void 0:t.chapters_range);if(o&&l&&l.start<=s&&s<=l.end)return o}return null}function g(r,e){const s=new Map;for(const u of r||[]){const n=c(e,u==null?void 0:u.chapter),t=n||0;s.has(t)||s.set(t,{volume:n,label:n?`卷 ${n}`:"未分卷",totalWords:0,chapterCount:0,values:[]});const o=s.get(t),l=Number((u==null?void 0:u.word_count)||0);o.totalWords+=Number.isFinite(l)?l:0,o.chapterCount+=1,Number.isFinite(l)&&l>0&&o.values.push(l)}return[...s.values()].sort((u,n)=>u.volume===null?1:n.volume===null?-1:(u.volume||0)-(n.volume||0))}export{m as a,g};
