import{$ as v}from"./datatables-Bo82YvhT.js";import{d as k}from"./datatables-I6jthWPb.js";import{i as O}from"./tooltip-manager-D9RaGGY4.js";import{g as C}from"./api-DZ3cXm1m.js";import"./bootstrap.esm-Bb7dPm-H.js";/* empty css                                  */document.addEventListener("DOMContentLoaded",function(){var p,f,m;const c=document.getElementById("productConfigOptions");if(!c)return;const E=c.getAttribute("data-records-url"),{permissions:l,routes:u}=window,d=v("#productConfigOptions").DataTable({...k.getDefaultConfig(),serverSide:!0,searching:!0,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:E,type:"GET",headers:{Authorization:"Bearer "+C()},data:function(e){var n,t;e.archived=((n=document.querySelector("[data-archived-filter]"))==null?void 0:n.value)||"no",e.type=((t=document.querySelector("[data-type-filter]"))==null?void 0:t.value)||""}},columns:[{data:"name",name:"name",render:function(e,n,t){return n==="display"?`<strong>${e}</strong>`:e}},{data:"group.name",name:"group.name",render:function(e,n,t){return n==="display"?e?`<span class="badge bg-info">${e}</span>`:'<span class="text-muted">-</span>':e}},{data:"description",name:"description",render:function(e,n,t){return n==="display"?e||'<span class="text-muted">-</span>':e}},{data:"type",name:"type",render:function(e,n,t){return n==="display"?`<span class="badge bg-secondary">${{number:"Sayı",select:"Seçim Kutusu",checkboxgroup:"Onay Kutusu Grubu",checkbox:"Onay Kutusu",text:"Metin"}[e]||e}</span>`:e}},{data:"order",name:"order",render:function(e,n,t){return n==="display"?`<span class="badge bg-secondary">${e}</span>`:e}},{data:"status_key",name:"status_key",render:function(e,n,t){var i,o;if(n==="display"){const s={active:"success",hidden:"secondary",archived:"warning"},r=e||"active",a=((o=(i=window.pageConfig)==null?void 0:i.translations)==null?void 0:o["status_"+r])||r;return`<span class="badge bg-${s[r]||"secondary"}">${a}</span>`}return e}},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(e,n,t){var o,s,r,a,g,w,y,h,b,x;const i=[];if((o=l.productConfigOptions)!=null&&o.update){const $=u.productConfigOptions.edit.replace(":id",e);i.push(`
                            <a href="${$}"
                               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="${((g=(a=(r=(s=window.translations)==null?void 0:s.admin)==null?void 0:r.product_config_options)==null?void 0:a.buttons)==null?void 0:g.edit)||"Edit"}">
                                <i class="fas fa-edit"></i>
                            </a>`)}return(w=l.productConfigOptions)!=null&&w.delete&&i.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-option"
                                    style="width: 32px; height: 32px;"
                                    data-id="${e}"
                                    data-name="${t.name}"
                                    data-bs-toggle="tooltip"
                                    title="${((x=(b=(h=(y=window.translations)==null?void 0:y.admin)==null?void 0:h.product_config_options)==null?void 0:b.buttons)==null?void 0:x.delete)||"Delete"}">
                                <i class="fas fa-trash"></i>
                            </button>`),i.length===0?'<span class="text-muted">-</span>':`<div class="d-inline-flex">${i.join("")}</div>`}}],drawCallback:function(){O()}});(p=document.getElementById("productConfigOptionsToggleFilters"))==null||p.addEventListener("click",()=>{const e=document.getElementById("productConfigOptionsFilters");e&&(e.style.display=e.style.display==="none"?"":"none")}),(f=document.querySelector("[data-archived-filter]"))==null||f.addEventListener("change",()=>d.ajax.reload()),(m=document.querySelector("[data-type-filter]"))==null||m.addEventListener("change",()=>d.ajax.reload()),v(document).on("click",".delete-option",async function(){var t,i,o,s;const e=this.getAttribute("data-id");this.getAttribute("data-name"),await window.showConfirm(((s=(o=(i=(t=window.translations)==null?void 0:t.admin)==null?void 0:i.product_config_options)==null?void 0:o.confirmation)==null?void 0:s.delete)||"Bu ürün opsiyonunu arşivlemek istediğine emin misin?",{confirmClass:"btn-danger",icon:"warning"})&&T(e)});function T(e){const n=u.productConfigOptions.delete.replace(":id",e);fetch(n,{method:"DELETE",headers:{Authorization:"Bearer "+C()}}).then(t=>t.json()).then(t=>{t.success?(window.showToast?window.showToast("success",t.message):window.showSuccess(t.message),d.ajax.reload()):window.showToast?window.showToast("error",t.message):window.showError(t.message)}).catch(t=>{console.error("Error:",t),window.showToast?window.showToast("error","Bir hata oluştu. Lütfen tekrar deneyin."):window.showError("Bir hata oluştu. Lütfen tekrar deneyin.")})}});
