@extends('layout')

@section('title', __('store.account_closure_title'))

@section('content')
<div class="container py-5">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <x-clientarea.page-header
                icon="fas fa-user-slash"
                :title="__('store.account_closure_title')"
                :subtitle="__('store.account_closure_description')"
            />

            
            <div class="card border-0 shadow-sm mb-4">
                <div class="card-header">
                    <h5 class="mb-0"><i class="fas fa-info-circle me-2"></i>{{ __('store.account_closure_summary') }}</h5>
                </div>
                <div class="card-body">
                    <p class="text-muted mb-3">{{ __('store.account_closure_summary_description') }}</p>

                    <div class="row g-3">
                        
                        <div class="col-md-6">
                            <div class="d-flex align-items-center p-3 border rounded h-100">
                                <div class="me-3">
                                    <i class="fas fa-server fa-2x {{ $activeServices->count() > 0 ? 'text-warning' : 'text-muted' }}"></i>
                                </div>
                                <div>
                                    <h6 class="mb-0">{{ __('store.account_closure_active_services') }}</h6>
                                    @if($activeServices->count() > 0)
                                        <span class="text-warning fw-bold">{{ $activeServices->count() }}</span>
                                        <ul class="list-unstyled mb-0 mt-1 small text-muted">
                                            @foreach($activeServices->take(5) as $service)
                                                <li><i class="fas fa-circle fa-xs me-1"></i>{{ $service->name ?? $service->product->name ?? '-' }}</li>
                                            @endforeach
                                            @if($activeServices->count() > 5)
                                                <li class="text-muted">+{{ $activeServices->count() - 5 }} ...</li>
                                            @endif
                                        </ul>
                                    @else
                                        <span class="text-muted small">{{ __('store.account_closure_no_active_items') }}</span>
                                    @endif
                                </div>
                            </div>
                        </div>

                        
                        <div class="col-md-6">
                            <div class="d-flex align-items-center p-3 border rounded h-100">
                                <div class="me-3">
                                    <i class="fas fa-globe fa-2x {{ $activeDomains->count() > 0 ? 'text-warning' : 'text-muted' }}"></i>
                                </div>
                                <div>
                                    <h6 class="mb-0">{{ __('store.account_closure_active_domains') }}</h6>
                                    @if($activeDomains->count() > 0)
                                        <span class="text-warning fw-bold">{{ $activeDomains->count() }}</span>
                                        <ul class="list-unstyled mb-0 mt-1 small text-muted">
                                            @foreach($activeDomains->take(5) as $domain)
                                                <li><i class="fas fa-circle fa-xs me-1"></i>{{ $domain->domain }}</li>
                                            @endforeach
                                            @if($activeDomains->count() > 5)
                                                <li class="text-muted">+{{ $activeDomains->count() - 5 }} ...</li>
                                            @endif
                                        </ul>
                                    @else
                                        <span class="text-muted small">{{ __('store.account_closure_no_active_items') }}</span>
                                    @endif
                                </div>
                            </div>
                        </div>

                        
                        <div class="col-md-6">
                            <div class="d-flex align-items-center p-3 border rounded h-100">
                                <div class="me-3">
                                    <i class="fas fa-file-invoice-dollar fa-2x {{ $unpaidInvoices->count() > 0 ? 'text-danger' : 'text-muted' }}"></i>
                                </div>
                                <div>
                                    <h6 class="mb-0">{{ __('store.account_closure_unpaid_invoices') }}</h6>
                                    @if($unpaidInvoices->count() > 0)
                                        <span class="text-danger fw-bold">{{ $unpaidInvoices->count() }}</span>
                                        <div class="small text-danger">{{ __('store.account_closure_invoice_total', ['amount' => number_format($unpaidTotal, 2)]) }}</div>
                                    @else
                                        <span class="text-muted small">{{ __('store.account_closure_no_active_items') }}</span>
                                    @endif
                                </div>
                            </div>
                        </div>

                        
                        <div class="col-md-6">
                            <div class="d-flex align-items-center p-3 border rounded h-100">
                                <div class="me-3">
                                    <i class="fas fa-wallet fa-2x {{ $creditBalance > 0 ? 'text-warning' : 'text-muted' }}"></i>
                                </div>
                                <div>
                                    <h6 class="mb-0">{{ __('store.account_closure_credit_balance') }}</h6>
                                    <span class="{{ $creditBalance > 0 ? 'text-warning fw-bold' : 'text-muted' }}">{{ number_format($creditBalance, 2) }}</span>
                                    @if($creditBalance > 0)
                                        <div class="small text-muted">{{ __('store.account_closure_balance_lost') }}</div>
                                    @endif
                                </div>
                            </div>
                        </div>
                    </div>

                    @if($activeServices->count() > 0 || $activeDomains->count() > 0 || $unpaidInvoices->count() > 0 || $creditBalance > 0)
                        <div class="alert alert-warning mt-3 mb-0">
                            <i class="fas fa-exclamation-triangle me-2"></i>
                            {{ __('store.account_closure_items_affected') }}
                        </div>
                    @endif
                </div>
            </div>

            
            <div class="card border-0 shadow-sm mb-4 border-start border-4 border-danger">
                <div class="card-body">
                    <h5 class="text-danger mb-3">
                        <i class="fas fa-exclamation-triangle me-2"></i>{{ __('store.account_closure_warning') }}
                    </h5>
                    <ul class="mb-0">
                        <li class="mb-2">
                            <i class="fas fa-server text-danger me-2"></i>{{ __('store.account_closure_warning_services') }}
                        </li>
                        <li class="mb-2">
                            <i class="fas fa-globe text-danger me-2"></i>{{ __('store.account_closure_warning_domains') }}
                        </li>
                        <li class="mb-2">
                            <i class="fas fa-file-invoice text-danger me-2"></i>{{ __('store.account_closure_warning_invoices') }}
                        </li>
                        <li class="mb-2">
                            <i class="fas fa-database text-danger me-2"></i>{{ __('store.account_closure_warning_data') }}
                        </li>
                        <li>
                            <strong><i class="fas fa-ban text-danger me-2"></i>{{ __('store.account_closure_warning_irreversible') }}</strong>
                        </li>
                    </ul>
                </div>
            </div>

            @if($pendingRequest)
                
                <div class="card border-0 shadow-sm mb-4">
                    <div class="card-body text-center py-4">
                        <i class="fas fa-clock fa-3x text-warning mb-3"></i>
                        <h4>{{ __('store.account_closure_pending') }}</h4>
                        <p class="text-muted mb-3">{{ __('store.account_closure_pending_description') }}</p>

                        <div class="mb-3">
                            <span class="badge bg-warning fs-6">
                                <i class="fas fa-hourglass-half me-1"></i>{{ __('store.account_closure_status_pending') }}
                            </span>
                        </div>

                        <p class="text-muted small mb-3">
                            <i class="fas fa-calendar me-1"></i>
                            {{ $pendingRequest->created_at->format($dateTimeFormat) }}
                        </p>

                        <form action="{{ route('store.auth.account-closure.cancel') }}" method="POST">
                            @csrf
                            <button type="submit" class="btn btn-outline-secondary">
                                <i class="fas fa-times me-1"></i>{{ __('store.account_closure_cancel') }}
                            </button>
                        </form>
                    </div>
                </div>
            @else
                
                <div class="card border-0 shadow-sm">
                    <div class="card-body">
                        <form action="{{ route('store.auth.account-closure.request') }}" method="POST">
                            @csrf

                            <div class="mb-3">
                                <label for="reason" class="form-label fw-bold">
                                    {{ __('store.account_closure_reason') }}
                                 <span class="text-danger">*</span></label>
                                <textarea
                                    class="form-control @error('reason') is-invalid @enderror"
                                    id="reason"
                                    name="reason"
                                    rows="5"
                                    required
                                    minlength="10"
                                    placeholder="{{ __('store.account_closure_reason_placeholder') }}"
                                >{{ old('reason') }}</textarea>
                                @error('reason')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="d-grid">
                                <button type="submit" class="btn btn-danger">
                                    <i class="fas fa-paper-plane me-1"></i>{{ __('store.account_closure_submit') }}
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            @endif
        </div>
    </div>
</div>
@endsection
