import{f as e,t}from"./useQuery-DxCFSWSJ.js";import{t as n}from"./useMutation-DW0aP2vQ.js";import{n as r}from"./errorHandler-BvCwSv90.js";import{t as i}from"./reportService-juyRkzHx.js";var a={all:[`layout-templates`],templates:()=>[...a.all,`list`],templatesList:e=>[...a.templates(),e],template:e=>[...a.all,`detail`,e],variables:e=>[...a.all,`variables`,e],supportedFormats:()=>[...a.all,`supported-formats`]};function o(e,n){return t({queryKey:a.variables(e),queryFn:async()=>await i.getTemplateVariables(e),...n,enabled:!!e&&(n?.enabled??!0)})}function s(t){let o=e();return n({...t,mutationFn:async e=>await i.uploadXMLTemplate(e),onSuccess:async(...e)=>{o.invalidateQueries({queryKey:a.templates()}),t?.onSuccess&&await t.onSuccess(...e)},onError:async(e,n,i)=>{t?.onError?await t.onError(e,n,i):r(e,`Failed to upload template`)}})}function c(t){let o=e();return n({...t,mutationFn:async({id:e,mappings:t})=>await i.saveVariableMappings(e,t),onSuccess:async(...e)=>{let[n]=e;o.setQueryData(a.template(n.id),n),o.invalidateQueries({queryKey:a.templates()}),t?.onSuccess&&await t.onSuccess(...e)},onError:async(e,n,i)=>{t?.onError?await t.onError(e,n,i):r(e,`Failed to save variable mappings`)}})}function l(t){let o=e();return n({...t,mutationFn:async({id:e,overrides:t})=>await i.convertTemplateToLayout(e,t),onSuccess:async(...e)=>{let[,n]=e;o.invalidateQueries({queryKey:a.templates()}),o.invalidateQueries({queryKey:a.template(n.id)}),o.invalidateQueries({queryKey:[`reports`,`print-layouts`]}),t?.onSuccess&&await t.onSuccess(...e)},onError:async(e,n,i)=>{t?.onError?await t.onError(e,n,i):r(e,`Failed to convert template to layout`)}})}export{o as i,c as n,s as r,l as t};