import{relative as n,sep as t}from"node:path";import r from"node:process";import{s as e}from"../../../../_virtual/index17.mjs";import i from"../../../../_virtual/picocolors.mjs";import o from"../../../../_virtual/index18.mjs";import{assertNumber as s}from"../utils/validateTypes.mjs";import a from"./calcSeverityCounts.mjs";import c from"../utils/isUnicodeSupported.mjs";import l from"../utils/pluralize.mjs";import u from"./preprocessWarnings.mjs";import f from"./terminalLink.mjs";const{yellow:m,dim:d,underline:p,blue:g,red:w,green:$}=i,h=/\P{ASCII}/u;const j={info:g,warning:m,error:w,success:function(n){return n}},v=c(),x={info:g(v?"ℹ":"i"),warning:m(v?"⚠":"‼"),error:w(v?"✖":"×"),success:$(v?"✔":"√")};function S(i,a,c){if(0===i.length)return"";const l={0:1,1:1,2:1,3:1,4:1};let u="\n";function m(n){let t=n.text;t=t.replace(/[\u0001-\u001A]+/g," ").replace(/\.$/,"");const r=` (${n.rule})`;return t.endsWith(r)&&(t=t.slice(0,t.lastIndexOf(r))),t}a&&(u+=`${function(r,e){if(r.startsWith("<"))return p(r);const i=n(e,r).split(t).join("/");return f(i,`file://${r}`)}(a,c)}\n`);const g=i.map(n=>{const{line:t,column:r,severity:e}=n,i=[t?t.toString():"",r?r.toString():"",x[e]?j[e](x[e]):e,m(n),d(n.rule||"")];return function(n){for(const[t,r]of Object.entries(n)){const n=r?r.toString():r,e=l[t];s(e),l[t]=Math.max(e,o(n))}}(i),i}),w=function(n){const t=n[3];if(s(t),!r.stdout.isTTY)return t;const e=r.stdout.columns<80?80:r.stdout.columns,i=Object.values(n).reduce((n,t)=>n+t);return e>i+9?t:e-(i-t+9)}(l),$=i.some(n=>h.test(n.text));return u+=e.table(g,{border:e.getBorderCharacters("void"),columns:{0:{alignment:"right",width:l[0],paddingRight:0,paddingLeft:2},1:{alignment:"left",width:l[1]},2:{alignment:"center",width:l[2]},3:{alignment:"left",width:w,wrapWord:w>1&&!$},4:{alignment:"left",width:l[4],paddingRight:0}},drawHorizontalLine:()=>!1}).split("\n").map(n=>n.replace(/(\d+)\s+(\d+)/,(n,t,r)=>d(`${t}:${r}`)).trimEnd()).join("\n"),u}function b(n,t){let e=function(n){const t=n.flatMap(n=>(n.invalidOptionWarnings||[]).map(n=>n.text));return[...new Set(t)].reduce((n,t)=>(n+=w("Invalid Option: "),`${n+=t}\n`),"\n")}(n);e+=function(n){const t=n.flatMap(n=>n.deprecations||[]);if(0===t.length)return"";const r=new Set,e=[];for(const{text:n,reference:i}of t){if(r.has(n))continue;r.add(n);let t=` ${d("-")} ${n}`;i&&(t+=d(` See: ${p(i)}`)),e.push(t)}return["",m("Deprecation warnings:"),...e,""].join("\n")}(n);const i={error:0,warning:0},o={error:0,warning:0};if(e=n.reduce((n,e)=>{u(e),n+=S(e.warnings,e.source||"",t&&t.cwd||r.cwd());for(const n of e.warnings){a(n.severity,i);const r=t.ruleMetadata?.[n.rule]?.fixable;!0===r&&a(n.severity,o)}return n},e),e=e.trim(),""!==e){e=`\n${e}\n`;const n=i.error,t=i.warning,r=n+t;if(r>0){const i=w(`${n} ${l("error",n)}`),o=m(`${t} ${l("warning",t)}`);e+=`\n${n>0?x.error:x.warning} ${r} ${l("problem",r)} (${i}, ${o})`}const s=o.error,a=o.warning;if(s>0||a>0){let n,t;s>0&&(n=`${s} ${l("error",s)}`),a>0&&(t=`${a} ${l("warning",a)}`);e+=`\n  ${[n,t].filter(Boolean).join(" and ")} potentially fixable with the "--fix" option.`}e+="\n\n"}return e}export{b as default};