var __awaiter=this&&this.__awaiter||function(e,t,a,i){return new(a||(a=Promise))(function(r,s){function o(e){try{d(i.next(e))}catch(e){s(e)}}function n(e){try{d(i.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?r(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(o,n)}d((i=i.apply(e,t||[])).next())})};import e from"@openremote/core";import{i18next as t}from"@openremote/or-translate";export var DashboardSizeOption;!function(e){e[e.DESKTOP=0]="DESKTOP",e[e.MOBILE=1]="MOBILE"}(DashboardSizeOption||(DashboardSizeOption={}));export class DashboardService{static create(t){return __awaiter(this,arguments,void 0,function*(t,a=DashboardSizeOption.DESKTOP,i=e.displayRealm,r=!0){var s;let o=()=>(Math.random()+1).toString(36).substring(2);return(t?(t.id=void 0,t.template&&(t.template.id=o(),null==(s=t.template.widgets)||s.forEach(e=>e.id=o()))):t={realm:i,displayName:this.getDefaultDisplayName(a),template:{id:o(),columns:this.getDefaultColumns(a),maxScreenWidth:this.getDefaultMaxScreenWidth(a),refreshInterval:"OFF",screenPresets:this.getDefaultScreenPresets(a)}},r)?(yield e.rest.api.DashboardResource.create(t)).data:t})}static delete(t){return __awaiter(this,arguments,void 0,function*(t,a=e.displayRealm){return(yield e.rest.api.DashboardResource.delete(a,t)).data})}static getDefaultColumns(e){switch(e){case DashboardSizeOption.MOBILE:return 4;case DashboardSizeOption.DESKTOP:default:return 12}}static getDefaultDisplayName(e){switch(e){case DashboardSizeOption.DESKTOP:return t.t("dashboard.initialName");case DashboardSizeOption.MOBILE:return t.t("dashboard.initialName")+" ("+t.t("dashboard.size.mobile")+")"}}static getDefaultScreenPresets(e){return e===DashboardSizeOption.MOBILE?[{id:"mobile",displayName:"dashboard.size.mobile",breakpoint:640,scalingPreset:"KEEP_LAYOUT"}]:[{id:"mobile",displayName:"dashboard.size.mobile",breakpoint:640,scalingPreset:"WRAP_TO_SINGLE_COLUMN"}]}static getDefaultMaxScreenWidth(e){switch(e){case DashboardSizeOption.DESKTOP:return 4e3;case DashboardSizeOption.MOBILE:return 640}}}