/*! phoscon-app 2025-05-20 */

import{serviceSend}from"./settings-gateway-machine.js";import{states,events}from"./settings-gateway-constants.js";import{createBackup,loadBackup,unloadListener}from"./settings-gateway-functions.js";const CREATE_BACKUP_TIME=3e3,LOAD_BACKUP_SUCCESS_TIME=2e4,LOAD_BACKUP_FAIL_TIME=3e3;export var generalBackupViewHandlerFactory=view=>(ctx,activity)=>{let event=activity.type;event===states.GENERAL_BACKUP_GW?(view.show(),view.page1()):event===events.CLOSE_PRESSED&&(view.hide(),serviceSend(states.IDLE))};export var generalBackupView1HandlerFactory=view=>(ctx,activity)=>{let event=activity.type;event===states.CREATE_BACKUP_PAGE_1?(window.addEventListener("beforeunload",unloadListener),view.pageCreate1(),createBackup()):event===events.CREATE_BACKUP_SUCCESS?app.createBackupTimer=setTimeout(function(){serviceSend(states.CREATE_BACKUP_PAGE_2)},3e3):event===events.CREATE_BACKUP_FAIL&&(app.createBackupTimer=setTimeout(function(){serviceSend(states.CREATE_BACKUP_PAGE_3)},3e3))};export var generalBackupView2HandlerFactory=view=>(ctx,activity)=>{let event=activity.type;event===states.CREATE_BACKUP_PAGE_2?view.pageCreateOk():event===events.NEXT_PRESSED&&(window.removeEventListener("beforeunload",unloadListener),window.location.href="//"+app.session.gw+"/deCONZ.tar.gz",serviceSend(states.CREATE_BACKUP_PAGE_2_AFTER_DOWNLOAD))};export var generalBackupView2AfterDownloadHandlerFactory=view=>(ctx,activity)=>{activity.type===states.CREATE_BACKUP_PAGE_2_AFTER_DOWNLOAD&&(window.removeEventListener("beforeunload",unloadListener),view.pageCreateOkAfterDownload())};export var generalBackupView3HandlerFactory=view=>(ctx,activity)=>{activity.type===states.CREATE_BACKUP_PAGE_3&&(window.removeEventListener("beforeunload",unloadListener),view.pageCreateFail())};export var generalBackupViewLoad1HandlerFactory=view=>(ctx,activity)=>{let event=activity.type;event===states.LOAD_BACKUP_PAGE_1?view.pageLoad1():event===events.NEXT_PRESSED&&serviceSend(states.LOAD_BACKUP_PAGE_2_INVALID)};export var generalBackupViewLoad2HandlerFactory=view=>(ctx,activity)=>{let event=activity.type;event===states.LOAD_BACKUP_PAGE_2_INVALID?view.pageLoad2Invalid():event===states.LOAD_BACKUP_PAGE_2_VALID?view.pageLoad2Valid():event===events.NEXT_PRESSED&&serviceSend(states.LOAD_BACKUP_PAGE_3)};export var generalBackupViewLoad3HandlerFactory=view=>(ctx,activity)=>{let event=activity.type;event===states.LOAD_BACKUP_PAGE_3?(window.addEventListener("beforeunload",unloadListener),view.pageLoad3(),view.uploadFile()):event===events.LOAD_BACKUP_SUCCESS?app.createBackupTimer=setTimeout(function(){serviceSend(states.LOAD_BACKUP_PAGE_4)},2e4):event===events.LOAD_BACKUP_FAIL&&(app.createBackupTimer=setTimeout(function(){serviceSend(states.LOAD_BACKUP_PAGE_5)},3e3))};export var generalBackupViewLoadOkHandlerFactory=view=>(ctx,activity)=>{activity.type===states.LOAD_BACKUP_PAGE_4&&(window.removeEventListener("beforeunload",unloadListener),view.pageLoadOk())};export var generalBackupViewLoadFailHandlerFactory=view=>(ctx,activity)=>{activity.type===states.LOAD_BACKUP_PAGE_5&&(window.removeEventListener("beforeunload",unloadListener),view.pageLoadFail())};