import{__awaiter as e,__generator as t}from"tslib";import{useState as n,useEffect as o}from"react";import r from"./useDebounce.js";var s=function(s,i,a,c,p,u){void 0===p&&(p=!0);var l=n([]),d=l[0],f=l[1],h=n(!1),m=h[0],w=h[1],y=n(null),g=y[0],v=y[1],_=r(s,500),b=r(i,500);return o(function(){if(_&&b&&p){e(void 0,void 0,void 0,function(){var e,n,o,r,s,i,a;return t(this,function(t){switch(t.label){case 0:w(!0),v(null),t.label=1;case 1:return t.trys.push([1,4,5,6]),e={template_context:_,template_description:b,mode:"PromptGenie",llm:c,n:1},[4,fetch("".concat(u,"/instant_learning/mode-wta-suggestion"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 2:if(!(n=t.sent()).ok)throw new Error("API Error: ".concat(n.statusText));return[4,n.json()];case 3:return o=t.sent(),r=[],null===(i=o.response.conditions_whentoapply)||void 0===i||i.forEach(function(e){r.push({type:"wta",text:e.whentoapply,score:e.confidence_score,reason:e.reason})}),null===(a=o.response.conditions_whennottoapply)||void 0===a||a.forEach(function(e){r.push({type:"wnta",text:e.whennottoapply,score:e.confidence_score,reason:e.reason})}),f(r),[3,6];case 4:return s=t.sent(),console.error("Failed to fetch prompt suggestions:",s),v(s),[3,6];case 5:return w(!1),[7];case 6:return[2]}})})}else f([])},[_,b,a,p]),{suggestions:d,isLoading:m,error:g}};export{s as default};
//# sourceMappingURL=usePromptSuggestions.js.map
