import{selectorSpecificity as e,compare as t}from"../../../../@csstools/selector-specificity/dist/index.mjs";import{isDeclaration as s,isAtRule as o}from"../../utils/typeGuards.mjs";import r from"../../utils/findAtRuleContext.mjs";import i from"../../utils/flattenNestedSelectorsForRule.mjs";import n from"../../utils/getStrippedSelectorSource.mjs";import l from"../../utils/isStandardSyntaxRule.mjs";import c from"../../utils/nodeContextLookup.mjs";import m from"../../utils/normalizeSelector.mjs";import u from"../../utils/optionsMatches.mjs";import{pseudoElements as f}from"../../reference/selectors.mjs";import p from"../../utils/report.mjs";import a from"../../utils/ruleMessages.mjs";import d from"../../utils/validateOptions.mjs";const g="no-descending-specificity",j=a(g,{expected:(e,t,s)=>`Expected selector "${e}" to come before selector "${t}", at line ${s}`}),h=(s,o)=>(a,h)=>{if(!d(h,g,{actual:s},{optional:!0,actual:o,possible:{ignore:["selectors-within-list"]}}))return;const y=u(o,"ignore","selectors-within-list"),S=c();a.walkRules(s=>{if(!l(s))return;if(y&&s.selectors.length>1)return;if(!x(s))return;const o=S.getContext(s,r(s));i(s,h).forEach(({selector:r,resolvedSelectors:i})=>{i.each(i=>{!function(s,o,r,i){const l=function(e){if(0===e.nodes.length)return;e=m(e.clone());const t=e.split(e=>"combinator"===e.type),s=t[t.length-1];if(!s)return;const o=s.filter(e=>"pseudo"!==e.type||e.value.startsWith("::")||f.has(e.value.replaceAll(":","")));return 0===o.length?void 0:o.join("")}(s);if(!l)return;const c=e(s),u={selector:s.toString().trim(),specificity:c,line:r.source?.start?.line??1},a=i.get(l);if(!a)return void i.set(l,[u]);for(const e of a)if(t(c,e.specificity)<0){const{index:t,endIndex:s,selector:i}=n(o);p({ruleName:g,result:h,node:r,message:j.expected,messageArgs:[i,e.selector,e.line],index:t,endIndex:s});break}a.push(u)}(i,r,s,o)})})})};function x(e){return!!e.nodes&&e.some(e=>s(e)||o(e)&&x(e))}h.ruleName=g,h.messages=j,h.meta={url:"https://stylelint.io/user-guide/rules/no-descending-specificity"};export{h as default};