import"./bootstrap.esm-Bb7dPm-H.js";import{d as b}from"./datatables-I6jthWPb.js";import{i as m}from"./tooltip-manager-D9RaGGY4.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */const{permissions:f,routes:l,translations:a}=window;let o;document.addEventListener("DOMContentLoaded",function(){h(),w(),m()});function h(){o=$("#domainCostsTable").DataTable({...b.getDefaultConfig(),serverSide:!0,searching:!1,ajax:{url:l.domainCosts.records,type:"GET",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},data:function(e){e.tld_id=$("#tldFilter").val(),e.registrar=$("#registrarFilter").val(),e.is_active=$("#statusFilter").val()}},columns:[{data:"tld",name:"tld",render:function(e,t,s){return t==="display"?`<span class="badge bg-primary">${e.toUpperCase()}</span>`:e}},{data:"registrar",name:"registrar",render:function(e,t,s){return t==="display"?e||'<span class="text-muted">-</span>':e}},{data:"years",name:"years",render:function(e,t,s){return t==="display"?!Array.isArray(e)||e.length===0?'<span class="text-muted">-</span>':e.map(n=>`<span class="badge bg-secondary me-1">${n}</span>`).join(""):e}},{data:"currency_id",name:"currency",render:function(e,t,s){return t==="display"?`<span class="badge ${v(e)}">${e}</span>`:e}},{data:"is_active",name:"is_active",render:function(e,t,s){var n,r;return t==="display"?e?`<span class="badge bg-success">${((n=a.filters)==null?void 0:n.active)||"Active"}</span>`:`<span class="badge bg-danger">${((r=a.filters)==null?void 0:r.inactive)||"Inactive"}</span>`:e}},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(e,t,s){var n,r,i,u;if(t==="display"){const c=[];if((n=f.domainCosts)!=null&&n.update){const g=l.domainCosts.edit.replace(":id",e);c.push(`
                                <a href="${g}"
                                   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="${((r=a.buttons)==null?void 0:r.edit)||"Edit"}">
                                    <i class="fas fa-edit"></i>
                                </a>`)}return(i=f.domainCosts)!=null&&i.delete&&c.push(`
                                <button type="button"
                                        class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-domain-cost"
                                        style="width: 32px; height: 32px;"
                                        data-id="${e}"
                                        data-bs-toggle="tooltip"
                                        title="${((u=a.buttons)==null?void 0:u.delete)||"Delete"}">
                                    <i class="fas fa-trash"></i>
                                </button>`),c.length===0?'<span class="text-muted">-</span>':`<div class="d-inline-flex">${c.join("")}</div>`}return e}}],drawCallback:function(){m()}})}function w(){$("#tldFilter, #registrarFilter, #statusFilter").on("change",function(){o.draw()}),$("#clearFilters").on("click",function(){$("#tldFilter, #registrarFilter, #statusFilter").val(""),o.draw()}),$("#createDomainCostForm").on("submit",function(e){e.preventDefault(),y()}),$(document).on("click",".delete-domain-cost",function(){const e=$(this).data("id");C(e)})}function y(){const e=document.getElementById("createDomainCostForm"),t=new FormData(e);t.set("is_active",t.get("is_active")?1:0);const s={};for(let r=1;r<=10;r++){const i=t.get(`prices[${r}]`);i!==null&&i!==""&&!isNaN(parseFloat(i))&&(s[r]=parseFloat(i)),t.delete(`prices[${r}]`)}const n=Object.fromEntries(t);n.prices=s,fetch(l.domainCosts.store,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}).then(r=>r.json()).then(r=>{r.success?(p(r.message),$("#createDomainCostModal").modal("hide"),e.reset(),o.draw()):d(r.message)}).catch(r=>{console.error("Error:",r),d("An error occurred. Please try again.")})}async function C(e){var s;await window.showConfirm(((s=a.confirmations)==null?void 0:s.delete_message)||"Are you sure you want to delete this domain cost?",{confirmClass:"btn-danger",icon:"warning"})&&fetch(l.domainCosts.delete.replace(":id",e),{method:"DELETE",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")}}).then(n=>n.json()).then(n=>{n.success?(p(n.message),o.draw()):d(n.message)}).catch(n=>{console.error("Error:",n),d("An error occurred. Please try again.")})}function v(e){return{USD:"bg-success",EUR:"bg-primary",TRY:"bg-warning"}[e]||"bg-secondary"}function p(e){window.toastr?window.toastr.success(e):window.showSuccess(e)}function d(e){window.toastr?window.toastr.error(e):window.showError(e)}
