<?php
// restore-files.php

if (!current_user_can('manage_options')) {
    wp_die('Access denied.');
}

check_admin_referer('restore_nonce');

$selectedFile = isset($_POST['file']) ? $_POST['file'] : '';

if (empty($selectedFile)) {
    wp_die('Invalid file.');
}

// Perform the restore action
$restore_result = restore_action($selectedFile);
$status = $restore_result['status'];
$output = $restore_result['output'];

// Display success or error message based on the exit status
if ($status === 0) {
    echo '<div class="notice notice-success"><p>' . esc_html__('Successfully Restored Backup!', 'text-domain') . '</p>';
    foreach ($output as $line) {
        echo '<p><strong>' . esc_html($line) . '</strong></p>';
    }
    echo '</div>';
} else {
    echo '<div class="notice notice-error"><p>' . esc_html__('Error Restoring Backup!', 'text-domain') . '</p>';
    foreach ($output as $line) {
        echo '<p><strong>' . esc_html($line) . '</strong></p>';
    }
    echo '</div>';
}
?>
