import{E as e,Ht as t,Q as n,R as r,W as i,X as a,_ as o,b as s,ut as c,v as l,w as u,y as d}from"./vue.runtime.esm-bundler-56z_v_HH.js";import{t as f}from"./notification.store-EczSZ_VB.js";import{n as p,r as m}from"./error-handling-S7N4FACK.js";import{n as h}from"./vue-i18n-DhldrKy8.js";import{t as g}from"./ai.service-wdG_24oJ.js";import{t as _}from"./AiConfigurationForm-CPJIXij0.js";var v={class:`mt-8`},y={key:0,class:`mt-6 p-4 rounded bg-alert-success-bg text-alert-success-text text-sm`},b={key:1,class:`mt-8`},x=e({__name:`AiConfigView`,setup(e){let{t:x}=h(),S=f(),C=c(!1),w=c(!1),T=c(!1),E=c(!1),D=c(null),O=c([]);k();async function k(){T.value=!0;try{let[e,t]=await Promise.all([g.getDrivers(),g.getCompanyConfig()]);O.value=e.ai_drivers,D.value=t,E.value=t.use_custom_ai_config===`YES`}catch(e){let t=m(e);S.showNotification({type:`error`,message:p(t.message)??t.message})}finally{T.value=!1}}a(E,async(e,t)=>{if(t!==void 0&&!e){C.value=!0;try{await g.saveCompanyConfig({use_custom_ai_config:`NO`}),D.value&&(D.value.use_custom_ai_config=`NO`),S.showNotification({type:`success`,message:`settings.ai.saved`})}catch(e){let t=m(e);S.showNotification({type:`error`,message:p(t.message)??t.message}),E.value=!0}finally{C.value=!1}}});async function A(e){C.value=!0;try{let t={...e,use_custom_ai_config:`YES`};(await g.saveCompanyConfig(t)).success&&(S.showNotification({type:`success`,message:`settings.ai.saved`}),D.value=t)}catch(e){let t=m(e);S.showNotification({type:`error`,message:p(t.message)??t.message})}finally{C.value=!1}}async function j(e){w.value=!0;try{let t=await g.testCompanyConnection(e);t.success?S.showNotification({type:`success`,message:`settings.ai.test_success`}):t.error&&S.showNotification({type:`error`,message:x(`settings.ai.errors.`+t.error,{error:t.message??``})})}catch(e){let t=m(e);S.showNotification({type:`error`,message:p(t.message)??t.message})}finally{w.value=!1}}return(e,a)=>{let c=i(`BaseSwitchSection`),f=i(`BaseSettingCard`);return r(),l(f,{title:e.$t(`settings.ai.title`),description:e.$t(`settings.ai.description`)},{default:n(()=>[o(`div`,v,[u(c,{modelValue:E.value,"onUpdate:modelValue":a[0]||=e=>E.value=e,title:e.$t(`settings.ai.use_custom_ai_config`),description:e.$t(`settings.ai.use_custom_ai_config_desc`)},null,8,[`modelValue`,`title`,`description`])]),E.value?d(``,!0):(r(),s(`div`,y,t(e.$t(`settings.ai.using_global_ai_config`)),1)),E.value&&D.value?(r(),s(`div`,b,[u(_,{"config-data":D.value,drivers:O.value,"is-saving":C.value,"is-testing":w.value,"is-fetching-initial-data":T.value,onSubmitData:A,onTestConnection:j},null,8,[`config-data`,`drivers`,`is-saving`,`is-testing`,`is-fetching-initial-data`])])):d(``,!0)]),_:1},8,[`title`,`description`])}}});export{x as default};