function openModal(){document.getElementById("songTitle").innerText=song,document.getElementById("artistName").innerText=artist,document.getElementById("lyricsText").innerHTML=lyrics,$("#lyricsModal").modal("show")}function closeModal(){$("#lyricsModal").modal("hide")}function printSection(){const e=document.querySelector(".modal-body").cloneNode(!0),t=window.open("","_blank");t.document.open(),t.document.write(`\n      <!DOCTYPE html>\n      <html>\n      <head>\n          <title>Impresión de Letra</title>\n          <style>\n              @media print {\n                  body {\n                      font-family: Arial, sans-serif;\n                      margin: 20mm;\n                  }\n                  .modal-body img {\n                      display: block;\n                      margin: 0 auto;\n                      max-width: 50%;\n                  }\n                  pre, p {\n                      white-space: pre-wrap;\n                      font-size: 14px;\n                      line-height: 1.5;\n                  }\n              }\n          </style>\n      </head>\n      <body>\n          <div style="padding: 20px; max-width: 600px; margin: auto;">\n              ${e.innerHTML} \x3c!-- Usamos innerHTML para mantener el formato HTML --\x3e\n          </div>\n      </body>\n      </html>\n  `),t.document.close(),t.print(),t.onafterprint=()=>{t.close()}}async function loadLatestSongs(){try{const e=await fetch("/top.xhr");if(!e.ok)throw new Error(`HTTP Error: ${e.status}`);const t=await e.json(),n=document.getElementById("latest-songs-list");if(!n)return void console.warn("Elemento con ID 'latest-songs-list' no encontrado.");n.innerHTML="",t.forEach((e=>{const t=document.createElement("li");t.className="col-md-4",t.innerHTML=`\n              <a href="${e.url}" class="item-box with-picture text-row d-flex boxed">\n                  <div>\n                      <img alt="${e.artT}" class="picture-wrap picture-rounded" \n                           data-src="${e.imagen}" \n                           src="${e.imagen}" lazy="loaded">\n                  </div>\n                  <div>\n                      <div class="title-default">${e.canT}</div>\n                      <div class="subtitle-default">${e.artT}</div>\n                  </div>\n              </a>\n          `,n.appendChild(t)}))}catch(e){console.error("Error al cargar las canciones:",e)}}function startAutoUpdate(){loadLatestSongs(),setInterval(loadLatestSongs,1e4)}function initializeLatestSongs(){startAutoUpdate()}$(document).ready((function(){$(document).on("click",".openBtn",(function(){$("#contentBody").html("<p>Cargando contenido...</p>"),$("#contentBody").load("/buscador.asp",(function(e,t){"error"===t&&$("#contentBody").html("<p>Error al cargar el contenido. Asegúrate de que el archivo exista y sea accesible.</p>")})),$("#contentOverlay").fadeIn(),$("#contentContainer").fadeIn(),$("body").addClass("modal-open")})),$(document).on("click","#closeContainer, #contentOverlay",(function(){$("#contentOverlay").fadeOut(),$("#contentContainer").fadeOut(),$("body").removeClass("modal-open")}))})),document.addEventListener("DOMContentLoaded",(function(){new class{constructor(e,t,n,o){this.menuToggle=document.querySelector(e),this.sidenav=document.querySelector(t),this.sidenavClose=document.querySelector(n),this.sidenavBg=document.querySelector(o),this.menuToggle&&this.sidenav&&this.sidenavClose&&this.sidenavBg?this.initialize():console.warn("Elementos no encontrados.")}initialize(){this.menuToggle.addEventListener("click",(()=>this.openNav())),this.sidenavClose.addEventListener("click",(()=>this.closeNav())),this.sidenavBg.addEventListener("click",(()=>this.closeNav()))}openNav(){this.sidenav.style.left="0",this.sidenavBg.style.left="0"}closeNav(){this.sidenav.style.left="-100%",this.sidenavBg.style.left="-100%"}}("#menu-toggle","#mySidenav","#sidenav-close","#sidenav-bg")})),document.addEventListener("DOMContentLoaded",(function(){new class{constructor(e,t){this.dropdownButton=document.querySelector(e),this.dropdownMenu=document.querySelector(t),this.dropdownButton&&this.dropdownMenu?this.initialize():console.warn("Elementos no encontrados.")}initialize(){this.dropdownButton.addEventListener("click",(e=>this.toggleDropdown(e))),document.addEventListener("click",(e=>this.closeDropdownOnClickOutside(e)))}toggleDropdown(e){e.preventDefault(),this.dropdownMenu.classList.toggle("show"),this.updateAriaExpanded()}updateAriaExpanded(){const e=this.dropdownMenu.classList.contains("show");this.dropdownButton.setAttribute("aria-expanded",e.toString())}closeDropdownOnClickOutside(e){this.dropdownButton.contains(e.target)||this.dropdownMenu.contains(e.target)||this.dropdownMenu.classList.contains("show")&&(this.dropdownMenu.classList.remove("show"),this.dropdownButton.setAttribute("aria-expanded","false"))}}(".btn-dropdown",".dropdown-menu")})),document.addEventListener("DOMContentLoaded",(()=>{new class{constructor(e,t,n){this.dropdownButton=document.getElementById(e),this.dropdownMenu=document.querySelector(t),this.dropdownContainer=document.getElementById(n),this.dropdownButton&&this.dropdownMenu&&this.dropdownContainer?this.initialize():console.log("Elementos necesarios no encontrados.")}initialize(){this.dropdownButton.addEventListener("click",(e=>this.toggleDropdown(e))),document.addEventListener("click",(()=>this.closeDropdown()))}toggleDropdown(e){e.stopPropagation(),this.dropdownContainer.classList.toggle("show"),this.dropdownMenu.classList.toggle("show")}closeDropdown(){this.dropdownContainer.classList.remove("show"),this.dropdownMenu.classList.remove("show")}}("dropdownButton","#dropdownShare .dropdown-menu","dropdownShare")})),document.addEventListener("DOMContentLoaded",(()=>{new class{constructor(e){this.links=document.querySelectorAll(e),this.links.length>0?this.initialize():console.log(`No se encontraron enlaces con el selector: ${e}`)}initialize(){this.links.forEach((e=>{e.addEventListener("click",(t=>this.openPopup(t,e)))}))}openPopup(e,t){e.preventDefault();const n=t.href,o=t.dataset.width||600,s=t.dataset.height||400,i=screen.width/2-o/2,r=screen.height/2-s/2;window.open(n,"popup",`width=${o},height=${s},top=${r},left=${i},resizable=yes,scrollbars=yes`)}}(".popup-link")})),document.addEventListener("DOMContentLoaded",(function(){window.iniciarListaArtista=function(){fetch(`/alla/${artjs}.xhr`).then((e=>{if(!e.ok)throw new Error("Error en la respuesta del servidor");return e.json()})).then((e=>{console.log("Datos recibidos:",e),e.error?console.error(e.error):function(e){const t=document.getElementById("song-list");if(!t)return void console.error("Elemento 'song-list' no encontrado.");t.innerHTML="";const n=function(e){return e.reduce(((e,t)=>{const n=t.cancion.charAt(0).toUpperCase(),o=isNaN(n)?n:"#";return e[o]=e[o]||[],e[o].push(t),e}),{})}(e);document.querySelectorAll(".button-letter").forEach((e=>{const o=e.textContent;n[o]?(function(e,t,n){const o=document.createElement("li");o.classList.add("col-12","item-quick-menu","letter-header"),o.innerHTML=`<a href="#" class="item-box item-list">\n              <span class="letter">${n}</span>\n          </a>`,e.appendChild(o),t.forEach((t=>{const n=document.createElement("li");n.classList.add("col-12","item-quick-menu"),n.innerHTML=`<a href="/${t.genero}/${t.artista_url}/${t.cancion_url}${end}" class="item-box item-list">\n                  <span class="lyric-name title-default weight-normal">${t.cancion}</span>\n              </a>`,e.appendChild(n)}))}(t,n[o],o),e.classList.remove("deactived")):e.classList.add("deactived"),e.addEventListener("click",(()=>function(e){const t=[...document.querySelectorAll(".letter")].find((t=>t.textContent===e));t&&t.scrollIntoView({behavior:"smooth",block:"start"})}(o)))}))}(e.canciones)})).catch((e=>{console.error("Error al cargar las canciones:",e)}))}})),document.addEventListener("DOMContentLoaded",(function(){class e{constructor(e,t){this.genre=e,this.end=t,this.currentPage=1}init(){this.loadArtistas(this.currentPage),this.setupPagination()}loadArtistas(e){fetch(`/gall/${this.genre}/page/${e}.xhr`).then((e=>{if(!e.ok)throw new Error("Error en la respuesta del servidor");return e.json()})).then((e=>{const t=document.getElementById("genre-artists-list");t?(t.innerHTML="",e.error?t.innerHTML=`<li>${e.error}</li>`:(this.renderArtists(e),this.updatePaginationButtons(e))):console.warn("El contenedor 'genre-artists-list' no existe.")})).catch((e=>console.error("Error al cargar los artistas:",e)))}renderArtists(e){const t=document.getElementById("genre-artists-list");e.forEach((e=>{const n=document.createElement("li");n.classList.add("col-md-4","col-lg-3","col-sm-6","mb-1");const o=document.createElement("a");o.href=`/${e.genero}/${e.artista_url}${this.end}`,o.classList.add("item-box","item-list");const s=document.createElement("div");s.classList.add("title-default"),s.innerHTML=`<span>${e.artista}</span>`,o.appendChild(s),n.appendChild(o),t.appendChild(n)}))}updatePaginationButtons(e){const t=document.getElementById("prevl"),n=document.getElementById("nextl");t&&(t.disabled=1===this.currentPage),n&&(n.disabled=e.length<20)}changePage(e){"prevl"===e&&this.currentPage>1?this.currentPage--:"nextl"===e&&this.currentPage++,this.loadArtistas(this.currentPage)}setupPagination(){const e=document.getElementById("prevl"),t=document.getElementById("nextl");e&&e.addEventListener("click",(()=>this.changePage("prevl"))),t&&t.addEventListener("click",(()=>this.changePage("nextl")))}}"undefined"!=typeof genre&&"undefined"!=typeof end&&function(t,n){new e(t,n).init()}(genre,end)})),document.addEventListener("DOMContentLoaded",(function(){class e{constructor(e,t){this.letra=e,this.end=t}init(){this.loadArtists(),this.setupToggleButton()}loadArtists(){fetch(`/xletras/${this.letra}.xhr`).then((e=>{if(!e.ok)throw new Error("Error al obtener datos: "+e.status);return e.json()})).then((e=>{e.error?console.error("Error en el servidor:",e.error):this.renderArtists(e.artistas)})).catch((e=>console.error("Error al cargar los artistas:",e)))}renderArtists(e){const t=document.getElementById("artist-list");t?(t.innerHTML="",e.forEach((e=>{const n=document.createElement("li");n.classList.add("col-md-3","col-sm-6"),n.innerHTML=`\n                    <a href="/${e.genero_url}/${e.artista_url}${this.end}" class="item-box item-list">\n                        <div class="title-default">${e.artista}</div>\n                    </a>\n                `,t.appendChild(n)}))):console.warn("El elemento 'artist-list' no existe.")}toggleArtistList(){const e=document.getElementById("artist-list");e?e.classList.toggle("show"):console.warn("El elemento 'artist-list' no existe.")}setupToggleButton(){const e=document.getElementById("lyrics-toggle");e&&e.addEventListener("click",(()=>this.toggleArtistList()))}}"undefined"!=typeof letra&&"undefined"!=typeof end&&function(t,n){new e(t,n).init()}(letra,end)})),document.addEventListener("DOMContentLoaded",(function(){if(document.getElementById("playlist-container")){"undefined"!=typeof end&&function(e){let t=1;function n(t){fetch(`/dplista/${t}.xhr`).then((e=>e.json())).then((n=>{const o=document.getElementById("playlist-container");o?(o.innerHTML="",Array.isArray(n)&&0!==n.length?(n.forEach((t=>{const n=document.createElement("div");n.classList.add("col-md-3","col-sm-6","mb-5","mb-lg-0"),n.innerHTML=`\n                                <section>\n                                    <a href="/playlist/${t.id}${e}" class="playlist-box">\n                                        <img class="embed-responsive embed-responsive-4by3 img-wrap" src="https://tse2.mm.bing.net/th?q=${t.nombre}&w=255&h=130&c=7&rs=1" alt="${t.nombre}" />\n                                    </a>\n                                    <header class="p-2 mt-1">\n                                        <h1 class="mb-1">\n                                            <a href="/playlist/${t.id}${e}" class="title-default title-size-2">${t.nombre}</a>\n                                        </h1>\n                                        <h2 class="subtitle-default">${t.descripcion}</h2>\n                                    </header>\n                                </section>\n                            `,o.appendChild(n)})),document.getElementById("prevp").disabled=1===t,document.getElementById("nextp").disabled=n.length<10):o.innerHTML='<p class="text-center">No hay más playlists para mostrar.</p>'):console.warn("El contenedor 'playlist-container' no existe.")})).catch((e=>{console.error("Error al cargar las playlists:",e);const t=document.getElementById("playlist-container");t&&(t.innerHTML='<p class="text-center text-danger">Error al cargar las playlists.</p>')}))}function o(e){"prevp"===e&&t>1?t--:"nextp"===e&&t++,n(t)}const s=document.getElementById("prevp"),i=document.getElementById("nextp");s&&s.addEventListener("click",(()=>o("prevp"))),i&&i.addEventListener("click",(()=>o("nextp"))),n(t)}(end)}})),document.addEventListener("DOMContentLoaded",(function(){if(document.getElementById("playlist-container")){"undefined"!=typeof end&&function(e){fetch("/dvideos.xhr").then((e=>e.json())).then((t=>{const n=document.getElementById("playlist-container");n?(n.innerHTML="",Array.isArray(t)&&0!==t.length?t.forEach((t=>{const o=document.createElement("div");o.classList.add("col-md-3","col-sm-6","mb-5","mb-lg-0"),o.innerHTML=`\n                            <section>\n                                <a href="/${t.generol}/${t.artistal}/${video}/${t.uid}${e}" class="playlist-box">\n                                    <img class="embed-responsive embed-responsive-4by3 img-wrap" src="https://i.ytimg.com/vi/${t.idyt}/default.jpg" alt="${t.cancion} | ${t.artista}" />\n                                </a>\n                                <header class="p-2 mt-1">\n                                    <h1 class="mb-1">\n                                        <a href="/${t.generol}/${t.artistal}/${video}/${t.uid}${e}" class="title-default title-size-2">${t.cancion}</a>\n                                    </h1>\n                                    <h2 class="subtitle-default">${t.artista}</h2>\n                                </header>\n                            </section>\n                        `,n.appendChild(o)})):n.innerHTML='<p class="text-center">No hay más playlists para mostrar.</p>'):console.warn("El contenedor 'playlist-container' no existe.")})).catch((e=>{console.error("Error al cargar las playlists:",e);const t=document.getElementById("playlist-container");t&&(t.innerHTML='<p class="text-center text-danger">Error al cargar las playlists.</p>')}))}(end)}}));