@extends('admin.layout')

@section('title', 'Backup & Restore')
@section('page_title', 'Backup & Restore')

@section('extra_styles')
@include('admin.partials.settings-styles')
@endsection

@section('content')
<div class="adm-page-header">
    <h1 class="adm-page-title"><i class="bi bi-archive"></i> Backup & Restore</h1>
</div>

@if(session('success'))
<div class="adm-alert adm-alert-success" style="margin-bottom:20px;">
    <i class="bi bi-check-circle-fill"></i>
    <span>{{ session('success') }}</span>
    <button class="adm-alert-close" type="button"><i class="bi bi-x"></i></button>
</div>
@endif

@if($errors->any())
<div class="adm-alert adm-alert-error" style="margin-bottom:20px;">
    <i class="bi bi-exclamation-triangle-fill"></i>
    <span>{{ $errors->first() }}</span>
    <button class="adm-alert-close" type="button"><i class="bi bi-x"></i></button>
</div>
@endif

<div class="settings-section">
    <div class="settings-section-header">
        <i class="bi bi-archive"></i>
        Users &amp; Settings Backup
    </div>
    <div class="settings-section-body">

        <div class="setting-row">
            <div class="setting-label">
                <strong>Export users &amp; settings</strong>
                <small>Downloads a JSON file containing all user accounts and system settings. Does not include media files.</small>
            </div>
            <div class="setting-control">
                <a href="{{ route('admin.backup.users-settings') }}" class="adm-btn adm-btn-primary">
                    <i class="bi bi-download"></i> Download Backup
                </a>
            </div>
        </div>

        <div class="setting-row">
            <div class="setting-label">
                <strong>Restore users &amp; settings</strong>
                <small>Upload a previously exported backup JSON. Existing users are matched by email and updated; new users are created. Settings are merged.</small>
            </div>
            <div class="setting-control">
                <form method="POST" action="{{ route('admin.backup.restore') }}" enctype="multipart/form-data" id="restoreForm">
                    @csrf
                    <input type="file" name="backup" id="restoreFile" accept=".json" style="display:none"
                           onchange="document.getElementById('restoreForm').submit()">
                    <button type="button" class="adm-btn" onclick="document.getElementById('restoreFile').click()">
                        <i class="bi bi-upload"></i> Upload &amp; Restore
                    </button>
                </form>
            </div>
        </div>

    </div>
</div>
@endsection
