
document.addEventListener("DOMContentLoaded", function () {
/* ========================================================== CONFIGURACIÓN DE SERVICIOS SIMPLYBOOK ========================================================== */
const SIMPLYBOOK_BASE = "https://fotografointeriores.simplybook.it/v2/?preview=1&theme_id=42&widget-type=iframe&is_rtl=0&timeline=modern_week&datepicker=top_calendar#book/category/1/service/";
const SERVICIOS = { 60: 36, 90: 37, 120: 38, 150: 39, 180: 40, 210: 41, 240: 42, 300: 43, 1440: 44 };
/* ========================================================== TIEMPO DE SESIÓN ========================================================== */
function calcularTiempoSesion() {
const sesion = document.getElementById("rf-sesion").value;
switch (sesion) {
case "1": return 30;
case "2": return 30;
case "3": return 60;
case "4": return 90;
default: return 0; } }
/* ========================================================== OPCIONES DE VIDEO SEGÚN TAMAÑO ========================================================== */
function actualizarVideos() {
const tamano = parseInt( document.getElementById("rf-tamano").value, 10 );
const contenedor = document.getElementById("rf-video-contenedor");
const select = document.getElementById("rf-video");
select.innerHTML = '';
if (!tamano || tamano < 1) { contenedor.style.display = "none"; return; } /* MENOS DE 81 m² */ if (tamano <= 80) { select.innerHTML += '';
}
/* 81 - 199 m² */
else if (tamano <= 199) { select.innerHTML += '';
select.innerHTML += '';
}
/* 200 m² O MÁS */
else {
select.innerHTML += '';
}
contenedor.style.display = "block"; }
/* ========================================================== TIEMPO EXTRA ========================================================== */
function calcularTiempoExtra() {
let tiempo = 0;
const video = document.getElementById("rf-video").value;
const tour = document.getElementById("rf-tour").value;
/* VIDEO TOUR NO AÑADE TIEMPO */
if (video === "tour") {
tiempo += 0;
}
/* VIDEO MONTAJE +60 MINUTOS */
if (video === "montaje") {
tiempo += 60;
}
/* MATTERPORT +60 MINUTOS */
if (tour === "1") {
tiempo += 60;
}
return tiempo; }
/* ========================================================== CÓDIGOS POSTALES ========================================================== */
const ZONA_B2 = new Set([ "28864","28660","28940","28941","28942","28943", "28944","28945","28946","28947","28906","28909", "28230","28231","28232","28290","28220","28840", "28931","28932","28933","28934","28935","28710", "28980","28981","28320","28708","28850","28851", "28760","28891","28670","28707","28669","28221", "28222" ]);
const ZONA_B3 = new Set([ "28801","28802","28803","28804","28805","28806", "28807","28110","28120","28500","28939","28690", "28350","28863","28400","28770","28270","28814", "28260","28971","28240","28970","28890","28950", "28600","28750","28339","28991","28990","28250", "28340","28341","28342","28434","28691","28229" ]);
const ZONA_C1 = new Set([ "28607","28430","28818","28300","28976","28490", "28413","28411","28492","28816","28510","28977", "28450","28978","28370","28280","28140","28440", "28410","28880","28710","28530","28723","28540", "28514","28693","28200","28817","28979","28609", "19791","28359","28813","28812","28210","28130", "28150","28360","28810" ]);
const ZONA_C2 = new Set([ "28755","28749","28620","28580","28189","28390", "28192","28194","28737","28596","28730","28720", "28721","28751","28640","28743","28560","28650", "28470","28193","28694","28380","28213","28811", "28595","28214","28815","28597","28739","28794", "28742","28752","28792","28460","28190","28491", "28729","28212","28695","28515","28570","28696", "28812","28736","28191","28754","28740","28294", "28649","28680","28296","28818","28756","28160", "28550","28180","28594","28391","28295","28170", "28511","28722","28630","28598","28610","28609", "28512","28590","28293","28791","45200","19200", "19170","45223" ]);
/* ========================================================== EXT 1 ========================================================== */
function esExt1(cp) {
const n = parseInt(cp, 10);
if ( n > 19000 && n < 19999 && cp !== "19170" && cp !== "19200" ) { return true; } if (n > 5000 && n < 5999) { return true; } if (n > 40000 && n < 40999) { return true; } if ( n > 45000 && n < 45999 && cp !== "45200" && cp !== "45223" ) { return true; } return false; } /* ========================================================== EXT 2 ========================================================== */ function esExt2(cp) { const n = parseInt(cp, 10); if (n > 1000 && n < 4999) { return true; } if (n > 6000 && n < 19000) { return true; } if (n > 20000 && n < 28000) { return true; } if (n > 41000 && n < 45000) { return true; } if (n > 46000) { return true; }
if (n > 29000 && n < 40000) { return true; } return false; } /* ========================================================== TIEMPO DE DESPLAZAMIENTO ========================================================== */ function calcularDesplazamiento() { let cp = document.getElementById("rf-cp").value .replace(/\D/g, ""); if (!cp) { return null; } cp = cp.padStart(5, "0"); const n = parseInt(cp, 10); /* EXT 2 */ if (esExt2(cp)) { return 150; } /* EXT 1 */ if (esExt1(cp)) { return 120; } /* ZONA C2 */ if (ZONA_C2.has(cp)) { return 120; } /* ZONA C1 */ if (ZONA_C1.has(cp)) { return 90; } /* ZONA B3 */ if (ZONA_B3.has(cp)) { return 60; } /* ZONA B2 */ if (ZONA_B2.has(cp)) { return 60; } /* ZONA A */ if (n >= 28000 && n <= 28099) { return 0; } /* ZONA B1 */ if (n >= 28100 && n <= 28999) { return 0; } /* SI NO ESTÁ EN NINGUNA ZONA */ return null; } /* ========================================================== REDONDEAR HACIA ARRIBA AL SERVICIO DISPONIBLE ========================================================== */ function obtenerServicio(tiempo) { const duraciones = [ 60, 90, 120, 150, 180, 210, 240, 300, 1440 ]; for (let i = 0; i < duraciones.length; i++) { if (tiempo <= duraciones[i]) { return { minutos: duraciones[i], id: SERVICIOS[duraciones[i]] }; } } return { minutos: 1440, id: 44 }; } /* ========================================================== TEXTO DE DURACIÓN ========================================================== */ function textoDuracion(minutos) { if (minutos === 1440) { return "1 día"; } const horas = Math.floor(minutos / 60); const minutosRestantes = minutos % 60; if (minutosRestantes === 0) { return horas === 1 ? "1 hora" : horas + " horas"; } return horas + " h " + minutosRestantes + " min"; } /* ========================================================== ACTUALIZAR TODO ========================================================== */ function actualizar() { actualizarVideos(); const sesion = calcularTiempoSesion(); const extra = calcularTiempoExtra(); const desplazamiento = calcularDesplazamiento(); /* TODAVÍA NO HAY DATOS SUFICIENTES */ if ( sesion === 0 || desplazamiento === null ) { document.getElementById( "rf-resultado" ).style.display = "none"; document.getElementById( "rf-boton" ).style.display = "none"; document.getElementById( "rf-aviso" ).style.display = "block"; return; } /* CALCULAR TOTAL */ const total = sesion + extra + desplazamiento; /* SERVICIO SIMPLYBOOK */ const servicio = obtenerServicio(total); /* MOSTRAR RESULTADO */ document.getElementById( "rf-tiempo-sesion" ).textContent = textoDuracion(sesion); document.getElementById( "rf-tiempo-extra" ).textContent = extra === 0 ? "0 min" : "+" + textoDuracion(extra); document.getElementById( "rf-tiempo-desplazamiento" ).textContent = desplazamiento === 0 ? "0 min" : "+" + textoDuracion(desplazamiento); document.getElementById( "rf-tiempo-total" ).textContent = textoDuracion(total); document.getElementById( "rf-servicio-texto" ).textContent = textoDuracion(servicio.minutos); /* CREAR URL */ const url = SIMPLYBOOK_BASE + servicio.id + "/count/1/"; document.getElementById( "rf-boton" ).href = url; /* MOSTRAR */ document.getElementById( "rf-resultado" ).style.display = "block"; document.getElementById( "rf-aviso" ).style.display = "none"; document.getElementById( "rf-boton" ).style.display = "block"; } /* ========================================================== EVENTOS ========================================================== */ document.getElementById( "rf-sesion" ).addEventListener( "change", actualizar ); document.getElementById( "rf-tamano" ).addEventListener( "input", actualizar ); document.getElementById( "rf-cp" ).addEventListener( "input", actualizar ); document.getElementById( "rf-video" ).addEventListener( "change", actualizar ); document.getElementById( "rf-tour" ).addEventListener( "change", actualizar ); /* ========================================================== INICIALIZAR ========================================================== */ actualizar(); });