backupApp.controller('RestoreWizardController', function($scope, $location, BackupList, AppUtils, gettextCatalog) {
    let hasBeenchange = false;
    $scope.backups = BackupList.watch($scope, () => {
        if (hasBeenchange || $scope.backups.length == 0 ) return;

        hasBeenchange = true;
        $scope.selection.backupid = $scope.backups[0].Backup.ID
    });

    $scope.selection = {
        backupid: 'direct' //$scope.backups.length == 0 ? 'direct' : $scope.backups[0].Backup.ID
    };

    $scope.nextPage = function() {
        if ($scope.selection.backupid == 'direct')
            $location.path('/restoredirect');
        else if ($scope.selection.backupid == 'import')
            $location.path('/restore-import');
        else
            $location.path('/restore/' + $scope.selection.backupid);
    };

    $scope.formatDuration = AppUtils.formatDuration;

    // $scope.$watch('backups', () => {
    //     if (hasBeenchange || $scope.backups.length == 0 ) return;

    //     console.log($scope.backups)

    //     hasBeenchange = true;
    //     $scope.selection.backupid = $scope.backups[0].Backup.ID
    // })
});
