import{a as p,b as y}from"./chunk-SIWBT4LK.mjs";var A={defaultStrategy:["merge","ours"],include:["**/*.json","**/*.yaml","**/*.yml","**/*.xml","**/*.toml"],exclude:["**/node_modules/**","**/dist/**"],debug:!1,writeConflictSidecar:!1},E=async t=>{let{rules:e,byStrategy:r,defaultStrategy:n,matcher:s,plugins:a,pluginConfig:I,customStrategies:b,...F}={...A,...t},N=await O(a,I),z={...b,...N},g={exact:Object.create(null),exactFields:Object.create(null),patterns:Object.create(null),default:L(n)},C=typeof s=="string"?await y(s):s!=null?s:p,S=0;if(r)for(let[d,i]of Object.entries(r)){if(!i)continue;let{name:o,important:m}=x(d);for(let u of i){let{key:c,important:f}=h(u);R(g,c,{strategies:[{name:o,important:m||f}],order:S++,source:c})}}return e&&w(e,[],(d,i)=>{let{key:o,important:m}=h(d),u=i.map(c=>{let{name:f,important:j}=x(c);return{name:f,important:j||m}});R(g,o,{strategies:u,order:S++,source:o})}),{...F,rules:g,matcher:C,customStrategies:z}},L=t=>(Array.isArray(t)?t:[t]).map(r=>{let n=r.endsWith("!");return T(r.slice(0,-1)),{name:n?r.slice(0,-1):r,important:n}}),x=t=>{let e=t.endsWith("!"),r=e?t.slice(0,-1):t;return T(r),{name:r,important:e}},T=t=>{if(t.endsWith("!"))throw new Error(`Strategy name "${t}" must not end with "!". Use "!" on field/glob to mark rule importance.`)},h=t=>{let e=t.endsWith("!"),r=e?t.slice(0,-1):t;if(!r)throw new Error(`Invalid rule key "${t}".`);return{key:r,important:e}},R=(t,e,r)=>{if(/^\[.*\]$/.test(e)){let s=e.slice(1,-1);if(s.replace(/\\\./g,"").includes(".")||s.trim()==="")throw new Error(`Invalid bracket form "${e}". Use a single bare key like "[id]".`);let a=`**.${s}.**`;l(t.patterns,a,r);return}if(/[*?[\]]/.test(e)){l(t.patterns,e,r);return}e.includes(".")?l(t.exact,e,r):l(t.exactFields,e,r)},w=(t,e,r)=>{for(let[n,s]of Object.entries(t)){let a=[...e,n];Array.isArray(s)?r(a.join("."),s):w(s,a,r)}},l=(t,e,r)=>{var s;((s=t[e])!=null?s:t[e]=[]).push(r)},O=async(t,e)=>{if(!(t!=null&&t.length))return{};let r={};for(let n of t)try{let s=await import(n),a=s.default||s;if(!a.strategies)throw new Error(`Plugin "${n}" does not export strategies`);a.init&&(e!=null&&e[n])&&await a.init(e[n]),Object.assign(r,a.strategies)}catch(s){throw new Error(`Failed to load plugin "${n}": ${s}`)}return r};export{A as a,E as b};
