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}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 getRandomCustom(array,type){const initialArray=array.filter((item=>item.type===type));return initialArray[random(0,initialArray.length-1)]}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 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"].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"].includes(item.type)&&item.hasOwnProperty("gpu")));const discountedAll=instantsData.filter((item=>!item.gpu&&item.discount!==null&&item.discount!=='{"percent":0}'));const discountedEntryLevel=instantsData.filter((item=>item.type.startsWith("M")&&!item.gpu&&item.discount!==null&&item.discount!=='{"percent":0}'));const discountedNVME=instantsData.filter((item=>["M710x","M510"].includes(item.type)&&!item.gpu&&item.discount!==null&&item.discount!=='{"percent":0}'));const discountedDualCPU=instantsData.filter((item=>["D103","D104","D105"].includes(item.type)&&!item.gpu&&item.discount!==null&&item.discount!=='{"percent":0}'));const discountedQuadCPU=instantsData.filter((item=>["D156","D157","D158"].includes(item.type)&&!item.gpu&&item.discount!==null&&item.discount!=='{"percent":0}'));const discountedCustomGPU=instantsData.filter((item=>["D103","D104","D105"].includes(item.type)&&item.hasOwnProperty("gpu")&&item.discount!==null&&item.discount!=='{"percent":0}'));return{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","D106"];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}));let dedicatedPlans=arr.filter((item=>item.data.type==="dedicated"&&!ignoredPlans.includes(item.type)));let temp=dedicatedPlans[1];dedicatedPlans[1]=dedicatedPlans[0];dedicatedPlans[0]=temp;temp=dedicatedPlans[2];dedicatedPlans[2]=dedicatedPlans[1];dedicatedPlans[1]=temp;temp=dedicatedPlans[12];dedicatedPlans[12]=dedicatedPlans[2];dedicatedPlans[2]=temp;temp=dedicatedPlans[7];dedicatedPlans[7]=dedicatedPlans[3];dedicatedPlans[3]=temp;temp=dedicatedPlans[7];dedicatedPlans[7]=dedicatedPlans[4];dedicatedPlans[4]=temp;temp=dedicatedPlans[7];dedicatedPlans[7]=dedicatedPlans[5];dedicatedPlans[5]=temp;temp=dedicatedPlans[8];dedicatedPlans[8]=dedicatedPlans[6];dedicatedPlans[6]=temp;temp=dedicatedPlans[11];dedicatedPlans[11]=dedicatedPlans[7];dedicatedPlans[7]=temp;temp=dedicatedPlans[12];dedicatedPlans[12]=dedicatedPlans[8];dedicatedPlans[8]=temp;temp=dedicatedPlans[11];dedicatedPlans[11]=dedicatedPlans[9];dedicatedPlans[9]=temp;temp=dedicatedPlans[12];dedicatedPlans[12]=dedicatedPlans[10];dedicatedPlans[10]=temp;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"].includes(item.type)));const quadCPUCustom=dedicatedPlans.filter((item=>["D156","D157","D158"].includes(item.type)));const customGPUCustom=dedicatedPlans.filter((item=>["D103","D104","D105"].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(initialData,finalData){const serverInitialData=initialData??JSON.parse(sessionStorage.getItem("initialServerData"));const finalOrderData=finalData??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=serverInitialData.OS.filter((item=>item.Value===finalOrderData[controllerKey][0].OS))[0];const selectedCPU=serverInitialData.CPU.filter((item=>item.SubItem===finalOrderData.CPU.SubItem&&item.Value===finalOrderData.CPU.Value))[0];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;const windowsOSPriceItem=serverInitialData.WindowsOSPrice.filter((item=>selectedOS.Value.includes(item.Value)))[0];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}}))}return{endpointInstants:endpointInstants,endpointCustoms:endpointCustoms,endpointInstantsMoonshots:endpointInstantsMoonshots,endpointInstantsDedicated:endpointInstantsDedicated,languagesData:languagesData,isOrder:isOrder,getAllInstantsFetch:getAllInstantsFetch,getAllPlansFetch:getAllPlansFetch,setInstantServersConfigurations:setInstantServersConfigurations,getInstantServerConfigurations:getInstantServerConfigurations,setCustomServersConfigurations:setCustomServersConfigurations,random:random,groupDuplicates:groupDuplicates,getRandomCustom:getRandomCustom,calculateOS:calculateOS,initialServerInstantData:initialServerInstantData}}();