import{isMediaQueryInvalid as e,isMediaFeatureRange as t,isMediaFeaturePlain as r,isMediaFeatureRangeNameValue as s,isMediaFeatureRangeValueName as a,isMediaFeature as o,MediaFeatureRangeNameValue as i,MediaFeatureName as n}from"../../../../@csstools/media-query-list-parser/dist/index.mjs";import{sourceIndices as m,TokenNode as l}from"../../../../@csstools/css-parser-algorithms/dist/index.mjs";import{TokenType as p}from"../../../../@csstools/css-tokenizer/dist/index.mjs";import{atRuleParamIndex as u}from"../../utils/nodeFieldIndices.mjs";import{atRuleRegexes as d}from"../../utils/regexes.mjs";import f from"../../utils/optionsMatches.mjs";import c from"../../utils/parseMediaQuery.mjs";import{rangeTypeMediaFeatureNames as x}from"../../reference/mediaFeatures.mjs";import g from"../../utils/report.mjs";import v from"../../utils/ruleMessages.mjs";import j from"../../utils/validateOptions.mjs";const h="media-feature-range-notation",w=v(h,{expected:e=>`Expected "${e}" media feature range notation`}),y=(v,y)=>(D,b)=>{if(!j(b,h,{actual:v,possible:["prefix","context"]},{actual:y,possible:{except:["exact-value"]},optional:!0}))return;const k=f(y,"except","exact-value");D.walkAtRules(d.mediaName,d=>{const f=c(d);f.forEach(c=>{e(c)||c.walk(({node:e,parent:c})=>{if(!t(e)&&!r(e))return;const j=e.getName(),y=j.replace(/^(?:min|max)-/i,"");if(!x.has(y))return;let D=v;if(k){const t=(s(e)||a(e))&&1===e.operator.length&&"="===e.operator[0][1],o=r(e)&&j.length===y.length;(t||o)&&(D="prefix"===v?"context":"prefix")}if("prefix"===D&&r(e))return;if("context"===D&&t(e))return;const N="context"===D&&r(e)&&o(c)?(I={node:e,parent:c},()=>{let e;e=/^min-/i.test(j)?[[p.Delim,">",-1,-1,{value:">"}],[p.Delim,"=",-1,-1,{value:"="}]]:/^max-/i.test(j)?[[p.Delim,"<",-1,-1,{value:"<"}],[p.Delim,"=",-1,-1,{value:"="}]]:[[p.Delim,"=",-1,-1,{value:"="}]],I.parent.feature=new i(new n(new l([p.Ident,y,-1,-1,{value:y}]),I.node.name.before,I.node.name.after.length>0?I.node.name.after:[[p.Whitespace," ",-1,-1,void 0]]),e,I.node.value);const t=f.map(e=>e.toString()).join(",");t!==d.params&&(d.params=t)}):void 0;var I;const[M,A]=m(e),E=u(d);g({message:w.expected,messageArgs:[D],node:d,index:E+M-1,endIndex:E+A+1+1,result:b,ruleName:h,fix:{apply:N,node:d}})})})})};y.ruleName=h,y.messages=w,y.meta={url:"https://stylelint.io/user-guide/rules/media-feature-range-notation",fixable:!0};export{y as default};