@extends('admin.layouts.app')
@section('title', 'Manage Domain: ' . $domain->domain_name)

@section('content')

    <div class="flex flex-col md:flex-row md:justify-between md:items-end mb-8 gap-4">
        <div>
            <h1 class="text-3xl font-extrabold text-white tracking-tight">Domain Configuration</h1>
            <p class="text-slate-400 mt-1 text-sm">{{ $domain->domain_name }}</p>
        </div>
        <div class="flex gap-3">
            <a href="{{ route('admin.domains.index') }}" class="bg-slate-800 border border-slate-700 hover:bg-slate-700 px-4 py-2 rounded-xl text-sm font-medium text-slate-300 transition-colors">
                <i class="fas fa-arrow-left mr-2"></i> Back to List
            </a>
            <a href="{{ $domain->website_url }}" target="_blank" class="bg-slate-800 border border-slate-700 hover:bg-slate-700 px-4 py-2 rounded-xl text-sm font-medium text-blue-400 transition-colors">
                <i class="fas fa-external-link-alt mr-2"></i> Visit Website
            </a>
        </div>
    </div>

    @if(session('success'))
        <div class="bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 px-4 py-3 rounded-xl mb-6 flex items-center gap-3">
            <i class="fas fa-check-circle"></i> {{ session('success') }}
        </div>
    @endif

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        
        <div class="lg:col-span-2 space-y-6">
            
            <div class="bg-slate-800/40 border border-slate-700 rounded-2xl p-6 shadow-lg">
                <h3 class="text-lg font-bold text-white mb-6 border-b border-slate-700 pb-3"><i class="fas fa-info-circle text-blue-400 mr-2"></i> Registration Details</h3>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div>
                        <p class="text-xs text-slate-500 uppercase font-bold tracking-wider mb-1">Domain Name</p>
                        <p class="text-lg font-semibold text-white">{{ $domain->domain_name }}</p>
                    </div>
                    <div>
                        <p class="text-xs text-slate-500 uppercase font-bold tracking-wider mb-1">Owner / Client</p>
                        <a href="{{ route('admin.users.show', $domain->user_id) }}" class="text-lg font-semibold text-blue-400 hover:underline">{{ $domain->user->username ?? 'Unknown' }}</a>
                    </div>
                    <div>
                        <p class="text-xs text-slate-500 uppercase font-bold tracking-wider mb-1">Registration Date</p>
                        <p class="text-slate-300 font-medium">{{ date('d M Y, h:i A', strtotime($domain->created_at)) }}</p>
                    </div>
                    <div>
                        <p class="text-xs text-slate-500 uppercase font-bold tracking-wider mb-1">Expiry Date</p>
                        <p class="text-slate-300 font-medium">{{ date('d M Y', strtotime($domain->expiry_date)) }}</p>
                    </div>
                    <div>
                        <p class="text-xs text-slate-500 uppercase font-bold tracking-wider mb-1">Pricing Plan</p>
                        <p class="text-emerald-400 font-bold text-lg">৳{{ number_format($domain->monthly_price, 2) }} <span class="text-sm font-medium text-slate-500">/ month</span></p>
                    </div>
                    <div>
                        <p class="text-xs text-slate-500 uppercase font-bold tracking-wider mb-1">Hosting IP Address</p>
                        <p class="text-slate-300 font-mono bg-slate-900 px-3 py-1 rounded inline-block border border-slate-700 mt-1">{{ $domain->hosting_ip ?? 'Not Assigned' }}</p>
                    </div>
                </div>
            </div>

            <div class="bg-slate-800/40 border border-slate-700 rounded-2xl p-6 shadow-lg">
                <div class="flex justify-between items-center mb-6 border-b border-slate-700 pb-3">
                    <h3 class="text-lg font-bold text-white"><i class="fas fa-network-wired text-indigo-400 mr-2"></i> DNS Configuration</h3>
                    <span class="bg-indigo-500/10 text-indigo-400 border border-indigo-500/20 px-2.5 py-1 rounded text-xs font-medium">Cloudflare Integration</span>
                </div>
                
                <p class="text-slate-400 text-sm mb-4">Note: The client manages specific DNS records via their user panel. If the domain is suspended, Cloudflare records will be automatically restricted.</p>
                
                <div class="bg-slate-900/50 rounded-xl border border-slate-700 p-4">
                    <div class="flex items-center gap-3 text-slate-300">
                        <i class="fas fa-server text-slate-500"></i>
                        <span>Root Domain: <strong>{{ explode('.', $domain->domain_name, 2)[1] ?? 'Unknown' }}</strong></span>
                    </div>
                </div>
            </div>

        </div>

        <div class="space-y-6">
            
            <div class="bg-slate-800/40 border border-slate-700 rounded-2xl p-6 shadow-lg">
                <h3 class="text-lg font-bold text-white mb-4"><i class="fas fa-shield-alt text-yellow-500 mr-2"></i> Service Control</h3>
                
                <form action="{{ route('admin.domains.status', $domain->id) }}" method="POST">
                    @csrf
                    <div class="mb-5">
                        <label class="block text-xs font-medium text-slate-400 uppercase tracking-wider mb-3">Current Status</label>
                        <div class="relative">
                            <select name="status" class="w-full bg-slate-900 border border-slate-700 text-white text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 p-3 appearance-none outline-none">
                                <option value="active" {{ $domain->status == 'active' ? 'selected' : '' }}>Active (Running)</option>
                                <option value="suspended" {{ $domain->status == 'suspended' ? 'selected' : '' }}>Suspended (Blocked)</option>
                                <option value="expired" {{ $domain->status == 'expired' ? 'selected' : '' }}>Expired (DNS Removed)</option>
                            </select>
                            <i class="fas fa-chevron-down absolute right-4 top-4 text-slate-500 pointer-events-none"></i>
                        </div>
                    </div>
                    
                    <button type="submit" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 rounded-xl shadow-lg shadow-blue-600/20 transition-all hover:scale-[1.02]">
                        <i class="fas fa-sync-alt mr-2"></i> Update Status
                    </button>
                </form>
                
                <div class="mt-4 p-4 bg-orange-500/10 border border-orange-500/20 rounded-xl text-orange-400 text-xs leading-relaxed">
                    <i class="fas fa-exclamation-triangle mb-1 block text-sm"></i>
                    Changing status to <strong>Suspended</strong> or <strong>Expired</strong> will restrict the user from managing this domain and may affect live DNS routing based on your cron configuration.
                </div>
            </div>

        </div>

    </div>

@endsection
