import{a as b}from"./chunk-7L36YK2X.js";import"./chunk-NUFRM6SI.js";import{a as S}from"./chunk-HWKDQ44K.js";import{a as x,b as y}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var F={name:"wc",summary:"print newline, word, and byte counts for each file",usage:"wc [OPTION]... [FILE]...",options:["-c, --bytes      print the byte counts","-m, --chars      print the character counts","-l, --lines      print the newline counts","-w, --words      print the word counts","    --help       display this help and exit"]},H={lines:{short:"l",long:"lines",type:"boolean"},words:{short:"w",long:"words",type:"boolean"},bytes:{short:"c",long:"bytes",type:"boolean"},chars:{short:"m",long:"chars",type:"boolean"}},I={name:"wc",async execute(a,c){if(y(a))return x(F);let n=S("wc",a,H);if(!n.ok)return n.error;let{lines:r,words:s}=n.result.flags,e=n.result.flags.bytes||n.result.flags.chars,t=n.result.positional;!r&&!s&&!e&&(r=s=e=!0);let i=await b(c,t,{cmdName:"wc",stopOnError:!1});if(t.length===0){let o=C(i.files[0].content);return{stdout:`${g(o,r,s,e,"",0)}
`,stderr:"",exitCode:0}}let h=[],p=0,d=0,u=0;for(let{filename:o,content:w}of i.files){let f=C(w);p+=f.lines,d+=f.words,u+=f.chars,h.push({filename:o,stats:f})}let M=t.length>1?p:Math.max(...h.map(o=>o.stats.lines)),L=t.length>1?d:Math.max(...h.map(o=>o.stats.words)),$=t.length>1?u:Math.max(...h.map(o=>o.stats.chars)),l=t.length>1?3:0;r&&(l=Math.max(l,String(M).length)),s&&(l=Math.max(l,String(L).length)),e&&(l=Math.max(l,String($).length));let m="";for(let{filename:o,stats:w}of h)m+=`${g(w,r,s,e,o,l)}
`;return t.length>1&&(m+=`${g({lines:p,words:d,chars:u},r,s,e,"total",l)}
`),{stdout:m,stderr:i.stderr,exitCode:i.exitCode}}};function C(a){let c=a.length,n=0,r=0,s=!1;for(let e=0;e<c;e++){let t=a[e];t===`
`?(n++,s&&(r++,s=!1)):t===" "||t==="	"||t==="\r"?s&&(r++,s=!1):s=!0}return s&&r++,{lines:n,words:r,chars:c}}function g(a,c,n,r,s,e){let t=[];c&&t.push(String(a.lines).padStart(e)),n&&t.push(String(a.words).padStart(e)),r&&t.push(String(a.chars).padStart(e));let i=t.join(" ");return s&&(i+=` ${s}`),i}export{I as wcCommand};
