import e from"postcss-value-parser";const creator=o=>{const t=Object.assign({functionName:"csstools-if"},o);return{postcssPlugin:"postcss-conditional-values",prepare(){const o=new Map,s=new Set,r=new Set;return{postcssPlugin:"postcss-conditional-values",Declaration(n,{postcss:a}){if(!n.value.toLowerCase().includes(t.functionName))return;const u=e(n.value);let l="";const i=[];let c=!1;const p=[];if(u.walk(o=>{if("function"===o.type&&o.nodes&&o.value.toLowerCase()===t.functionName)return o.nodes.forEach(o=>{l||"word"!==o.type||"--"!==o.value.slice(0,2)?l&&("word"!==o.type||"else"!==o.value?c?p.push(o):i.push(o):c=!0):l=e.stringify(o).trim()}),!1}),!l)return;if(i.some(e=>"div"===e.type&&","===e.value))return;if(p.some(e=>"div"===e.type&&","===e.value))return;const d=e.stringify(i).trim(),f=e.stringify(p).trim();if(d&&f){{const s=o.get(l)||0;o.set(l,s+1);const r=`${l}--${s}`;n.cloneBefore({prop:r,value:`var(${l}) ${f}`}),u.walk(o=>{if("function"===o.type&&o.nodes&&o.value.toLowerCase()===t.functionName)return o.value="var",o.nodes=[...e(r).nodes,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""},...e(d).nodes],!1}),n.cloneBefore({value:u.toString()})}if(!s.has(l)&&(n.root().walkDecls(l,e=>{e.prop===l&&(""!==e.value.trim()?"true"===e.value.trim().toLowerCase()?e.value="initial":"false"===e.value.trim().toLowerCase()&&(e.value=" ",r.add(l)):r.add(l))}),s.add(l),!r.has(l))){let e;r.add(l),n.root().each(o=>{if("rule"===o.type&&":root"===o.selector)return e=o,!1}),e||(e=a.rule({selector:":root",source:n.source,raws:{before:"",after:"\n",between:" "}}),n.root().prepend(e));const o=a.decl({value:" ",prop:l,raws:{before:"\n\t"}});o.source=n.source,e.append(o)}n.remove()}}}}}};creator.postcss=!0;export{creator as default,creator as"module.exports"};
