import T from"jquery";import"./datatables-bbQliV7G.js";import{T as $}from"./bootstrap.esm-Bb7dPm-H.js";import{d as j}from"./datatables-CdFC5o1t.js";import{s as m}from"./toastr-helper-Wdj0mZjX.js";/* empty css                                  */document.addEventListener("DOMContentLoaded",function(){const b=document.getElementById("paymentGateways").dataset.recordsUrl,h=T("#paymentGateways").DataTable({...j.getDefaultConfig(),serverSide:!1,searching:!0,paging:!1,info:!1,lengthChange:!1,dom:'<"d-flex justify-content-end mb-3"f>t',order:[[4,"asc"]],ajax:{url:b,type:"GET",dataSrc:"data",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},error:function(e){var r,l,n;e.status===401?window.location.reload():m("danger",((n=(l=(r=window.translations)==null?void 0:r.paymentGateways)==null?void 0:l.messages)==null?void 0:n.load_error)||"Veriler yüklenirken bir hata oluştu.")}},columns:[{data:"logo",name:"logo",orderable:!1,searchable:!1,render:function(e,r,l){return e?`<img src="${e}" alt="${l.label}" style="width: 48px; height: 48px; object-fit: contain; border-radius: 4px;">`:'<div style="width: 48px; height: 48px; background-color: #f8f9fa; border: 1px solid #dee2e6; border-radius: 4px; display: flex; align-items: center; justify-content: center;"><i class="fas fa-image text-muted"></i></div>'},className:"text-center"},{data:"label",name:"label",render:function(e,r,l){return`<strong>${e}</strong>`}},{data:"description",name:"description"},{data:"version",name:"version",className:"text-center"},{data:"active",name:"active",render:function(e,r,l){var n,s,i,t,a,o;return e===!0||e===1||e==="true"||e==="1"?`<span class="badge bg-success">${((i=(s=(n=window.translations)==null?void 0:n.paymentGateways)==null?void 0:s.status)==null?void 0:i.active)||"Active"}</span>`:`<span class="badge bg-danger">${((o=(a=(t=window.translations)==null?void 0:t.paymentGateways)==null?void 0:a.status)==null?void 0:o.inactive)||"Inactive"}</span>`},className:"text-center"},{data:"test_mode",name:"test_mode",render:function(e,r,l){var n,s,i,t,a,o;return e===!0||e===1||e==="true"||e==="1"?`<span class="badge bg-warning">${((i=(s=(n=window.translations)==null?void 0:n.paymentGateways)==null?void 0:s.test_mode)==null?void 0:i.enabled)||"Etkin"}</span>`:`<span class="badge bg-secondary">${((o=(a=(t=window.translations)==null?void 0:t.paymentGateways)==null?void 0:a.test_mode)==null?void 0:o.disabled)||"Disabled"}</span>`},className:"text-center"},{data:"name",name:"actions",orderable:!1,searchable:!1,render:function(e,r,l){var s,i,t,a,o,d,c,u,p,w,y,f,g;const n=[];if((i=(s=window.permissions)==null?void 0:s.paymentGateways)!=null&&i.update){const E=window.routes.paymentGateways.edit.replace(":name",e);n.push(`
                            <a href="${E}" 
                               class="btn btn-sm btn-outline-primary d-inline-flex align-items-center justify-content-center" 
                               style="width: 32px; height: 32px;"
                               data-bs-toggle="tooltip" 
                               title="${((o=(a=(t=window.translations)==null?void 0:t.common)==null?void 0:a.buttons)==null?void 0:o.edit)||"Edit"}">
                                <i class="fas fa-edit"></i>
                            </a>`)}return n.push(`
                        <button type="button"
                                class="btn btn-sm btn-outline-info d-inline-flex align-items-center justify-content-center ms-1 test-gateway"
                                style="width: 32px; height: 32px;"
                                data-id="${e}"
                                data-bs-toggle="tooltip"
                                title="${((u=(c=(d=window.translations)==null?void 0:d.paymentGateways)==null?void 0:c.messages)==null?void 0:u.test_connection)||"Test Et"}">
                            <i class="fas fa-vial"></i>
                        </button>`),(w=(p=window.permissions)==null?void 0:p.paymentGateways)!=null&&w.delete&&n.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-gateway"
                                    style="width: 32px; height: 32px;"
                                    data-id="${e}"
                                    data-bs-toggle="tooltip"
                                    title="${((g=(f=(y=window.translations)==null?void 0:y.common)==null?void 0:f.buttons)==null?void 0:g.delete)||"Delete"}">
                                <i class="fas fa-trash"></i>
                            </button>`),n.length===0?'<span class="text-muted">-</span>':`<div class="d-inline-flex">${n.join("")}</div>`},className:"text-center"}],drawCallback:function(){v(),document.querySelectorAll(".delete-gateway").forEach(e=>{e.addEventListener("click",function(){const r=this.getAttribute("data-id");x(r)})}),document.querySelectorAll(".test-gateway").forEach(e=>{e.addEventListener("click",function(){const r=this.getAttribute("data-id");G(r)})})}});async function x(e){var n,s,i;if(!await window.showConfirm(((i=(s=(n=window.translations)==null?void 0:n.common)==null?void 0:s.messages)==null?void 0:i.confirm_delete)||"Bu payment gateway'i silmek istediğinizden emin misiniz?",{confirmClass:"btn-danger",icon:"warning"}))return;const l=window.routes.paymentGateways.delete.replace(":name",e);fetch(l,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")}}).then(t=>t.json()).then(t=>{var a,o,d,c,u,p;t.status==="success"?(m("success",t.message||((d=(o=(a=window.translations)==null?void 0:a.paymentGateways)==null?void 0:o.success)==null?void 0:d.deleted)||"Payment gateway başarıyla silindi."),h.ajax.reload()):m("danger",t.message||((p=(u=(c=window.translations)==null?void 0:c.paymentGateways)==null?void 0:u.error)==null?void 0:p.delete_failed)||"Payment gateway silinirken bir hata oluştu.")}).catch(t=>{var a,o,d;console.error("Error:",t),m("danger",((d=(o=(a=window.translations)==null?void 0:a.paymentGateways)==null?void 0:o.error)==null?void 0:d.delete_failed)||"Payment gateway silinirken bir hata oluştu.")})}function G(e){const r=window.routes.paymentGateways.test.replace(":name",e),l=document.querySelector(`.test-gateway[data-id="${e}"] i`),n=l.className;l.className="fas fa-spinner fa-spin",fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")}}).then(s=>s.json()).then(s=>{var i,t,a,o,d,c;s.status==="success"?m("success",s.message||((a=(t=(i=window.translations)==null?void 0:i.paymentGateways)==null?void 0:t.messages)==null?void 0:a.test_success)||"Test başarılı."):m("danger",s.message||((c=(d=(o=window.translations)==null?void 0:o.paymentGateways)==null?void 0:d.messages)==null?void 0:c.test_failed)||"Test başarısız.")}).catch(s=>{var i,t,a;console.error("Error:",s),m("danger",((a=(t=(i=window.translations)==null?void 0:i.paymentGateways)==null?void 0:t.messages)==null?void 0:a.test_failed)||"Test sırasında bir hata oluştu.")}).finally(()=>{l.className=n})}function v(){[...document.querySelectorAll('[data-bs-toggle="tooltip"]')].map(r=>new $(r,{boundary:document.body}))}});
