import{M as I}from"./bootstrap.esm-Bb7dPm-H.js";import{d as k}from"./datatables-CdFC5o1t.js";import{r as g,g as b}from"./api-DZ3cXm1m.js";import{i as h}from"./tooltip-manager-D9RaGGY4.js";import"jquery";import"./datatables-bbQliV7G.js";/* empty css                                  */const v=window.backupConfig||{},u=v.routes||{},s=v.translations||{},p=window.permissions&&window.permissions.backups||{};async function f(e,n="GET",t=null){const a={Authorization:`Bearer ${b()}`,Accept:"application/json","Content-Type":"application/json"},o={method:n,headers:a};t!==null&&(o.body=JSON.stringify(t));const i=await fetch(e,o);if(i.status===401){const d=await g();if(d)return a.Authorization=`Bearer ${d}`,fetch(e,o)}return i}function T(e){if(!e)return"-";const n=["B","KB","MB","GB"];let t=0,a=e;for(;a>=1024&&t<n.length-1;)a/=1024,t++;return`${a.toFixed(1)} ${n[t]}`}function x(e){return e?new Date(e*1e3).toLocaleString():"-"}const y=$("#backupDestinationsTable").DataTable({...k.getDefaultConfig(),serverSide:!1,searching:!1,dom:'<"d-flex align-items-center mb-3"<"d-flex align-items-center"l>>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:$("#backupDestinationsTable").data("records-url"),type:"GET",beforeSend:function(e){e.setRequestHeader("Authorization",`Bearer ${b()}`)},error:async function(e){e.status===401&&await g()&&y.ajax.reload()}},columns:[{data:"name",name:"name"},{data:"driver",name:"driver",render:e=>`<span class="badge bg-secondary">${e||"-"}</span>`},{data:"is_enabled",name:"is_enabled",orderable:!1,render:e=>e?`<span class="badge bg-success"><i class="fas fa-check me-1"></i>${s.status_enabled}</span>`:`<span class="badge bg-secondary"><i class="fas fa-times me-1"></i>${s.status_disabled}</span>`},{data:"last_test_at",name:"last_test_at",render:(e,n,t)=>e?`${t.last_test_ok?`<span class="badge bg-success">${s.status_ok||"OK"}</span>`:`<span class="badge bg-danger">${s.status_fail||"Fail"}</span>`} <small class="text-muted ms-1">${e}</small>`:`<span class="text-muted small">${s.status_not_tested||"-"}</span>`},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(e,n,t){const a='style="width:32px;height:32px;"',o="btn btn-sm d-inline-flex align-items-center justify-content-center";let i="";return p.update&&(i+=`<button type="button" class="${o} btn-outline-info ms-1 test-destination"
                            ${a} data-id="${e}"
                            data-bs-toggle="tooltip" title="${s.test_connection||"Test"}">
                        <i class="fas fa-plug"></i>
                    </button>
                    <button type="button" class="${o} btn-outline-primary ms-1 edit-destination"
                            ${a} data-id="${e}" data-name="${t.name}" data-driver="${t.driver}"
                            data-enabled="${t.is_enabled?"1":"0"}"
                            data-bs-toggle="tooltip" title="${s.edit}">
                        <i class="fas fa-edit"></i>
                    </button>`),p.delete&&(i+=`<button type="button" class="${o} btn-outline-danger ms-1 delete-destination"
                            ${a} data-id="${e}"
                            data-bs-toggle="tooltip" title="${s.delete||"Sil"}">
                        <i class="fas fa-trash"></i>
                    </button>`),`<div class="d-inline-flex">${i}</div>`}}],drawCallback:function(){h()}}),w=$("#backupsTable").DataTable({...k.getDefaultConfig(),serverSide:!1,searching:!1,dom:'<"d-flex align-items-center mb-3"<"d-flex align-items-center"l>>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:$("#backupsTable").data("records-url"),type:"GET",beforeSend:function(e){e.setRequestHeader("Authorization",`Bearer ${b()}`)},error:async function(e){e.status===401&&await g()&&w.ajax.reload()}},columns:[{data:"name",name:"name"},{data:"size",name:"size",render:e=>T(e)},{data:"last_modified",name:"last_modified",render:e=>x(e)},{data:"disk",name:"disk",render:e=>`<span class="badge bg-secondary">${e}</span>`},{data:"path",name:"actions",orderable:!1,searchable:!1,render:function(e,n,t){const a='style="width:32px;height:32px;"',o="btn btn-sm d-inline-flex align-items-center justify-content-center";let i="";return p.view&&(i+=`<button type="button" class="${o} btn-outline-secondary ms-1 download-backup"
                            ${a} data-disk="${t.disk}" data-path="${e}"
                            data-bs-toggle="tooltip" title="${s.download||"İndir"}">
                        <i class="fas fa-download"></i>
                    </button>`),p.delete&&(i+=`<button type="button" class="${o} btn-outline-danger ms-1 delete-backup"
                            ${a} data-disk="${t.disk}" data-path="${e}"
                            data-bs-toggle="tooltip" title="${s.delete||"Sil"}">
                        <i class="fas fa-trash"></i>
                    </button>`),`<div class="d-inline-flex">${i}</div>`}}],drawCallback:function(){h()}}),E=new I(document.getElementById("destinationModal")),B=document.getElementById("dest_driver");function _(){const e=B.value;document.getElementById("s3Fields").style.display=e==="s3"?"":"none",document.getElementById("sftpFields").style.display=e==="sftp"?"":"none",document.getElementById("ftpFields").style.display=e==="ftp"?"":"none",document.getElementById("dropboxFields").style.display=e==="dropbox"?"":"none"}B.addEventListener("change",_);_();document.getElementById("addDestinationBtn").addEventListener("click",function(){document.getElementById("destinationId").value="",document.getElementById("destinationForm").reset(),document.getElementById("dest_is_enabled").checked=!0,_(),document.querySelector("#destinationModal .modal-title").textContent=s.add_destination||"Hedef Ekle",document.getElementById("saveDestinationLabel").textContent=s.add||"Ekle"});document.addEventListener("click",function(e){const n=e.target.closest(".edit-destination");if(!n)return;const t=n.dataset.id;document.getElementById("destinationId").value=t,document.getElementById("dest_name").value=n.dataset.name||"",document.getElementById("dest_driver").value=n.dataset.driver||"s3",document.getElementById("dest_is_enabled").checked=n.dataset.enabled==="1",_(),document.querySelector("#destinationModal .modal-title").textContent=s.edit_destination||"Hedefi Düzenle",document.getElementById("saveDestinationLabel").textContent=s.save||"Kaydet",E.show()});document.getElementById("saveDestinationBtn").addEventListener("click",async function(){var d,r,c;const e=document.getElementById("destinationId").value,n=document.getElementById("dest_driver").value,t={};n==="s3"?(t.key=document.getElementById("config_key").value,t.secret=document.getElementById("config_secret").value,t.region=document.getElementById("config_region").value,t.bucket=document.getElementById("config_bucket").value,t.endpoint=document.getElementById("config_endpoint").value,t.path_style=document.getElementById("config_path_style").checked,t.root=document.getElementById("config_s3_root").value):n==="sftp"?(t.host=document.getElementById("config_sftp_host").value,t.username=document.getElementById("config_sftp_username").value,t.password=document.getElementById("config_sftp_password").value,t.privateKey=document.getElementById("config_sftp_private_key").value,t.port=parseInt(document.getElementById("config_sftp_port").value,10)||22,t.root=document.getElementById("config_sftp_root").value):n==="ftp"?(t.host=document.getElementById("config_ftp_host").value,t.username=document.getElementById("config_ftp_username").value,t.password=document.getElementById("config_ftp_password").value,t.port=parseInt(document.getElementById("config_ftp_port").value,10)||21,t.root=document.getElementById("config_ftp_root").value,t.ssl=document.getElementById("config_ftp_ssl").checked,t.passive=document.getElementById("config_ftp_passive").checked):n==="dropbox"&&(t.app_key=document.getElementById("config_dropbox_app_key").value,t.app_secret=document.getElementById("config_dropbox_app_secret").value,t.refresh_token=document.getElementById("config_dropbox_refresh_token").value,t.access_token=document.getElementById("config_dropbox_access_token").value,t.root=document.getElementById("config_dropbox_root").value);const a={name:document.getElementById("dest_name").value,driver:n,is_enabled:document.getElementById("dest_is_enabled").checked,config:t},o=e?u.destinationsUpdate.replace(":id",e):u.destinationsStore,i=e?"PUT":"POST";try{const l=await(await f(o,i,a)).json();l.success?(E.hide(),y.ajax.reload(),(d=window.showToast)==null||d.call(window,"success",s.saved||"Kaydedildi.")):(r=window.showToast)==null||r.call(window,"error",l.message||s.error_generic)}catch(m){console.error("Save destination error:",m),(c=window.showToast)==null||c.call(window,"error",s.error_generic)}});document.addEventListener("click",async function(e){var o,i,d;const n=e.target.closest(".test-destination");if(!n)return;const t=n.dataset.id,a=u.destinationsTest.replace(":id",t);n.disabled=!0,n.innerHTML='<i class="fas fa-spinner fa-spin"></i>';try{const c=await(await f(a,"POST")).json();if(c.success)(o=window.showToast)==null||o.call(window,"success",s.test_ok||"Bağlantı başarılı.");else{const m=(s.test_fail||"Bağlantı başarısız: :message").replace(":message",c.message||"");(i=window.showToast)==null||i.call(window,"error",m)}}catch(r){console.error("Test destination error:",r),(d=window.showToast)==null||d.call(window,"error",s.error_request)}finally{n.disabled=!1,n.innerHTML='<i class="fas fa-plug"></i>',y.ajax.reload(null,!1)}});document.addEventListener("click",async function(e){var o,i,d;const n=e.target.closest(".delete-destination");if(!n||!confirm(s.confirm_delete_dest||"Bu hedefi silmek istediğinizden emin misiniz?"))return;const t=n.dataset.id,a=u.destinationsDestroy.replace(":id",t);try{const c=await(await f(a,"DELETE")).json();c.success?(y.ajax.reload(),(o=window.showToast)==null||o.call(window,"success",s.saved||"Silindi.")):(i=window.showToast)==null||i.call(window,"error",c.message||s.error_generic)}catch(r){console.error("Delete destination error:",r),(d=window.showToast)==null||d.call(window,"error",s.error_delete)}});document.getElementById("runBackupBtn").addEventListener("click",async function(){var e,n,t;this.disabled=!0,this.innerHTML='<i class="fas fa-spinner fa-spin me-1"></i>';try{const o=await(await f(u.run,"POST")).json();o.success?((e=window.showToast)==null||e.call(window,"success",s.run_dispatched||"Yedekleme kuyruğa eklendi."),setTimeout(()=>w.ajax.reload(),2e3)):(n=window.showToast)==null||n.call(window,"error",o.message||s.error_generic)}catch(a){console.error("Run backup error:",a),(t=window.showToast)==null||t.call(window,"error",s.error_request)}finally{this.disabled=!1,this.innerHTML='<i class="fas fa-play me-1"></i>'+s.run_now}});document.addEventListener("click",async function(e){var i,d;const n=e.target.closest(".download-backup");if(!n)return;const t=n.dataset.disk,a=n.dataset.path,o=new URL(u.download,window.location.origin);o.searchParams.set("disk",t),o.searchParams.set("path",a),n.disabled=!0,n.innerHTML='<i class="fas fa-spinner fa-spin"></i>';try{const r=await fetch(o.toString(),{headers:{Authorization:`Bearer ${b()}`}});if(r.status===401){await g()&&(n.disabled=!1,n.click());return}if(!r.ok){(i=window.showToast)==null||i.call(window,"error",s.error_download);return}const c=await r.blob(),m=URL.createObjectURL(c),l=document.createElement("a");l.href=m,l.download=a.split("/").pop(),document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(m)}catch(r){console.error("Download error:",r),(d=window.showToast)==null||d.call(window,"error",s.error_download)}finally{n.disabled=!1,n.innerHTML='<i class="fas fa-download"></i>'}});document.addEventListener("click",async function(e){var o,i,d;const n=e.target.closest(".delete-backup");if(!n||!confirm(s.confirm_delete_backup||"Bu yedeği silmek istediğinizden emin misiniz?"))return;const t=n.dataset.disk,a=n.dataset.path;try{const c=await(await f(u.backupDestroy,"DELETE",{disk:t,path:a})).json();c.success?(w.ajax.reload(),(o=window.showToast)==null||o.call(window,"success",s.saved||"Silindi.")):(i=window.showToast)==null||i.call(window,"error",c.message||s.error_generic)}catch(r){console.error("Delete backup error:",r),(d=window.showToast)==null||d.call(window,"error",s.error_delete)}});document.getElementById("backupSettingsForm").addEventListener("submit",async function(e){var t,a,o;e.preventDefault();const n={backup_enabled:document.getElementById("backup_enabled").checked,backup_frequency:document.getElementById("backup_frequency").value,backup_time:document.getElementById("backup_time").value,backup_retention_days:parseInt(document.getElementById("backup_retention_days").value,10),backup_include_db:document.getElementById("backup_include_db").checked,backup_include_files:document.getElementById("backup_include_files").checked,backup_notify:document.getElementById("backup_notify").checked};try{const d=await(await f(u.settingsUpdate,"PUT",n)).json();d.success?(t=window.showToast)==null||t.call(window,"success",s.saved||"Kaydedildi."):(a=window.showToast)==null||a.call(window,"error",d.message||s.error_save)}catch(i){console.error("Settings save error:",i),(o=window.showToast)==null||o.call(window,"error",s.error_request)}});
