+watch(simulatorState, () => {
+ state.value.renderSimulator = randomUUID()
+})
+
+const clearTemplates = (): void => {
+ if (app != null) {
+ app.appContext.config.globalProperties.$templates.value = []
+ }
+}
+
+const clearChargingStations = (): void => {
+ if (app != null) {
+ app.appContext.config.globalProperties.$chargingStations.value = []
+ }
+}
+
+const uiClient = useUIClient()
+
+const $toast = useToast()
+
+const getSimulatorState = (): void => {
+ if (state.value.gettingSimulatorState === false) {
+ state.value.gettingSimulatorState = true
+ uiClient
+ .simulatorState()
+ .then((response: ResponsePayload) => {
+ simulatorState.value = response.state as SimulatorState
+ })
+ .catch((error: Error) => {
+ $toast.error('Error at fetching simulator state')
+ console.error('Error at fetching simulator state:', error)
+ })
+ .finally(() => {
+ state.value.gettingSimulatorState = false
+ })
+ }
+}
+
+const getTemplates = (): void => {
+ if (state.value.gettingTemplates === false) {
+ state.value.gettingTemplates = true
+ uiClient
+ .listTemplates()
+ .then((response: ResponsePayload) => {
+ if (app != null) {
+ app.appContext.config.globalProperties.$templates.value = response.templates
+ }
+ })
+ .catch((error: Error) => {
+ clearTemplates()
+ $toast.error('Error at fetching charging station templates')
+ console.error('Error at fetching charging station templates:', error)
+ })
+ .finally(() => {
+ state.value.gettingTemplates = false
+ })
+ }
+}
+
+const getChargingStations = (): void => {
+ if (state.value.gettingChargingStations === false) {
+ state.value.gettingChargingStations = true
+ uiClient
+ .listChargingStations()
+ .then((response: ResponsePayload) => {
+ if (app != null) {
+ app.appContext.config.globalProperties.$chargingStations.value = response.chargingStations
+ }
+ })
+ .catch((error: Error) => {
+ clearChargingStations()
+ $toast.error('Error at fetching charging stations')
+ console.error('Error at fetching charging stations:', error)
+ })
+ .finally(() => {
+ state.value.gettingChargingStations = false
+ })
+ }