const dataModelGlobal=function(){const endpointInstants="/api/readyservers/config?detail=true";const endpointCustoms="/api/order/config?type=all";const endpointInstantsMoonshots="/api/readyservers/config?type=M%&detail=true";const endpointInstantsDedicated="/api/readyservers/config?type=D%&detail=true";const languagesData=[{imageSrc:"image9.jpg",text:"English",type:"en"},{imageSrc:"image5.jpg",text:"Română",type:"ro"},{imageSrc:"image10.jpg",text:"Español",type:"es"},{imageSrc:"image3.jpg",text:"Portuguesa",type:"pt"},{imageSrc:"image2.jpg",text:"Italiana",type:"it"},{imageSrc:"image4.jpg",text:"Française",type:"fr"},{imageSrc:"image6.jpg",text:"Deutsche",type:"de"},{imageSrc:"image8.jpg",text:"Polski",type:"pl"},{imageSrc:"image1.jpg",text:"Ελληνικά",type:"el"},{imageSrc:"image11.jpg",text:"Türk",type:"tr"},{imageSrc:"image7.jpg",text:"中文",type:"zh"}];const isOrder=window.location.pathname.toLowerCase().includes("order");function random(min,max){min=Math.ceil(min);max=Math.floor(max);return Math.floor(Math.random()*(max-min+1))+min}const getListOfComponents=(criteria,data)=>{const list=[];data.forEach((item=>{if(Object.hasOwn(item,criteria)&&!list.includes(item[criteria])){list.push(item[criteria])}}));if(["cpu","gpu","hdd"].includes(criteria)){return list.sort(sortComponents("descending",criteria))}return list.sort(sortComponents("ascending",criteria))};const setServersFilters=data=>{if(data==="default"){const defaultServerFilters={type:"all",deployment:"instant",location:null,pricing:{minPrice:0,maxPrice:0},hardware:{cpu:null,gpu:null,ram:null,hdd:null,os:null,traffic:null}};return sessionStorage.setItem("serverFilters",JSON.stringify(defaultServerFilters))}return sessionStorage.setItem("serverFilters",JSON.stringify(data))};const getServersFilters=()=>JSON.parse(sessionStorage.getItem("serverFilters"));const setInitialPriceingFilters=data=>{const initialServersFilters=getServersFilters();const sortedServers=data.toSorted(((a,b)=>a.price-b.price));const minPrice=sortedServers.length===0?0:sortedServers[0].price;const maxPrice=sortedServers.length===0?0:sortedServers[sortedServers.length-1].price;const values={minPrice:parseInt(minPrice),maxPrice:Math.ceil(maxPrice)};const newFilterData={...initialServersFilters,pricing:values};sessionStorage.setItem("serverFilters",JSON.stringify(newFilterData))};function calculateOperatingSystem(planConfigurationData,defaultConfig){const controllerKey=defaultConfig.JBOD&&!defaultConfig.EmbeddedRAID?"JBOD":"EmbeddedRAID";if(!defaultConfig[controllerKey]||!defaultConfig[controllerKey].length){return 0}if(!defaultConfig.CPU){return}const selectedOS=planConfigurationData.OS.filter((item=>item.Value===defaultConfig[controllerKey][0].OS))[0];const selectedCPU=planConfigurationData.CPU.filter((item=>item.SubItem===defaultConfig.CPU.SubItem&&item.Value===defaultConfig.CPU.Value))[0];if(!selectedOS||!selectedCPU){return}let price=selectedOS.FixedPrice;const windowsOSPriceItem=planConfigurationData.WindowsOSPrice.filter((item=>selectedOS.Value.includes(item.Value)))[0];const isWindows=selectedOS.WindowsOSPrice;if(isWindows&&windowsOSPriceItem){if(Object.hasOwn(windowsOSPriceItem,"PricePerCore")){const coresCount=selectedCPU.Value*selectedCPU.CoresCount;const minimumLimit=8;price=coresCount<=minimumLimit?windowsOSPriceItem.FixedPrice:windowsOSPriceItem.PricePerCore*coresCount}else{price=windowsOSPriceItem.FixedPrice*selectedCPU.Value}}return price}const getComponentPrice=item=>{let price=0;if(item.FixedPrice){price=item.FixedPrice}if(item.PerValuePrice){price=item.PerValuePrice}return price};function setMockupAllPrices(planConfigurationData,defaultConfig){if(!defaultConfig){return}const prices=Object.keys(defaultConfig).map((key=>{let component;const value=planConfigurationData[key];if(!value){return}switch(key){case"CPU":{component=value.filter((item=>item.SubItem===defaultConfig[key].SubItem&&item.Value===defaultConfig[key].Value))[0];if(component){return{[key]:getComponentPrice(component)}}break}case"EmbeddedRAID":case"JBOD":case"6DiskRAID":case"12DiskRAID":case"24DiskRAID":{const hddPrice=defaultConfig[key].map((item=>{let price=planConfigurationData.HDD.filter((hdd=>hdd.SubItem===item.SubItem))[0];price=price?getComponentPrice(price)*item.Value:0;return price})).reduce(((total,current)=>total+current),0);let operatingSystemPrice=calculateOperatingSystem(planConfigurationData,defaultConfig);operatingSystemPrice=operatingSystemPrice&&(key==="EmbeddedRAID"||key==="JBOD")?operatingSystemPrice:0;let controllerPrice=planConfigurationData.HDController.filter((item=>item.LinkedItems?.[0].SkelItem===key))[0];controllerPrice=Object.hasOwn(controllerPrice,"FixedPrice")?controllerPrice.FixedPrice:0;return{[key]:{hddPrice:hddPrice,operatingSystemPrice:operatingSystemPrice,controllerPrice:controllerPrice}}}case"RAM":case"PortSpeed":{component=value.filter((item=>item.Value===defaultConfig[key]))[0];if(component){return{[key]:getComponentPrice(component)}}break}case"GPU":{component=value.filter((item=>item.Value===defaultConfig[key][0]))[0];if(component){const GPUcount=defaultConfig[key].length;return{[key]:getComponentPrice(component)*GPUcount}}break}case"IPv":{const IPv4=value.filter((item=>{if(item.SubItem.toLowerCase().includes("ipv4")){const currentIPv=defaultConfig[key].filter((item=>item.SubItem.toLowerCase().includes("ipv4")))[0];if(currentIPv){return item.Value===currentIPv.Value}}}))[0];const IPv6=value.filter((item=>{if(item.SubItem.toLowerCase().includes("ipv6")){const currentIPv=defaultConfig[key].filter((item=>item.SubItem.toLowerCase().includes("ipv6")))[0];if(currentIPv){return item.Value===currentIPv.Value}}}))[0];if(IPv4){return{IPv4:getComponentPrice(IPv4),IPv6:IPv6?getComponentPrice(IPv6):0}}break}case"FlashMedia":{component=value.filter((item=>item.Value===defaultConfig[key]))[0];return{[key]:{price:getComponentPrice(component),setupFee:component.SetupPrice}}}case"LinuxOpSoft":case"WindowsOpSoft":{const initialValues=value.map((item=>item.Value));const selectedValues=defaultConfig[key];const formatted=[];initialValues.forEach(((item,index)=>{if(selectedValues.includes(item)){const software=value[index];formatted.push({price:getComponentPrice(software),setupFee:software.SetupPrice,name:software.Value})}}));return{[key]:formatted}}case"Management":{component=value.filter((item=>item.Value===defaultConfig[key]))[0];return{[key]:component.FixedPrice??0}}}})).filter((item=>item));const obj={};prices.forEach((item=>Object.assign(obj,item)));return obj}const calculateMockupTotalPrice=(planConfigurationData,componentPrices)=>{if(!componentPrices){return undefined}const totalWithoutSetupFee=Object.keys(componentPrices).map((key=>{const item=componentPrices[key];let number=item;if(isNaN(item)){switch(key){case"EmbeddedRAID":case"JBOD":case"6DiskRAID":case"12DiskRAID":case"24DiskRAID":number=Object.values(item).reduce(((total,currentNumber)=>total+currentNumber),0);break;case"FlashMedia":number=item.price;break;case"WindowsOpSoft":case"LinuxOpSoft":number=item.map((opsoft=>opsoft.price)).reduce(((total,currentNumber)=>total+currentNumber),0);break}}return number})).reduce(((total,number)=>total+number),0);const setupFeeTotal=Object.keys(componentPrices).map((key=>{const item=componentPrices[key];let number=0;switch(key){case"FlashMedia":number=item.setupFee;break;case"WindowsOpSoft":case"LinuxOpSoft":number=item.map((opsoft=>opsoft.setupFee)).reduce(((total,currentNumber)=>total+currentNumber),0);break}return number})).reduce(((total,number)=>total+number),planConfigurationData.SetupPrice?planConfigurationData.SetupPrice:0);return{totalWithoutSetupFee:totalWithoutSetupFee,setupFeeTotal:setupFeeTotal,totalPrice:totalWithoutSetupFee+setupFeeTotal}};function groupDuplicates(array,hasGpu=false){function groupBy(objectArray,keys){return objectArray.reduce(((group,obj)=>{const combinedKeys=keys.map((key=>obj[key])).join("-");(group[combinedKeys]=group[combinedKeys]??[]).push(obj);return group}),{})}if(hasGpu){return groupBy(array,["cpu","gpu","ram","hdd","os","traffic","location"])}else{return groupBy(array,["cpu","ram","hdd","os","traffic","location"])}}function groupDuplicatesV2(array,hasGpu=false){function groupBy(objectArray,keys){let id=1;return objectArray.reduce(((group,obj)=>{const combinedKeys=keys.map((key=>obj[key])).join("-");(group[combinedKeys]=group[combinedKeys]??[]).push({...obj,id:id});return group}),{})}return groupBy(array,["cpu","gpu","ram","hdd","os","traffic","location"])}let instantServerConfigurations;let customServerConfigurations;const setInstantServersConfigurations=data=>{instantServerConfigurations=data};const setCustomServersConfigurations=data=>{customServerConfigurations=data};const getInstantServerConfigurations=()=>instantServerConfigurations?instantServerConfigurations:{};function getAllInstantsFetch(){return fetch(endpointInstants).then((response=>{utilGlobal.handleError(response,"Instants not found. Please contact the development department.");return response.json()})).then((data=>{const instantsData=data.filter((item=>{if(!item.os||!item.hdd||item.skel.hasOwnProperty("FlexibleStorage")){return}return item}));const allInstants=instantsData;const instantsWithoutGPU=instantsData.filter((item=>!item.gpu));const instantsWithGPU=instantsData.filter((item=>item.gpu));const fiveBareMetal=instantsData.filter((item=>item.type==="M700"&&!item.gpu));const entryLevel=instantsData.filter((item=>item.type.startsWith("M")&&!item.gpu));const entryLevelGPU=instantsData.filter((item=>item.type.startsWith("M")&&item.gpu));const nvme=instantsData.filter((item=>item.hdd.includes("NVMe")&&!item.gpu));const nvmeGPU=instantsData.filter((item=>item.hdd.includes("NVMe")&&item.gpu));const ssd=instantsData.filter((item=>item.hdd.includes("SATA")&&!item.gpu));const hdd=instantsData.filter((item=>item.hdd.includes("SAS")&&!item.gpu));const dualCPU=instantsData.filter((item=>["D103","D104","D105","D106"].includes(item.type)&&!item.gpu));const quadCPU=instantsData.filter((item=>["D156","D157","D158"].includes(item.type)&&!item.gpu));const customGPU=instantsData.filter((item=>["D103","D104","D105","D106"].includes(item.type)&&item.hasOwnProperty("gpu")));const discountedAll=instantsData.filter((item=>!item.gpu&&item.discount&&item.discount.percent));const discountedEntryLevel=instantsData.filter((item=>item.type.startsWith("M")&&!item.gpu&&item.discount&&item.discount.percent));const discountedNVME=instantsData.filter((item=>["M710x","M510"].includes(item.type)&&!item.gpu&&item.discount&&item.discount.percent));const discountedDualCPU=instantsData.filter((item=>["D103","D104","D105","D106"].includes(item.type)&&!item.gpu&&item.discount&&item.discount.percent));const discountedQuadCPU=instantsData.filter((item=>["D156","D157","D158"].includes(item.type)&&!item.gpu&&item.discount&&item.discount.percent));const discountedCustomGPU=instantsData.filter((item=>["D103","D104","D105","D106"].includes(item.type)&&item.hasOwnProperty("gpu")&&item.discount&&item.discount.percent));return{allInstants:allInstants,instantsWithoutGPU:instantsWithoutGPU,instantsWithGPU:instantsWithGPU,fiveBareMetal:fiveBareMetal,entryLevel:entryLevel,entryLevelGPU:entryLevelGPU,nvme:nvme,nvmeGPU:nvmeGPU,ssd:ssd,hdd:hdd,dualCPU:dualCPU,quadCPU:quadCPU,customGPU:customGPU,discountedAll:discountedAll,discountedEntryLevel:discountedEntryLevel,discountedNVME:discountedNVME,discountedDualCPU:discountedDualCPU,discountedQuadCPU:discountedQuadCPU,discountedCustomGPU:discountedCustomGPU}})).catch((error=>console.error(error)))}function getAllPlansFetch(){const ignoredPlans=["D102","xD103","xD990","xD991","D990"];return fetch(endpointCustoms).then((response=>{utilGlobal.handleError(response,"Plans not found. Please contact the development department.");return response.json()})).then((data=>{const arr=data.map((item=>{item.data=JSON.parse(item.data);return item}));const plansObject={};const availablePlans=arr.filter((item=>item.data.type==="dedicated"&&!ignoredPlans.includes(item.type)));for(let i=0;iplansObject[item]));const fiveBareMetalCustom=dedicatedPlans.filter((item=>item.type==="M700"));const entryLevelCustom=dedicatedPlans.filter((item=>item.type.startsWith("M")));const nvmeCustom=dedicatedPlans.filter((item=>["M710x","M510"].includes(item.type)));const dualCPUCustom=dedicatedPlans.filter((item=>["D103","D104","D105","D106"].includes(item.type)));const quadCPUCustom=dedicatedPlans.filter((item=>["D156","D157","D158"].includes(item.type)));const customGPUCustom=dedicatedPlans.filter((item=>["D103","D104","D105","D106"].includes(item.type)));return{dedicatedPlans:dedicatedPlans,fiveBareMetalCustom:fiveBareMetalCustom,entryLevelCustom:entryLevelCustom,nvmeCustom:nvmeCustom,dualCPUCustom:dualCPUCustom,quadCPUCustom:quadCPUCustom,customGPUCustom:customGPUCustom}})).catch((error=>console.error(error)))}function calculateOS(dataObject){const serverInitialData=dataObject.initialServerData??JSON.parse(sessionStorage.getItem("initialServerData"));const finalOrderData=dataObject.finalOrderData??JSON.parse(sessionStorage.getItem("finalOrderData"));const controllerKey=finalOrderData.JBOD&&!finalOrderData.EmbeddedRAID?"JBOD":"EmbeddedRAID";if(!finalOrderData[controllerKey]||!finalOrderData[controllerKey].length){return 0}if(!finalOrderData.CPU){uiGlobal.showGlobalSwalError("Operating system and CPU not found, please contact the development department.");console.error(finalOrderData[controllerKey].length);console.error(finalOrderData.CPU);return}const selectedOS=dataObject.currentOperatingSystem?dataObject.currentOperatingSystem:serverInitialData.OS.find((item=>item.Value===finalOrderData[controllerKey][0].OS));const selectedCPU=serverInitialData.CPU.find((item=>item.SubItem===finalOrderData.CPU.SubItem&&item.Value===finalOrderData.CPU.Value));if(!selectedOS||!selectedCPU){uiGlobal.showGlobalSwalError("Operating system and CPU not found, please contact the development department.");console.error({selectedOS:selectedOS,selectedCPU:selectedCPU});return}let price=selectedOS.FixedPrice??0;const windowsOSPriceItem=serverInitialData.WindowsOSPrice.find((item=>selectedOS.Value.includes(item.Value)));const isWindows=selectedOS.WindowsOSPrice;if(isWindows&&windowsOSPriceItem){if(windowsOSPriceItem.hasOwnProperty("PricePerCore")){const coresCount=selectedCPU.Value*selectedCPU.CoresCount;const minimumLimit=8;price=coresCount<=minimumLimit?windowsOSPriceItem.FixedPrice:windowsOSPriceItem.PricePerCore*coresCount}else{price=windowsOSPriceItem.FixedPrice*selectedCPU.Value}}return price}function initialServerInstantData(){return dataModelGlobal.getAllInstantsFetch().then((instantsData=>{dataModelGlobal.setInstantServersConfigurations({...instantsData});return{...instantsData}}))}const sortComponents=(order,type)=>{if(!order||!type){return}let nameA;let nameB;return function(a,b){if(type==="ram"){nameA=a;nameB=b;if(!nameA||nameA===0){nameA=undefined}if(!nameB||nameB===0){nameB=undefined}}else{nameA=a!==null&&a!==undefined?a.toString().toUpperCase():a;nameB=b!==null&&b!==undefined?b.toString().toUpperCase():b}if(nameA===nameB){return 0}if(nameA===null||nameA===undefined||nameA===""){return 1}if(nameB===null||nameB===undefined||nameB===""){return-1}if(order==="ascending"){return nameA