import{g as c,r as u}from"./api-DZ3cXm1m.js";const r=window.pageConfig||{};$(document).ready(function(){d()});async function l(s,e="GET",a=null){const o={method:e,headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:`Bearer ${c()}`}};a&&(o.body=JSON.stringify(a));let t=await fetch(s,o);if(t.status===401){const n=await u();n&&(o.headers.Authorization=`Bearer ${n}`,t=await fetch(s,o))}return t}function d(){$("#editTransactionForm").on("submit",async function(s){s.preventDefault();const e={status:$("#status").val(),payment_method:$("#payment_method").val()||null,payment_transaction_id:$("#payment_transaction_id").val()||null,bank_fee:$("#bank_fee").val()||null,description:$("#description").val()||null,notes:$("#notes").val()||null},a=$(this).find('button[type="submit"]');a.prop("disabled",!0);try{const o=await l(r.routes.update,"PUT",e),t=await o.json();if(t.success)i("success",t.message||r.translations.updated),setTimeout(()=>{window.location.href=r.routes.show},1500);else if(o.status===422&&t.errors){const n=Object.values(t.errors)[0];i("error",Array.isArray(n)?n[0]:n)}else i("error",t.message||r.translations.updateFailed)}catch{i("error",r.translations.updateFailed)}finally{a.prop("disabled",!1)}})}function i(s,e){s==="success"&&window.showSuccess?window.showSuccess(e):s==="error"&&window.showError?window.showError(e):window.showToast&&window.showToast(s,e)}
