import{C as f}from"./codemirror-AHFfuqAu.js";import{f as b}from"./forEachState-DETpARGm.js";import{m,Y as h,Z as x,a4 as u,E as T,X as V}from"./index-B0EbEgFv.js";import"./codemirror-DpyRu-EA.js";function p(i,n,t){const r=L(t,g(n.string));if(!r)return;const e=n.type!==null&&/"|\w/.test(n.string[0])?n.start:n.end;return{list:r,from:{line:i.line,ch:e},to:{line:i.line,ch:n.end}}}function L(i,n){if(!n)return y(i,s=>!s.isDeprecated);const t=i.map(s=>({proximity:j(g(s.text),n),entry:s}));return y(y(t,s=>s.proximity<=2),s=>!s.entry.isDeprecated).sort((s,l)=>(s.entry.isDeprecated?1:0)-(l.entry.isDeprecated?1:0)||s.proximity-l.proximity||s.entry.text.length-l.entry.text.length).map(s=>s.entry)}function y(i,n){const t=i.filter(n);return t.length===0?i:t}function g(i){return i.toLowerCase().replaceAll(/\W/g,"")}function j(i,n){let t=v(n,i);return i.length>n.length&&(t-=i.length-n.length-1,t+=i.indexOf(n)===0?0:.5),t}function v(i,n){let t,r;const e=[],s=i.length,l=n.length;for(t=0;t<=s;t++)e[t]=[t];for(r=1;r<=l;r++)e[0][r]=r;for(t=1;t<=s;t++)for(r=1;r<=l;r++){const c=i[t-1]===n[r-1]?0:1;e[t][r]=Math.min(e[t-1][r]+1,e[t][r-1]+1,e[t-1][r-1]+c),t>1&&r>1&&i[t-1]===n[r-2]&&i[t-2]===n[r-1]&&(e[t][r]=Math.min(e[t][r],e[t-2][r-2]+c))}return e[s][l]}f.registerHelper("hint","graphql-variables",(i,n)=>{const t=i.getCursor(),r=i.getTokenAt(t),e=O(t,r,n);return e?.list&&e.list.length>0&&(e.from=f.Pos(e.from.line,e.from.ch),e.to=f.Pos(e.to.line,e.to.ch),f.signal(i,"hasCompletion",i,e,r)),e});function O(i,n,t){const r=n.state.kind==="Invalid"?n.state.prevState:n.state,{kind:e,step:s}=r;if(e==="Document"&&s===0)return p(i,n,[{text:"{"}]);const{variableToType:l}=t;if(!l)return;const c=N(l,n.state);if(e==="Document"||e==="Variable"&&s===0){const a=Object.keys(l);return p(i,n,a.map(o=>({text:`"${o}": `,type:l[o]})))}if((e==="ObjectValue"||e==="ObjectField"&&s===0)&&c.fields){const a=Object.keys(c.fields).map(o=>c.fields[o]);return p(i,n,a.map(o=>({text:`"${o.name}": `,type:o.type,description:o.description})))}if(e==="StringValue"||e==="NumberValue"||e==="BooleanValue"||e==="NullValue"||e==="ListValue"&&s===1||e==="ObjectField"&&s===2||e==="Variable"&&s===2){const a=c.type?m(c.type):void 0;if(a instanceof h)return p(i,n,[{text:"{"}]);if(a instanceof x){const o=a.getValues();return p(i,n,o.map(d=>({text:`"${d.name}"`,type:a,description:d.description})))}if(a===u)return p(i,n,[{text:"true",type:u,description:"Not false."},{text:"false",type:u,description:"Not true."}])}}function N(i,n){const t={type:null,fields:null};return b(n,r=>{switch(r.kind){case"Variable":{t.type=i[r.name];break}case"ListValue":{const e=t.type?T(t.type):void 0;t.type=e instanceof V?e.ofType:null;break}case"ObjectValue":{const e=t.type?m(t.type):void 0;t.fields=e instanceof h?e.getFields():null;break}case"ObjectField":{const e=r.name&&t.fields?t.fields[r.name]:null;t.type=e?.type;break}}}),t}
//# sourceMappingURL=hint-GWFK2YM8.js.map
