import{isString as e,isRegExp as s}from"../../utils/validateTypes.mjs";import t from"../../utils/fixEmptyLinesBefore.mjs";import r from"../../utils/getPreviousNonSharedLineCommentNode.mjs";import o from"../../utils/hasEmptyLine.mjs";import l from"../../utils/isAfterComment.mjs";import{isAtRule as i}from"../../utils/typeGuards.mjs";import m from"../../utils/isBlocklessAtRuleAfterBlocklessAtRule.mjs";import n from"../../utils/isBlocklessAtRuleAfterSameNameBlocklessAtRule.mjs";import a from"../../utils/isFirstNested.mjs";import f from"../../utils/isFirstNodeOfRoot.mjs";import u from"../../utils/isStandardSyntaxAtRule.mjs";import c from"../../utils/optionsMatches.mjs";import p from"../../utils/report.mjs";import d from"../../utils/ruleMessages.mjs";import b from"../../utils/validateOptions.mjs";const k="at-rule-empty-line-before",j=d(k,{expected:"Expected empty line before at-rule",rejected:"Unexpected empty line before at-rule"}),g=(d,g,x)=>(y,A)=>{if(!b(A,k,{actual:d,possible:["always","never"]},{actual:g,possible:{except:["after-same-name","inside-block","blockless-after-same-name-blockless","blockless-after-blockless","first-nested"],ignore:["after-comment","first-nested","inside-block","blockless-after-same-name-blockless","blockless-after-blockless"],ignoreAtRules:[e,s]},optional:!0}))return;const R=d;y.walkAtRules(e=>{const s=e.parent&&"root"!==e.parent.type;if(f(e))return;if(!u(e))return;if(c(g,"ignoreAtRules",e.name))return;if(c(g,"ignore","blockless-after-blockless")&&m(e))return;if(c(g,"ignore","first-nested")&&a(e))return;if(c(g,"ignore","blockless-after-same-name-blockless")&&n(e))return;if(c(g,"ignore","inside-block")&&s)return;if(c(g,"ignore","after-comment")&&l(e))return;const d=o(e.raws.before);let b="always"===R;if((c(g,"except","after-same-name")&&function(e){const s=r(e);return s&&i(s)&&s.name===e.name}(e)||c(g,"except","inside-block")&&s||c(g,"except","first-nested")&&a(e)||c(g,"except","blockless-after-blockless")&&m(e)||c(g,"except","blockless-after-same-name-blockless")&&n(e))&&(b=!b),b===d)return;const y=b?j.expected:j.rejected,N=b?"add":"remove";p({message:y,messageArgs:[],node:e,result:A,ruleName:k,fix:{apply:()=>t({node:e,newline:x.newline,action:N}),node:e.parent}})})};g.ruleName=k,g.messages=j,g.meta={url:"https://stylelint.io/user-guide/rules/at-rule-empty-line-before",fixable:!0};export{g as default};