import{execFile as x}from"child_process";import{promisify as T}from"util";var d=T(x),S=async(s,e)=>{var h;let r=s.split(`
`),n=[],p=[],f;(o=>(o[o.Normal=0]="Normal",o[o.InOurs=1]="InOurs",o[o.InTheirs=2]="InTheirs"))(f||(f={}));let a=0;for(let t of r){if(t.startsWith("<<<<<<<")){a=1;continue}else if(t.startsWith("=======")){a===1&&(a=2);continue}else if(t.startsWith(">>>>>>>")){a===2&&(a=0);continue}switch(a){case 0:n.push(t),p.push(t);break;case 1:n.push(t);break;case 2:p.push(t);break}}let i=n.join(`
`),l=p.join(`
`),u=await d("git",["show",`:1:${e.filename}`],{maxBuffer:1024*1024*50}).then(({stdout:t})=>t).catch(()=>null);if(i===l&&(i=(h=await d("git",["show",`HEAD:${e.filename}`],{maxBuffer:1024*1024*50}).then(({stdout:t})=>t).catch(()=>null))!=null?h:i),!i||!l)throw new Error("Conflict parsing resulted in empty content.");let y=E(e),[P,c]=await w(i,y),[[g],m]=await Promise.all((u?[l,u]:[l]).map(t=>w(t,[c])));return{ours:P,theirs:g,base:m==null?void 0:m[0],format:typeof c=="string"?c:c.name}},j={json:"json",json5:"json5",yaml:"yaml",yml:"yaml",toml:"toml",xml:"xml"},E=s=>{var e,r;if(Array.isArray(s.parsers))return s.parsers;if(s.parsers)return s.parsers==="auto"?["json","json5","yaml","toml","xml"]:[s.parsers];if(s.filename){let n=j[(r=(e=s.filename.split(".").pop())==null?void 0:e.toLowerCase())!=null?r:""];if(n)return[n]}return["json"]},w=async(s,e)=>{for(let r of e)try{return typeof r!="string"?[r.parser(s),r]:[await C(r,s),r]}catch(n){console.debug(`Parser ${typeof r=="string"?r:r.name} failed:`,n)}throw new Error(`Failed to parse content. Tried parsers: ${e.map(r=>typeof r=="string"?r:r.name).join(", ")}`)},C=async(s,e)=>{switch(s){case"json":return JSON.parse(e);case"json5":try{let{parse:r}=await import("json5");return r(e)}catch{throw new Error("json5 parser not installed. Please install as peer dependency.")}case"yaml":try{let{parse:r}=await import("yaml");return r(e)}catch{throw new Error("yaml parser not installed. Please install as peer dependency.")}case"toml":try{let{parse:r}=await import("smol-toml");return r(e)}catch{throw new Error("toml parser not installed. Please install as peer dependency.")}case"xml":try{let{XMLParser:r}=await import("fast-xml-parser");return new r().parse(e)}catch{throw new Error("fast-xml-parser not installed. Please install as peer dependency.")}}};export{S as a,E as b,w as c,C as d};
