import{tokenize as t,isTokenURL as e}from"../../../../@csstools/css-tokenizer/dist/index.mjs";import{declarationValueIndex as s,atRuleParamIndex as r}from"../../utils/nodeFieldIndices.mjs";import n from"../../utils/functionArgumentsSearch.mjs";import o from"../../utils/getAtRuleParams.mjs";import i from"../../utils/getDeclarationValue.mjs";import u from"../../utils/isStandardSyntaxDeclaration.mjs";import a from"../../utils/isStandardSyntaxUrl.mjs";import l from"../../utils/optionsMatches.mjs";import c from"../../utils/report.mjs";import m from"../../utils/ruleMessages.mjs";import f from"../../utils/validateOptions.mjs";const p="function-url-quotes",d=m(p,{expected:t=>`Expected quotes around "${t}" function argument`,rejected:t=>`Unexpected quotes around "${t}" function argument`}),g=/url\(/i,x=(m,x)=>(j,y)=>{if(!f(y,p,{actual:m,possible:["always","never"]},{actual:x,possible:{except:["empty"]},optional:!0}))return;const h=l(x,"except","empty"),w=new Set(["","''",'""']);function S(s,r,o){n(r,/^url$/i,(r,n,i,u)=>{const l=function(s,r){const n=s.trimStart();if(!a(n))return;let o="always"===m;h&&w.has(s.trim())&&(o=!o);const i=n.startsWith("'")||n.startsWith('"');if(i&&function(s){let r=s;const n=s[0]??"",o=s.lastIndexOf(n);o>0&&(r=s.slice(1,o));const i=t({css:`url(${r})`});if(2!==i.length)return!0;const u=i[0];return!e(u)}(n))return;if(o&&i)return;if(!o&&!i)return;const u=o?"expected":"rejected",l=r+s.length-n.length,c=r+s.length;return{messageType:u,index:l,endIndex:c}}(r,o+n);if(l){const{messageType:t,...e}=l,r=d[t],n=[i.value.toLowerCase()],o=function(t,e,s,r){return()=>{switch(s){case"expected":!function(t){for(const e of t.nodes)"word"===e.type&&(e.value=`"${e.value}"`)}(e);break;case"rejected":!function(t){for(const e of t.nodes)"string"===e.type&&(e.type="word")}(e)}switch(t.type){case"decl":t.value=r.toString();break;case"atrule":t.params=r.toString()}}}(s,i,t,u);c({...e,node:s,fix:{apply:o,node:s},message:r,messageArgs:n,result:y,ruleName:p})}})}j.walkAtRules(function(t){const e=o(t),s=r(t);S(t,e,s)}),j.walkDecls(function(t){if(!g.test(t.value))return;if(!u(t))return;const e=i(t),r=s(t);S(t,e,r)})};x.ruleName=p,x.messages=d,x.meta={url:"https://stylelint.io/user-guide/rules/function-url-quotes",fixable:!0};export{x as default};