var endpointResult = ''; window.addEventListener('DOMContentLoaded', async () => { endpointResult = await endpoint(); fetchCustomMaps(); fetchMaps(); }); async function fetchCustomMaps() { try { const response = await fetch(`${endpointResult}/website/custom`); if (!response.ok) throw new Error(`Error al obtener Custom Maps: ${response.status}`); const json = await response.json(); renderCustomMapsSwiper(json.data, 'customMapsContainer'); } catch (error) { console.error(error); } } async function fetchMaps() { try { const response = await fetch(`${endpointResult}/website/maps`); if (!response.ok) throw new Error(`Error al obtener Maps: ${response.status}`); const json = await response.json(); renderItems(json.data, 'mapsContainer'); } catch (error) { console.error(error); } } function renderItems(data, containerId) { const container = document.getElementById(containerId); if (!container) return; container.innerHTML = ''; if (!data || data.length === 0) { container.innerHTML = '

No se encontraron resultados.

'; return; } for (let item of data) { const card = document.createElement('div'); card.className = 'col-xxl-3 col-xl-3 col-md-6 col-sm-12 mb-4'; card.innerHTML = `
${item.title}
`; container.appendChild(card); } } async function endpoint() { const res = await fetch("endpoint.php"); const data = await res.json(); return data.base_url; } function renderCustomMapsSwiper(data, containerId) { const container = document.getElementById(containerId); if (!container) return; container.innerHTML = ''; if (!data || data.length === 0) { container.innerHTML = '

No se encontraron resultados.

'; return; } for (let item of data) { const slide = document.createElement('div'); slide.className = 'swiper-slide'; slide.innerHTML = ` ${item.title}
${item.title}
`; container.appendChild(slide); } }