import j from"jquery";import"./datatables-bbQliV7G.js";import{M as $,T as M}from"./bootstrap.esm-Bb7dPm-H.js";import{d as S}from"./datatables-CdFC5o1t.js";import{s as l}from"./toastr-helper-Wdj0mZjX.js";/* empty css                       *//* empty css                                  */document.addEventListener("DOMContentLoaded",function(){const B=document.getElementById("currenciesTable"),y=document.getElementById("saveCurrencyBtn"),m=document.getElementById("currencyForm"),p=document.getElementById("currencyId"),_=document.getElementById("currencyModalLabel"),d=document.getElementById("updateRatesBtn"),w=new $(document.getElementById("currencyModal")),L=B.dataset.recordsUrl;let f="";h(),d&&d.addEventListener("click",function(){k()});const g=j("#currenciesTable").DataTable({...S.getDefaultConfig(),serverSide:!0,ordering:!1,dom:'<"d-flex justify-content-between align-items-center mb-3"<"d-flex align-items-center"l><"d-flex align-items-center"f>>t<"d-flex justify-content-between align-items-center mt-3"<"d-flex align-items-center"i><"d-flex align-items-center"p>>',ajax:{url:L,type:"GET",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},error:function(e){var t,n,r;e.status===401?window.location.reload():l("danger",((r=(n=(t=window.translations)==null?void 0:t.currencies)==null?void 0:n.messages)==null?void 0:r.load_error)||"Veriler yüklenirken bir hata oluştu.")}},columns:[{data:"id",name:"id"},{data:"name",name:"name",render:function(e,t,n){return n.country?`<span class="fi fi-${n.country.toLowerCase()} me-2"></span> ${e}`:e}},{data:"code",name:"code"},{data:"prefix",name:"prefix",render:function(e){return e||"-"}},{data:"suffix",name:"suffix",render:function(e){return e||"-"}},{data:"rate",name:"rate",render:function(e){return parseFloat(e).toFixed(5)}},{data:"is_default",name:"is_default",render:function(e){var t,n,r;return e==1?`<span class="badge bg-info">${((r=(n=(t=window.translations)==null?void 0:t.currencies)==null?void 0:n.status)==null?void 0:r.default)||"Default"}</span>`:"-"}},{data:"status",name:"status",render:function(e){var t,n,r,s,i,a;return e==1?`<span class="badge bg-success">${((r=(n=(t=window.translations)==null?void 0:t.currencies)==null?void 0:n.status)==null?void 0:r.active)||"Active"}</span>`:`<span class="badge bg-danger">${((a=(i=(s=window.translations)==null?void 0:s.currencies)==null?void 0:i.status)==null?void 0:a.inactive)||"Inactive"}</span>`}},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(e,t,n){var s,i,a,o,c;const r=[];return(i=(s=window.permissions)==null?void 0:s.currencies)!=null&&i.update&&r.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-primary d-inline-flex align-items-center justify-content-center edit-currency"
                                    style="width: 32px; height: 32px;"
                                    data-id="${e}"
                                    data-bs-toggle="tooltip"
                                    title="${((c=(o=(a=window.translations)==null?void 0:a.currencies)==null?void 0:o.buttons)==null?void 0:c.edit)||"Edit"}">
                                <i class="fas fa-edit"></i>
                            </button>`),r.length===0?'<span class="text-muted">-</span>':`<div class="d-inline-flex">${r.join("")}</div>`}}],drawCallback:function(){C(),E(),document.querySelectorAll(".edit-currency").forEach(e=>{e.addEventListener("click",function(){const t=this.getAttribute("data-id");T(t)})})}});y&&y.addEventListener("click",function(){b()}),m&&m.addEventListener("submit",function(e){e.preventDefault(),b()});function b(){const e=new FormData(m),t=p.value;if(!A())return;const n=document.getElementById("is_default").checked,r={name:e.get("name"),prefix:e.get("prefix")||"",suffix:e.get("suffix")||"",rate:e.get("rate"),is_default:n,status:e.get("status")==="1"},s=window.routes.currencies.update.replace(":id",t);fetch(s,{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},body:JSON.stringify(r)}).then(a=>a.json()).then(a=>{a.success?(l("success",a.message),w.hide(),v(),g.ajax.reload()):(l("danger",a.message),a.errors&&Object.keys(a.errors).forEach(o=>{const c=document.getElementById(o+"_error");c&&(c.textContent=a.errors[o][0],document.getElementById(o).classList.add("is-invalid"))}))}).catch(a=>{var o,c,u;console.error("Error:",a),l("danger",((u=(c=(o=window.translations)==null?void 0:o.currencies)==null?void 0:c.messages)==null?void 0:u.save_error)||"Kaydetme sırasında bir hata oluştu.")})}function T(e){var n,r,s,i,a,o;const t=g.rows().data().toArray().find(c=>c.id==e);t?(v(),p.value=t.id,document.getElementById("name").value=t.name,document.getElementById("code").value=t.code,document.getElementById("code").setAttribute("readonly","readonly"),document.getElementById("prefix").value=t.prefix||"",document.getElementById("suffix").value=t.suffix||"",document.getElementById("rate").value=t.rate,document.getElementById("is_default").checked=t.is_default==1,t.status==1?document.getElementById("status_active").checked=!0:document.getElementById("status_inactive").checked=!0,_.innerHTML=`
                <i class="fas fa-edit me-2"></i>
                <span class="fi fi-${t.country?t.country.toLowerCase():""} me-2"></span>
                ${((s=(r=(n=window.translations)==null?void 0:n.currencies)==null?void 0:r.modal)==null?void 0:s.edit_title)||"Para Birimi Düzenle"}
            `,w.show()):l("danger",((o=(a=(i=window.translations)==null?void 0:i.currencies)==null?void 0:a.messages)==null?void 0:o.not_found)||"Para birimi kaydı bulunamadı.")}function v(){m.reset(),p.value="",document.getElementById("code").removeAttribute("readonly"),document.querySelectorAll(".is-invalid").forEach(e=>{e.classList.remove("is-invalid")}),document.querySelectorAll(".invalid-feedback").forEach(e=>{e.textContent=""})}function A(){var r,s,i,a,o,c,u,I,x;let e=!0;const t=document.getElementById("name"),n=document.getElementById("rate");return t.value.trim()?(t.classList.remove("is-invalid"),document.getElementById("name_error").textContent=""):(document.getElementById("name_error").textContent=((i=(s=(r=window.translations)==null?void 0:r.currencies)==null?void 0:s.validation)==null?void 0:i.name_required)||"Para birimi adı gereklidir.",t.classList.add("is-invalid"),e=!1),n.value?isNaN(n.value)||parseFloat(n.value)<0?(document.getElementById("rate_error").textContent=((x=(I=(u=window.translations)==null?void 0:u.currencies)==null?void 0:I.validation)==null?void 0:x.rate_invalid)||"Kur değeri geçerli bir sayı olmalıdır.",n.classList.add("is-invalid"),e=!1):(n.classList.remove("is-invalid"),document.getElementById("rate_error").textContent=""):(document.getElementById("rate_error").textContent=((c=(o=(a=window.translations)==null?void 0:a.currencies)==null?void 0:o.validation)==null?void 0:c.rate_required)||"Kur değeri gereklidir.",n.classList.add("is-invalid"),e=!1),e}function C(){[...document.querySelectorAll('[data-bs-toggle="tooltip"]')].map(t=>new M(t,{boundary:document.body}))}function k(){var e,t,n;d&&(d.disabled=!0,d.innerHTML=`<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> ${((n=(t=(e=window.translations)==null?void 0:e.currencies)==null?void 0:t.buttons)==null?void 0:n.update_rates)||"Kurları Güncelle"}`),fetch(window.routes.currencies.rates.update,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")}}).then(r=>r.json()).then(r=>{var s,i,a;r.success?(l("success",r.message),g.ajax.reload(),h()):l("danger",r.message||((a=(i=(s=window.translations)==null?void 0:s.currencies)==null?void 0:i.messages)==null?void 0:a.rates_update_error))}).catch(r=>{var s,i,a;console.error("Error:",r),l("danger",((a=(i=(s=window.translations)==null?void 0:s.currencies)==null?void 0:i.messages)==null?void 0:a.rates_update_error)||"Kur güncelleme sırasında bir hata oluştu.")}).finally(()=>{var r,s,i;d&&(d.disabled=!1,d.innerHTML=`<i class="fas fa-sync-alt me-2"></i> ${((i=(s=(r=window.translations)==null?void 0:r.currencies)==null?void 0:s.buttons)==null?void 0:i.update_rates)||"Kurları Güncelle"}`)})}function h(){fetch(window.routes.currencies.rates.info,{method:"GET",headers:{Accept:"application/json",Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")}}).then(e=>e.json()).then(e=>{var t,n,r,s,i,a;if(e.success){const o=((r=(n=(t=window.translations)==null?void 0:t.currencies)==null?void 0:n.messages)==null?void 0:r.rates_last_updated)||"Exchange rates last updated at :time.",c=((a=(i=(s=window.translations)==null?void 0:s.currencies)==null?void 0:i.messages)==null?void 0:a.rates_never_updated)||"Exchange rates have not been updated yet.";f=e.last_updated?o.replace(":time",e.last_updated):c,E()}}).catch(e=>{console.error("Error loading rates info:",e)})}function E(){if(!f)return;const e=document.getElementById("ratesInfoInline");if(e){e.innerHTML=`<i class="fas fa-info-circle me-1"></i>${f}`;return}const t=document.getElementById("currenciesTable_wrapper");if(t){const n=document.createElement("div");n.id="ratesInfoInline",n.className="text-muted small mt-2",n.innerHTML=`<i class="fas fa-info-circle me-1"></i>${f}`,t.appendChild(n)}}});
