var p=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports);var v=p((b,d)=>{class u{constructor(){this.modal=null,this.modalElement=null,this.languages=[],this.currentModelType=null,this.currentModelId=null,this.currentField=null,this.currentModelName=null,this.currentModelValue=null,this.saveCallback=null,this.init()}init(){var e;if(this.routes=((e=window.apiRoutes)==null?void 0:e.translations)||{},!this.routes.get||!this.routes.save){console.error("Translation API routes not found. Please check window.apiRoutes.translations");return}document.addEventListener("DOMContentLoaded",()=>{this.initializeTranslationButtons()}),document.addEventListener("click",t=>{t.target.closest("[data-translate]")&&(t.preventDefault(),this.handleTranslationButtonClick(t.target.closest("[data-translate]")))})}initializeTranslationButtons(){document.querySelectorAll("[data-translate]:not([data-translate-initialized])").forEach(t=>{if(t.setAttribute("data-translate-initialized","true"),t.classList.contains("btn")||t.classList.add("btn","btn-outline-info"),!t.querySelector("i")){const a=document.createElement("i");a.className="fas fa-language",t.appendChild(a)}t.getAttribute("title")||t.setAttribute("title","Çevirileri Yönet")})}handleTranslationButtonClick(e){const t=e.dataset;if(!t.translate||!t.translateModel||!t.translateId){console.error("Translation button eksik data attribute'lara sahip:",t);return}const a=t.translate,s=t.translateModel,n=parseInt(t.translateId),i=t.translateName||`${s} #${n}`;let l="";const o=t.translateTarget;if(o){const r=document.querySelector(o);r&&(l=r.value||r.textContent||"")}this.openTranslationModal(s,n,a,i,l,{targetSelector:o,updateCallback:t.translateCallback})}async openTranslationModal(e,t,a,s,n,i={}){this.currentModelType=e,this.currentModelId=t,this.currentField=a,this.currentModelName=s,this.currentModelValue=n,this.options=i,this.createModal(),this.modal.show(),this.showLoading();try{await this.loadTranslations()}catch(l){console.error("Translation verileri yüklenirken hata:",l),this.showError("Çeviri verileri yüklenirken bir hata oluştu.")}}createModal(){this.modalElement&&this.modalElement.remove(),document.body.insertAdjacentHTML("beforeend",`
            <div class="modal fade" id="universalTranslationModal" tabindex="-1" aria-labelledby="universalTranslationModalLabel" aria-hidden="true">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="universalTranslationModalLabel">
                                <i class="fas fa-language me-2"></i>Çevirileri Yönet
                            </h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <div id="translationLoadingSpinner" class="text-center py-4">
                                <div class="spinner-border text-primary" role="status">
                                    <span class="visually-hidden">Yükleniyor...</span>
                                </div>
                                <p class="mt-2 text-muted">Çeviriler yükleniyor...</p>
                            </div>
                            <div id="translationContent" style="display: none;">
                                <div class="alert alert-info mb-3">
                                    <i class="fas fa-info-circle me-1"></i>
                                    <strong id="translationModelName"></strong>: <span id="translationModelValue"></span>
                                </div>
                                <div id="universalTranslationTabs"></div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">İptal</button>
                            <button type="button" id="saveUniversalTranslationsBtn" class="btn btn-primary">
                                <i class="fas fa-save me-1"></i>Kaydet
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        `),this.modalElement=document.getElementById("universalTranslationModal"),this.modal=new bootstrap.Modal(this.modalElement);const t=this.modalElement.querySelector("#saveUniversalTranslationsBtn");t&&t.addEventListener("click",()=>this.saveTranslations()),this.modalElement.addEventListener("hidden.bs.modal",()=>{this.modalElement.remove(),this.modalElement=null,this.modal=null})}showLoading(){document.getElementById("translationLoadingSpinner").style.display="block",document.getElementById("translationContent").style.display="none"}hideLoading(){document.getElementById("translationLoadingSpinner").style.display="none",document.getElementById("translationContent").style.display="block"}showError(e){this.hideLoading();const t=document.getElementById("translationContent");t.innerHTML=`
            <div class="alert alert-danger">
                <i class="fas fa-exclamation-triangle me-2"></i>${e}
            </div>
        `,t.style.display="block"}async loadTranslations(){try{const e=this.routes.get.replace(":modelType",this.currentModelType).replace(":modelId",this.currentModelId).replace(":field",this.currentField),t=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest",Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")}});if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);const a=await t.json();if(a.success)this.languages=a.languages,this.renderTranslationTabs(a.translations),this.hideLoading();else throw new Error(a.message||"Failed to load data")}catch(e){throw e}}renderTranslationTabs(e){document.getElementById("translationModelName").textContent=this.currentModelName,document.getElementById("translationModelValue").textContent=this.currentModelValue;const t=document.getElementById("universalTranslationTabs");let a='<ul class="nav nav-tabs" role="tablist">',s='<div class="tab-content mt-3">';this.languages.forEach((n,i)=>{const l=i===0?"active":"",o=e[n.code]||"",r=n.flag_class?`<span class="${n.flag_class}"></span>`:"";a+=`
                <li class="nav-item" role="presentation">
                    <button class="nav-link ${l}" data-bs-toggle="tab" data-bs-target="#universal-translation-${n.code}" type="button">
                        ${r} ${n.name}
                        ${n.site_default?'<span class="badge bg-primary ms-1">Varsayılan</span>':""}
                    </button>
                </li>
            `;const m=this.getInputType(),h=this.generateInputHtml(n.code,o,m);s+=`
                <div class="tab-pane fade ${l?"show active":""}" id="universal-translation-${n.code}">
                    <div class="mb-3">
                        <label class="form-label">
                            ${this.currentField.charAt(0).toUpperCase()+this.currentField.slice(1)} (${n.name})
                            ${n.site_default?'<span class="text-danger">*</span>':""}
                        </label>
                        ${h}
                        ${n.site_default?'<small class="form-text text-muted">Bu varsayılan dildir ve zorunludur.</small>':""}
                    </div>
                </div>
            `}),a+="</ul>",s+="</div>",t.innerHTML=a+s}getInputType(){return this.currentField.includes("description")||this.currentField.includes("content")?"textarea":"text"}generateInputHtml(e,t,a){const s=`class="form-control universal-translation-input" data-lang="${e}"`;return a==="textarea"?`<textarea ${s} rows="4">${t}</textarea>`:`<input type="text" ${s} value="${t}">`}async saveTranslations(){const e=document.getElementById("saveUniversalTranslationsBtn"),t=e.innerHTML;e.disabled=!0,e.innerHTML='<i class="fas fa-spinner fa-spin me-1"></i>Kaydediliyor...';try{const a={};this.languages.forEach(l=>{const o=document.querySelector(`.universal-translation-input[data-lang="${l.code}"]`);o&&(a[l.code]=o.value.trim())});const s=this.routes.save.replace(":modelType",this.currentModelType).replace(":modelId",this.currentModelId).replace(":field",this.currentField),n=await fetch(s,{method:"PUT",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest",Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},body:JSON.stringify({translations:a})});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);const i=await n.json();if(i.success)this.showNotification(i.message||"Translations saved successfully.","success"),this.updateTargetInput(a),this.modal.hide(),this.saveCallback&&this.saveCallback(a);else throw new Error(i.message||"An error occurred while saving")}catch(a){console.error("Translation kaydetme hatası:",a),this.showNotification("Çeviriler kaydedilirken bir hata oluştu: "+a.message,"error")}finally{e.disabled=!1,e.innerHTML=t}}updateTargetInput(e){var n;if(!this.options.targetSelector)return;const t=document.querySelector(this.options.targetSelector);if(!t)return;const a=this.languages.find(i=>i.site_default),s=a?a.code:((n=this.languages[0])==null?void 0:n.code)??"en";if(e[s])if(t.tagName==="INPUT"||t.tagName==="TEXTAREA"){if(t.value=e[s],t.dispatchEvent(new Event("input",{bubbles:!0})),this.currentField==="name"&&typeof window.createSlug=="function"){const i=document.querySelector("#slug");i&&(i.value=window.createSlug(e[s]))}}else t.textContent=e[s];this.options.updateCallback&&typeof window[this.options.updateCallback]=="function"&&window[this.options.updateCallback](e)}showNotification(e,t="info"){const s=`
            <div class="alert ${t==="success"?"alert-success":t==="error"?"alert-danger":"alert-info"} alert-dismissible fade show position-fixed" 
                 style="top: 20px; right: 20px; z-index: 9999; min-width: 300px;">
                <i class="fas fa-${t==="success"?"check-circle":t==="error"?"exclamation-circle":"info-circle"} me-2"></i>
                ${e}
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        `;document.body.insertAdjacentHTML("beforeend",s),setTimeout(()=>{document.querySelectorAll(".alert").forEach(i=>{i.textContent.includes(e.substring(0,20))&&i.remove()})},5e3)}setSaveCallback(e){this.saveCallback=e}}window.translationManager=new u;typeof d<"u"&&d.exports&&(d.exports=u)});export default v();
