const eventsGlobal=function(){function selectLanguage(event){const{target:target}=event;const{languageType:languageType}=target.dataset;const request={endpoint:"/translate_serv.php",options:{method:"POST",headers:{"Content-Type":"text/html"},body:languageType}};fetch(request.endpoint,request.options).then((response=>{utilGlobal.handleError(response,"Languages not found, please contact the development department.");return response.json()})).then((data=>{console.log(data)})).catch((error=>console.error(error)))}function toggleDropdown(event){const{target:target}=event;const dropdownMenu=document.querySelector(`[data-dropdown-menu="${target.id}"]`);const dropdownEnabled=target.dataset.dropdownEnabled;let displayStyle;let enabled;resetClickOutside();if(dropdownEnabled==="false"){enabled="true";displayStyle="block";target.parentElement.style.zIndex="2"}else{displayStyle="none";enabled="false";target.parentElement.style.zIndex=""}dropdownMenu.style.display=displayStyle;target.setAttribute("data-dropdown-enabled",enabled);event.stopPropagation()}function resetClickOutside(){const dropdownButtons=document.querySelectorAll(".custom-dropdown-button");if(dropdownButtons&&dropdownButtons.length){dropdownButtons.forEach((item=>{item.parentElement.style.zIndex="";item.setAttribute("data-dropdown-enabled","false");item.nextElementSibling.style.display="none"}))}}function displayInfoContainer(event){const{target:target}=event;const bodyType=target.dataset.bodyType;if(bodyType&&!target.classList.contains("current")){const body=document.querySelector(`.included-with-server-box[data-body-type="${bodyType}"]`);document.querySelectorAll(".included-with-server-box").forEach((item=>{if(item){item.classList.remove("d-flex");item.classList.remove("animation-triggered");item.classList.add("d-none")}}));if(body){body.classList.remove("d-none");body.classList.add("d-flex");body.classList.add("animation-triggered")}document.querySelectorAll(".header-button").forEach((item=>{if(item){item.classList.remove("current")}}));target.classList.add("current")}}const selectFilteredObject={};const getFilteredArray=event=>{const{target:target}=event;const{dataset:dataset}=target;const{componentType:componentType}=dataset;let value=target.value;let data;const instantServerConfigurations=dataModelGlobal.getInstantServerConfigurations();const numberValues=["ram"];if(numberValues.includes(componentType)){value=parseFloat(value)}if(componentType==="price"){value=value!=="none"?JSON.parse(value):value}const parentElement=uiGlobal.findParent(target,"TABLE","tagName");const{instantsType:instantsType}=parentElement.dataset;switch(instantsType){case"without-gpu":data=instantServerConfigurations.instantsWithoutGPU;break;case"with-gpu":data=instantServerConfigurations.instantsWithGPU;break;case"5-bare-metal":data=instantServerConfigurations.fiveBareMetal;break;case"entry-level":data=instantServerConfigurations.entryLevel;break;case"nvme":data=instantServerConfigurations.nvme;break;case"ssd":data=instantServerConfigurations.ssd;break;case"hdd":data=instantServerConfigurations.hdd;break;case"dual-cpu":data=instantServerConfigurations.dualCPU;break;case"quad-cpu":data=instantServerConfigurations.quadCPU;break;case"custom-gpu":data=instantServerConfigurations.customGPU;break;case"discounted-all":data=instantServerConfigurations.discountedAll;break;case"discounted-entry-level":data=instantServerConfigurations.discountedEntryLevel;break;case"discounted-nvme":data=instantServerConfigurations.discountedNVME;break;case"discounted-dual-cpu":data=instantServerConfigurations.discountedDualCPU;break;case"discounted-quad-cpu":data=instantServerConfigurations.discountedQuadCPU;break;case"discounted-custom-gpu":data=instantServerConfigurations.discountedCustomGPU;break;case"entry-level-gpu":data=instantServerConfigurations.entryLevelGPU;break;case"nvmeGPU":data=instantServerConfigurations.nvmeGPU;break}selectFilteredObject[instantsType]={...selectFilteredObject[instantsType],[componentType]:value};if(!selectFilteredObject[instantsType]||!selectFilteredObject[instantsType][componentType]||selectFilteredObject[instantsType][componentType]==="none"){delete selectFilteredObject[instantsType][componentType]}const entries=Object.entries(selectFilteredObject[instantsType]);let filteredArray=data.filter((item=>entries.every((([key,val])=>{let min=val[0];let max=val[1];if(item.price>=parseFloat(min)&&item.price<=parseFloat(max)&&min&&max){return item}else if(item.price<=parseFloat(min)&&!max){return item}else if(!min&&item.price>=parseFloat(max)){return item}else if(item[key]===val){return item}}))));return filteredArray};function handleTableFilterChange(event){const{target:target}=event;const{dataset:dataset}=target;const{componentType:componentType}=dataset;let value=target.value;let data;const instantServerConfigurations=dataModelGlobal.getInstantServerConfigurations();const numberValues=["ram"];if(numberValues.includes(componentType)){value=parseFloat(value)}if(componentType==="price"){value=value!=="none"?JSON.parse(value):value}const parentElement=uiGlobal.findParent(target,"TABLE","tagName");const{instantsType:instantsType}=parentElement.dataset;const hasGPU=instantsType==="with-gpu"||instantsType==="custom-gpu"||instantsType==="entry-level-gpu"||instantsType==="nvmeGPU";const discountedCustomGPU=instantsType==="discounted-custom-gpu";switch(instantsType){case"without-gpu":data=instantServerConfigurations.instantsWithoutGPU;break;case"with-gpu":data=instantServerConfigurations.instantsWithGPU;break;case"5-bare-metal":data=instantServerConfigurations.fiveBareMetal;break;case"entry-level":data=instantServerConfigurations.entryLevel;break;case"entry-level-gpu":data=instantServerConfigurations.entryLevelGPU;break;case"nvme":data=instantServerConfigurations.nvme;break;case"nvmeGPU":data=instantServerConfigurations.nvmeGPU;break;case"dual-cpu":data=instantServerConfigurations.dualCPU;break;case"quad-cpu":data=instantServerConfigurations.quadCPU;break;case"custom-gpu":data=instantServerConfigurations.customGPU;break;case"discounted-all":data=instantServerConfigurations.discountedAll;break;case"discounted-entry-level":data=instantServerConfigurations.discountedEntryLevel;break;case"discounted-nvme":data=instantServerConfigurations.discountedNVME;break;case"discounted-dual-cpu":data=instantServerConfigurations.discountedDualCPU;break;case"discounted-quad-cpu":data=instantServerConfigurations.discountedQuadCPU;break;case"discounted-custom-gpu":data=instantServerConfigurations.discountedCustomGPU;break}selectFilteredObject[instantsType]={...selectFilteredObject[instantsType],[componentType]:value};if(!selectFilteredObject[instantsType]||!selectFilteredObject[instantsType][componentType]||selectFilteredObject[instantsType][componentType]==="none"){delete selectFilteredObject[instantsType][componentType]}const entries=Object.entries(selectFilteredObject[instantsType]);let filteredArray=data.filter((item=>entries.every((([key,val])=>{let min=val[0];let max=val[1];if(item.price>=parseFloat(min)&&item.price<=parseFloat(max)&&min&&max){return item}else if(item.price<=parseFloat(min)&&!max){return item}else if(!min&&item.price>=parseFloat(max)){return item}else if(item[key]===val){return item}}))));const tbody=document.querySelector(`[data-instants-type="${instantsType}"] tbody.table-configuration-body`);uiGlobal.renderInstantsTable(filteredArray,tbody,hasGPU,discountedCustomGPU);initShowMoreConfigsBtns()}const initShowMoreConfigsBtns=()=>{const showMoreConfigsBtn=document.querySelectorAll(".show-more-configs-btn");if(showMoreConfigsBtn?.length){showMoreConfigsBtn.forEach((item=>item.addEventListener("click",initShowMoreConfigsCustomFilters)))}};const initShowMoreConfigsCustomFilters=event=>{const filteredArray=getFilteredArray(event);showMoreConfigsCustomFilters(event,filteredArray)};const addDuplicatesToTableCustomFilter=(currRow,currTableContainer,currServers)=>{const currRowID=currRow.dataset.rowId;const newServersObj=dataModelGlobal.groupDuplicates(currServers);const sortedNewServersObj=Object.entries(newServersObj).sort(((a,b)=>a[1][0].price-b[1][0].price));let firstItems=[];Object.values(sortedNewServersObj).forEach((item=>{firstItems.push(item[0])}));const currItem=firstItems[currRowID];const currArray=newServersObj[currItem];currArray.shift();let tableBodyHtml="";currArray.sort(((a,b)=>a.price-b.price)).forEach((item=>{const{cpu:cpu,gpu:gpu,ram:ram,hdd:hdd,os:os,traffic:traffic,location:location,type:type,name:name}=item;const discount=item&&JSON.parse(item.discount)&&JSON.parse(item.discount).percent;const initialPrice=item.price;let discountPrice=initialPrice/100*discount;let calculatedPrice=discount?initialPrice-discountPrice:initialPrice;calculatedPrice=calculatedPrice.toFixed(2);const currency=item.location.includes("US")?"$":"€";const initialPriceHTML=initialPrice.toFixed(2);const monthlyHtml=`\n ${discount?`\n ${currency}${initialPriceHTML}\n `:""}\n \n ${currency}${calculatedPrice}\n\n ${discount?`(-${discount}%)`:""}\n `;tableBodyHtml+=`\n \n \n ${cpu}\n ${gpu?`${gpu}`:""}\n ${ram} GB\n ${hdd}\n ${os}\n ${traffic}\n ${location}\n ${monthlyHtml}\n \n \n \n INSTANT\n \n \n \n `}));$(currRow).after(tableBodyHtml)};const addDuplicatesToTable=(currRow,currTableContainer)=>{const currRowID=currRow.dataset.rowId;const parentTableID=currTableContainer.dataset.instantsType;const servers=dataModelGlobal.getInstantServerConfigurations();let currServers=parentTableID==="without-gpu"?servers.instantsWithoutGPU:parentTableID==="with-gpu"?servers.instantsWithGPU:parentTableID==="5-bare-metal"?servers.fiveBareMetal:parentTableID==="entry-level"?servers.entryLevel:parentTableID==="nvme"?servers.nvme:parentTableID==="ssd"?servers.ssd:parentTableID==="hdd"?servers.hdd:parentTableID==="dual-cpu"?servers.dualCPU:parentTableID==="quad-cpu"?servers.quadCPU:parentTableID==="custom-gpu"?servers.customGPU:parentTableID==="discounted-entry-level"?servers.discountedEntryLevel:parentTableID==="discounted-nvme"?servers.discountedNVME:parentTableID==="discounted-dual-cpu"?servers.discountedDualCPU:parentTableID==="discounted-quad-cpu"?servers.discountedQuadCPU:parentTableID==="discounted-custom-gpu"?servers.discountedCustomGPU:()=>{};const newServersObj=dataModelGlobal.groupDuplicates(currServers);const sortedNewServersObj=Object.entries(newServersObj).sort(((a,b)=>a[1][0].price-b[1][0].price));let firstItems=[];Object.values(sortedNewServersObj).forEach((item=>{firstItems.push(item[0])}));const currItem=firstItems[currRowID];const currArray=newServersObj[currItem];currArray.shift();let tableBodyHtml="";currArray.sort(((a,b)=>a.price-b.price)).forEach((item=>{const{cpu:cpu,gpu:gpu,ram:ram,hdd:hdd,os:os,traffic:traffic,location:location,type:type,name:name}=item;const discount=item&&JSON.parse(item.discount)&&JSON.parse(item.discount).percent;const initialPrice=item.price;let discountPrice=initialPrice/100*discount;let calculatedPrice=discount?initialPrice-discountPrice:initialPrice;calculatedPrice=calculatedPrice.toFixed(2);const currency=item.location.includes("US")?"$":"€";const initialPriceHTML=initialPrice.toFixed(2);const monthlyHtml=`\n ${discount?`\n ${currency}${initialPriceHTML}\n `:""}\n \n ${currency}${calculatedPrice}\n\n ${discount?`(-${discount}%)`:""}\n `;tableBodyHtml+=`\n \n \n ${cpu}\n ${gpu?`${gpu}`:""}\n ${ram} GB\n ${hdd}\n ${os}\n ${traffic}\n ${location}\n ${monthlyHtml}\n \n \n \n INSTANT\n \n \n \n `}));$(currRow).after(tableBodyHtml)};const removeDuplicatesToTableCustomFilter=currRow=>{const allAddedEls=$(currRow).nextAll(".new-table-cell");allAddedEls.remove()};const removeDuplicatesToTable=currRow=>{const allAddedEls=$(currRow).nextAll(".new-table-cell");allAddedEls.remove()};const showMoreConfigsCustomFilters=(event,filteredArray)=>{const target=$(event.target);const action=event.target.dataset.actionBtndisplay;if(!action){return}const parents=target.parents();const currRow=parents[1];const currTableContainer=parents[3];if(action==="increment"){addDuplicatesToTableCustomFilter(currRow,currTableContainer,filteredArray);target.text("-").attr("data-action-btndisplay","decrement")}else if(action==="decrement"){removeDuplicatesToTableCustomFilter(currRow);target.text("+").attr("data-action-btndisplay","increment")}};const showMoreConfigs=event=>{const target=$(event.target);const action=event.target.dataset.actionBtndisplay;if(!action){return}const parents=target.parents();const currRow=parents[1];const currTableContainer=parents[3];if(action==="increment"){addDuplicatesToTable(currRow,currTableContainer);target.text("-").attr("data-action-btndisplay","decrement")}else if(action==="decrement"){removeDuplicatesToTable(currRow);target.text("+").attr("data-action-btndisplay","increment")}};function initFilterSelect(){const selectFilters=document.querySelectorAll("select.form-select");if(selectFilters&&selectFilters.length){selectFilters.forEach((item=>item.addEventListener("change",handleTableFilterChange)))}}function initStaticEvents(){const headerContainer=document.querySelector(".included-with-server-header");if(headerContainer){headerContainer.addEventListener("click",displayInfoContainer)}document.addEventListener("click",(event=>{resetClickOutside()}))}function initDynamicallyEvents(){const languageSelectorContainer=document.getElementById("language-selector-container");if(languageSelectorContainer){languageSelectorContainer.addEventListener("click",selectLanguage)}if(!dataModelGlobal.isOrder){const dropdownButtons=document.querySelectorAll(".custom-dropdown-button");if(dropdownButtons&&dropdownButtons.length){dropdownButtons.forEach((item=>item.addEventListener("click",toggleDropdown)))}}}const changePlan=()=>{const switchContainer=document.querySelector(".toggle-switch-container");const allOptions=document.querySelectorAll(".label");const firstOption=document.querySelector("#firstOption");const secondOption=document.querySelector("#secondOption");if(switchContainer){switchContainer.addEventListener("click",(()=>{allOptions.forEach((item=>{if(item.classList.contains("active")){item.classList.remove("active")}else{item.classList.add("active")}}))}))}if(window.location.pathname.includes("custom")){firstOption.classList.remove("active");secondOption.classList.add("active")}};return{initDynamicallyEvents:initDynamicallyEvents,initStaticEvents:initStaticEvents,resetClickOutside:resetClickOutside,toggleDropdown:toggleDropdown,initFilterSelect:initFilterSelect,showMoreConfigs:showMoreConfigs,initShowMoreConfigsBtns:initShowMoreConfigsBtns,changePlan:changePlan}}();