import{isFunction as e,isNumber as n,isRange as t,isPlainObject as r,isString as i}from"./validateTypes.mjs";import{DEFAULT_SEVERITY as s,SEVERITY_WARNING as o,SEVERITY_ERROR as a,RULE_NAME_ALL as l}from"../constants.mjs";import u from"./addSemicolonForEditInfo.mjs";import f from"./appendRuleName.mjs";import{emitDeprecationWarning as d}from"./emitWarning.mjs";import m from"./narrowFixRange.mjs";import c from"./rangesOverlap.mjs";function p(l){const{node:p,index:h,endIndex:I,line:O,start:N,end:b,result:P,ruleName:R,word:S,fix:E,...T}=l;!function(e){if(e.result.stylelint.quietDeprecationWarnings)return;e.node||d(`Omitting the \`node\` argument in the \`utils.report()\` function is deprecated ("${e.ruleName}").`,"REPORT_AMBIGUOUS_POSITION",`Please pass a \`node\` argument in the \`utils.report()\` function of "${e.ruleName}".`);t(e)||!("start"in e)&&!("end"in e)||d(`Partial position information in the \`utils.report()\` function is deprecated ("${e.ruleName}").`,"REPORT_AMBIGUOUS_POSITION",`Please pass both a valid \`start\` and \`end\` argument in the \`utils.report()\` function of "${e.ruleName}".`);i=e,r(i)&&n(i.index)&&n(i.endIndex)||!("index"in e)&&!("endIndex"in e)||d(`Partial position information in the \`utils.report()\` function is deprecated ("${e.ruleName}").`,"REPORT_AMBIGUOUS_POSITION",`Please pass both \`index\` and \`endIndex\` as arguments in the \`utils.report()\` function of "${e.ruleName}".`);var i;"line"in e&&d(`Providing the \`line\` argument in the \`utils.report()\` function is deprecated ("${e.ruleName}").`,"REPORT_AMBIGUOUS_POSITION",`Please pass both \`index\` and \`endIndex\` as arguments in the \`utils.report()\` function of "${e.ruleName}" instead.`)}(l);const{disabledRanges:v,quiet:$,ruleSeverities:U,config:{defaultSeverity:w,ignoreDisables:_}={},customMessages:{[R]:j=T.message},customUrls:{[R]:D},ruleMetadata:{[R]:M}}=P.stylelint,{messageArgs:A=[],severity:B=U[R]}=T,W=(e(B)?B(...A):B)??w??s;if($&&W===o)return;if((e(E)||y(E))&&M&&!M.fixable)throw new Error(`The "${R}" rule requires "meta.fixable" to be truthy if the "fix" callback is being passed`);const G=O??p?.rangeBy({index:h,endIndex:I}).start.line;if(!G)throw new Error(`The "${R}" rule failed to pass either a node or a line number to the \`report()\` function.`);if(function({fix:n,line:t,result:{stylelint:r},ruleName:i}){if(!n)return!1;const{disabledRanges:s,config:o={},fixersData:a}=r;if(!o.fix)return!1;if(x(t,i,o,s))return!1;const l=y(n)?n.apply:n;return!!e(l)&&(l(),function({fixersData:e,ruleName:n}){e[n]??=0,e[n]++}({fixersData:a,ruleName:i}),!0)}({...l,line:G}))return;if(g(R,G,v)){if((P.stylelint.disabledWarnings||=[]).push({rule:R,line:G}),!_)return}P.stylelint.stylelintError||W!==a||(P.stylelint.stylelintError=!0),P.stylelint.stylelintWarning||W!==o||(P.stylelint.stylelintWarning=!0);const q={severity:W,rule:R};p&&(q.node=p),N?q.start=N:n(h)&&(q.index=h),b?q.end=b:n(I)&&(q.endIndex=I),S&&(q.word=S),D&&(q.url=D),q.fix=function({fix:e,line:t,result:r,ruleName:i}){if(!e)return;const{disabledRanges:s,config:o={},rangesOfComputedEditInfos:a}=r.stylelint;if(!o.computeEditInfo||o.fix)return;if(x(t,i,o,s))return;if(!y(e)||!e.apply||!e.node)return;const{apply:l,node:f}=e;if(!n(f.source?.start?.offset)||!n(f.source?.end?.offset))return;const d=[f.source.start.offset,f.source.end.offset];if(a.some(e=>c(e,d)))return;l();let p={range:d,text:f.toString(r.opts?.syntax)};return p=u(f,p),p=m(f,p),a.push(p.range),p}({...l,line:G});const F=function(e,n,t){return f(i(e)?function(e,...n){return n.reduce((e,n)=>e.replace(/%[ds]/,String(n)),e)}(e,...n):e(...n),t)}(j,A,R);P.warn(F,q)}function g(e,n,t){const r=t[e]??t[l]??[];for(const t of r)if(t.start<=n&&(void 0===t.end||t.end>=n)&&(!t.rules||t.rules.includes(e)))return!0;return!1}function x(e,n,t,r){return!!t.rules?.[n][1]?.disableFix||!(t.ignoreDisables||!g(n,e,r))}function y(n){return!!r(n)&&(!!n.node&&!!e(n.apply))}export{p as default};