import{M as c}from"./bootstrap.esm-Bb7dPm-H.js";import{d as m}from"./datatables-I6jthWPb.js";import{i as f}from"./tooltip-manager-D9RaGGY4.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */let l=null,r=null;$(document).ready(function(){const u=$("#taxRulesTable").DataTable({...m.getDefaultConfig(),serverSide:!1,dom:"t",paging:!1,info:!1,lengthChange:!1,ajax:{url:window.routes.taxes.records,type:"GET",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},dataSrc:"data"},columns:[{data:"name"},{data:"rate",render:t=>t+" %"},{data:"all_countries",render:(t,a,e)=>t==1||t===!0?window.translations.all_countries:e.countries&&e.countries.length>0?e.countries.map(n=>n).join(", "):"-"},{data:"id",orderable:!1,searchable:!1,render:(t,a,e)=>{var i,s,o,d;const n=[];return(s=(i=window.permissions)==null?void 0:i.taxes)!=null&&s.update&&n.push(`
                        <button class="btn btn-sm btn-outline-primary d-inline-flex align-items-center justify-content-center edit-tax-rule"
                                style="width: 32px; height: 32px;"
                                data-id="${t}"
                                data-bs-toggle="tooltip"
                                title="${window.translations.edit_rule||"Edit"}">
                            <i class="fas fa-edit"></i>
                        </button>
                    `),(d=(o=window.permissions)==null?void 0:o.taxes)!=null&&d.delete&&n.push(`
                        <button class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-tax-rule"
                                style="width: 32px; height: 32px;"
                                data-id="${t}"
                                data-bs-toggle="tooltip"
                                title="${window.translations.delete_rule||"Delete"}">
                            <i class="fas fa-trash"></i>
                        </button>
                    `),n.length===0?'<span class="text-muted">-</span>':`<div class="d-inline-flex">${n.join("")}</div>`}}],drawCallback:function(){f()}});l=new c(document.getElementById("taxRuleModal")),$("#addTaxRuleBtn").on("click",function(){r=null,$("#taxRuleModalLabel").text(window.translations.add_rule),$("#taxRuleForm")[0].reset(),$("#tax_rule_countries").val([]).trigger("change"),l.show()}),$("#taxRulesTable").on("click",".edit-tax-rule",function(){const t=$(this).data("id");r=t,$.ajax({url:window.routes.taxes.show.replace(":id",t),type:"GET",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},success:function(a){const e=a.data;e&&($("#taxRuleModalLabel").text(window.translations.edit_rule),$("#tax_rule_name").val(e.name),$("#tax_rule_rate").val(e.rate),e.all_countries==1||e.all_countries===!0?$("#tax_rule_countries").val(["all"]):$("#tax_rule_countries").val(e.countries||[]),l.show())},error:function(a){var e;toastr.error(((e=a.responseJSON)==null?void 0:e.message)||"Vergi kuralı yüklenirken hata oluştu!")}})}),$("#taxRulesTable").on("click",".delete-tax-rule",async function(){const t=$(this).data("id");await window.showConfirm(window.translations.delete_confirm,{confirmClass:"btn-danger",icon:"warning"})&&$.ajax({url:window.routes.taxes.destroy.replace(":id",t),type:"DELETE",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},success:function(){u.ajax.reload(),toastr.success(window.translations.success_deleted)}})}),$("#taxRuleForm").on("submit",function(t){t.preventDefault();const a={name:$("#tax_rule_name").val(),rate:$("#tax_rule_rate").val()},e=$("#tax_rule_countries").val();e&&e.includes("all")?(a.all_countries=1,a.countries=[]):(a.all_countries=0,a.countries=e||[]);const n=r?"PUT":"POST",i=r?window.routes.taxes.update.replace(":id",r):window.routes.taxes.store;$.ajax({url:i,type:n,data:a,headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},success:function(){u.ajax.reload(),l.hide(),toastr.success(r?window.translations.success_updated:window.translations.success_created)},error:function(s){var o;toastr.error(((o=s.responseJSON)==null?void 0:o.message)||"Hata!")}})})});
