import{sourceIndices as e,isFunctionNode as i}from"../../../../@csstools/css-parser-algorithms/dist/index.mjs";import{isMediaQueryInvalid as s,isGeneralEnclosed as t,isMediaFeaturePlain as r,isMediaFeatureRange as o,isMediaFeatureBoolean as n}from"../../../../@csstools/media-query-list-parser/dist/index.mjs";import{isString as m,isRegExp as a}from"../../utils/validateTypes.mjs";import{atRuleParamIndex as u}from"../../utils/nodeFieldIndices.mjs";import{atRuleRegexes as d}from"../../utils/regexes.mjs";import l from"../../utils/isCustomMediaQuery.mjs";import c from"../../utils/optionsMatches.mjs";import f from"../../utils/parseMediaQuery.mjs";import{rangeTypeMediaFeatureNames as p}from"../../reference/mediaFeatures.mjs";import g from"../../utils/report.mjs";import x from"../../utils/ruleMessages.mjs";import j from"../../utils/validateOptions.mjs";const v="media-query-no-invalid",_=x(v,{rejected:(e,i)=>i?`Unexpected invalid media query "${e}", ${i}`:`Unexpected invalid media query "${e}"`}),y={custom:"custom media queries can only be used in boolean queries",min_max_in_range:'"min-" and "max-" prefixes are not needed when using range queries',min_max_in_boolean:'"min-" and "max-" prefixes are not needed in boolean queries',discrete:"discrete features can only be used in plain and boolean queries"},q=/^(?:min|max)-/i,b=(i,c)=>(x,b)=>{function h(i,s,t,r){const[o,n]=e(t);g({message:_.rejected,messageArgs:[t.toString(),r?y[r]:""],index:s+o,endIndex:s+n+1,node:i,ruleName:v,result:b})}j(b,v,{actual:i},{actual:c,possible:{ignoreFunctions:[m,a]},optional:!0})&&x.walkAtRules(d.mediaName,e=>{const i=u(e);f(e).forEach(m=>{if(s(m)){if(N(m,c))return;h(e,i,m)}else m.walk(({node:s,parent:a})=>{if(t(s)){if(N(m,c))return;h(e,i,s)}else{if(r(s)){const t=s.getName();return l(t)?void h(e,i,a,"custom"):void 0}if(o(s)){const t=s.getName().toLowerCase();return l(t)?void h(e,i,a,"custom"):q.test(t)?void h(e,i,a,"min_max_in_range"):p.has(t)?void 0:void h(e,i,a,"discrete")}if(n(s)){const t=s.getName();q.test(t)&&h(e,i,a,"min_max_in_boolean")}}})})})};function N(e,s){if(!s?.ignoreFunctions)return!1;let t=!1;return e.walk(({node:e})=>{if(i(e))return t=c(s,"ignoreFunctions",e.getName()),!t&&void 0}),t}b.ruleName=v,b.messages=_,b.meta={url:"https://stylelint.io/user-guide/rules/media-query-no-invalid"};export{b as default};