import{__awaiter as n,__generator as t}from"tslib";import{useState as e}from"react";var o=function(o,r,a,l){void 0===a&&(a=!0);var i=e(!1),s=i[0],c=i[1],u=e(null),d=u[0],p=u[1],f=e(null),m=f[0],v=f[1];return{validateRules:function(e,i){return n(void 0,void 0,void 0,function(){var n,s,u,d;return t(this,function(t){switch(t.label){case 0:if(!a)return[2,null];if(c(!0),p(null),v(null),0===(n={template_context:o,template_description:r,wta:e.wta.map(function(n){return n.text}),wnta:e.wnta.map(function(n){return n.text}),mode:"PromptGenie",llm_model:i}).wta.length)return console.error("WTA conditions cannot be empty."),v(new Error("When to Apply conditions cannot be empty.")),c(!1),[2,null];t.label=1;case 1:return t.trys.push([1,4,5,6]),[4,fetch("".concat(l,"/instant_learning/mode-wta-validation"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})];case 2:if(!(s=t.sent()).ok)throw new Error("API Error: ".concat(s.statusText));return[4,s.json()];case 3:return(u=t.sent()).response.is_valid?(console.log("Prompt Validation Successful!"),p(null)):(console.warn("Prompt Validation failed, conflicts found."),p(u.response)),[2,u.response];case 4:return d=t.sent(),console.error("Failed to validate prompt rules:",d),v(d),[2,null];case 5:return c(!1),[7];case 6:return[2]}})})},clearValidation:function(){p(null)},isSaving:s,validationResponse:d,error:m}};export{o as default};
//# sourceMappingURL=usePromptValidation.js.map
