import{r as p}from"./createLucideIcon-BcINIXoS.js";import{Y as S,H as m}from"../assets/admin-D0g83suT.js";const y=({form:n,api:i,setHasApiKey:o,onSuccess:r})=>{const[g,c]=p.useState(!1),s=window.replyan_ai_admin||{};return{saving:g,saveSettings:async l=>{var d;c(!0);try{const a={...s.settings,...l},t=new URLSearchParams;t.append("action","replyan_ai_save_settings"),t.append("nonce",s.nonce),t.append("settings",JSON.stringify(S(a)));const e=await(await fetch(s.ajaxUrl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},credentials:"same-origin",body:t})).json();if(!e.success)throw new Error(((d=e.data)==null?void 0:d.message)||"Settings could not be saved.");o&&o(!!e.data.apiKeySaved),r&&r(e.data),n&&n.setFieldsValue(m(e.data.settings)),s.settings=e.data.settings,i.success({message:"Settings saved."})}catch(a){i.error({message:a.message||"Settings could not be saved."})}finally{c(!1)}}}};export{y as u};
