@extends('layouts.master')
@section('title', 'رخصة إعادة البيع والتوزيع')

@section('content')
<div style="max-width: 950px; margin: 0 auto;">

    {{-- Hero Header --}}
    <div style="text-align: center; padding: 40px 20px; background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%); color: #fff; margin: -20px -40px 30px; border-bottom: 4px solid #e94560; position: relative; overflow: hidden;">
        <div style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: url('data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><circle cx=%2250%22 cy=%2250%22 r=%2240%22 fill=%22none%22 stroke=%22rgba(255,255,255,0.03)%22 stroke-width=%222%22/></svg>') repeat; opacity: 0.5;"></div>
        <div style="position: relative; z-index: 1;">
            <div style="display: inline-block; background: #e94560; color: #fff; padding: 6px 20px; border-radius: 30px; font-size: 0.85em; font-weight: 700; margin-bottom: 15px; letter-spacing: 1px;">{{ $reseller['reseller_badge'] ?? 'RESELLER LICENSE' }}</div>
            <h1 style="font-weight: 900; font-size: 2.2em; margin-bottom: 8px; color: #fff;">{{ $reseller['reseller_title'] ?? 'رخصة إعادة البيع والتوزيع' }}</h1>
            <p style="font-size: 1.15em; opacity: 0.85; margin-bottom: 15px; max-width: 600px; margin-left: auto; margin-right: auto; font-weight: 600;">{{ $reseller['reseller_subtitle'] ?? 'احصل على حق إعادة بيع وتوزيع السكريبت لعملائك بعلامتك التجارية الخاصة' }}</p>
            @if(!empty($reseller['reseller_price']))
            <div style="margin-top: 20px;">
                <span style="font-size: 1em; opacity: 0.6; text-decoration: line-through; margin-left: 10px;">{{ $reseller['reseller_old_price'] ?? '' }}</span>
                <span style="font-size: 2.8em; font-weight: 900; color: #e94560;">{{ $reseller['reseller_price'] }}</span>
            </div>
            <div style="font-size: 0.85em; opacity: 0.6; margin-top: 5px;">{{ $reseller['reseller_price_note'] ?? 'دفعة واحدة - بدون اشتراكات شهرية' }}</div>
            @endif
        </div>
    </div>

    {{-- Why Reseller --}}
    <div style="margin-bottom: 30px;">
        <h2 style="text-align: center; font-weight: 900; color: #1a1a2e; margin-bottom: 8px; font-size: 1.6em;">{{ $reseller['reseller_why_title'] ?? 'لماذا رخصة إعادة البيع؟' }}</h2>
        <p style="text-align: center; color: #666; font-size: 1em; margin-bottom: 25px; max-width: 600px; margin-left: auto; margin-right: auto;">{{ $reseller['reseller_why_desc'] ?? 'فرصة استثمارية حقيقية لتحقيق دخل متكرر من بيع السكريبت' }}</p>

        <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 18px;">
            @foreach($resellerFeatures as $f)
            <div style="background: linear-gradient(135deg, #f8f9ff 0%, #eef0ff 100%); border: 2px solid #d0d4f0; padding: 22px 18px; text-align: center; transition: all 0.3s; border-radius: 4px;">
                @if(!empty($f['icon']))
                <div style="font-size: 2.5em; margin-bottom: 8px;">{{ $f['icon'] }}</div>
                @endif
                <h4 style="font-weight: 800; color: #1a1a2e; margin-bottom: 6px; font-size: 1.05em;">{{ $f['title'] }}</h4>
                @if(!empty($f['desc']))
                <p style="color: #555; font-size: 0.88em; margin: 0; line-height: 1.6;">{{ $f['desc'] }}</p>
                @endif
            </div>
            @endforeach
        </div>
    </div>

    {{-- What's Included --}}
    @php $resellerIncludes = json_decode(\App\SiteSetting::get('reseller_includes', '[]'), true) ?: []; @endphp
    @if(count($resellerIncludes) > 0)
    <div style="margin-bottom: 30px; background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); padding: 30px 25px; color: #fff;">
        <h3 style="font-weight: 900; text-align: center; margin-bottom: 20px; color: #e94560; font-size: 1.4em;">{{ $reseller['reseller_includes_title'] ?? 'ماذا تحصل مع رخصة إعادة البيع؟' }}</h3>
        <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; max-width: 750px; margin: 0 auto;">
            @foreach($resellerIncludes as $item)
            <div style="display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.08); padding: 12px 15px; border-right: 3px solid #e94560;">
                <span style="color: #4ecca3; font-size: 1.3em; flex-shrink: 0;">✓</span>
                <span style="font-size: 0.95em;">{{ $item }}</span>
            </div>
            @endforeach
        </div>
    </div>
    @endif

    {{-- Comparison Table --}}
    <div style="margin-bottom: 30px;">
        <h3 style="text-align: center; font-weight: 900; color: #1a1a2e; margin-bottom: 20px; font-size: 1.4em;">مقارنة بين الرخص</h3>
        <div style="overflow-x: auto;">
            <table style="width: 100%; border-collapse: collapse; font-size: 0.92em;">
                <thead>
                    <tr>
                        <th style="background: #1a1a2e; color: #fff; padding: 14px; text-align: right; font-weight: 700;">الميزة</th>
                        <th style="background: #7777CC; color: #fff; padding: 14px; text-align: center; font-weight: 700;">الرخصة العادية</th>
                        <th style="background: #e94560; color: #fff; padding: 14px; text-align: center; font-weight: 700;">رخصة إعادة البيع ⭐</th>
                    </tr>
                </thead>
                <tbody>
                    @php
                    $comparisons = json_decode(\App\SiteSetting::get('reseller_comparison', '[]'), true) ?: [];
                    @endphp
                    @foreach($comparisons as $i => $comp)
                    <tr style="background: {{ $i % 2 == 0 ? '#f8f9ff' : '#fff' }};">
                        <td style="padding: 12px 14px; border-bottom: 1px solid #e0e0e0; font-weight: 600;">{{ $comp['feature'] }}</td>
                        <td style="padding: 12px 14px; border-bottom: 1px solid #e0e0e0; text-align: center;">{!! $comp['normal'] == '✓' ? '<span style="color: #4ecca3; font-size: 1.2em;">✓</span>' : ($comp['normal'] == '✗' ? '<span style="color: #e94560; font-size: 1.2em;">✗</span>' : e($comp['normal'])) !!}</td>
                        <td style="padding: 12px 14px; border-bottom: 1px solid #e0e0e0; text-align: center; background: rgba(233,69,96,0.04);">{!! $comp['reseller'] == '✓' ? '<span style="color: #4ecca3; font-size: 1.2em;">✓</span>' : ($comp['reseller'] == '✗' ? '<span style="color: #e94560; font-size: 1.2em;">✗</span>' : e($comp['reseller'])) !!}</td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>

    {{-- How It Works --}}
    @php $resellerSteps = json_decode(\App\SiteSetting::get('reseller_steps', '[]'), true) ?: []; @endphp
    @if(count($resellerSteps) > 0)
    <div style="margin-bottom: 30px; background: #f8f9ff; border: 2px solid #d0d4f0; padding: 25px;">
        <h3 style="font-weight: 900; color: #1a1a2e; margin-bottom: 20px; text-align: center; font-size: 1.4em;">{{ $reseller['reseller_steps_title'] ?? 'كيف تبدأ كموزع؟' }}</h3>
        <div style="max-width: 650px; margin: 0 auto;">
            @foreach($resellerSteps as $i => $step)
            <div style="display: flex; align-items: flex-start; {{ $i < count($resellerSteps) - 1 ? 'margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px dashed #c0c4e0;' : '' }}">
                <div style="background: {{ $i == count($resellerSteps) - 1 ? '#4ecca3' : '#e94560' }}; color: #fff; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 900; flex-shrink: 0; margin-left: 15px; font-size: 1.1em;">{{ $i + 1 }}</div>
                <div>
                    <strong style="color: #1a1a2e; font-size: 1.05em;">{{ $step['title'] }}</strong>
                    @if(!empty($step['desc']))
                    <p style="margin: 5px 0 0; font-size: 0.9em; color: #555; line-height: 1.6;">{{ $step['desc'] }}</p>
                    @endif
                </div>
            </div>
            @endforeach
        </div>
    </div>
    @endif

    {{-- License Terms --}}
    @php
        $resellerAllowed = json_decode(\App\SiteSetting::get('reseller_allowed', '[]'), true) ?: [];
        $resellerNotAllowed = json_decode(\App\SiteSetting::get('reseller_not_allowed', '[]'), true) ?: [];
    @endphp
    @if(count($resellerAllowed) > 0 || count($resellerNotAllowed) > 0)
    <div style="margin-bottom: 30px;">
        <h3 style="text-align: center; font-weight: 900; color: #1a1a2e; margin-bottom: 20px; font-size: 1.4em;">شروط رخصة إعادة البيع</h3>
        <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
            @if(count($resellerAllowed) > 0)
            <div style="background: #e8f5e9; border: 2px solid #66bb6a; padding: 18px;">
                <h4 style="color: #2e7d32; font-weight: 800; text-align: center; margin-bottom: 12px; font-size: 1.1em;">✓ مسموح لك</h4>
                <ul style="list-style: none; padding: 0; margin: 0;">
                    @foreach($resellerAllowed as $a)
                    <li style="padding: 7px 0; border-bottom: 1px solid rgba(46,125,50,0.15); font-size: 0.92em; display: flex; align-items: center; gap: 8px;">
                        <span style="color: #4caf50; font-weight: 900;">✓</span> {{ $a }}
                    </li>
                    @endforeach
                </ul>
            </div>
            @endif
            @if(count($resellerNotAllowed) > 0)
            <div style="background: #fce4ec; border: 2px solid #ef5350; padding: 18px;">
                <h4 style="color: #c62828; font-weight: 800; text-align: center; margin-bottom: 12px; font-size: 1.1em;">✗ غير مسموح</h4>
                <ul style="list-style: none; padding: 0; margin: 0;">
                    @foreach($resellerNotAllowed as $na)
                    <li style="padding: 7px 0; border-bottom: 1px solid rgba(198,40,40,0.15); font-size: 0.92em; display: flex; align-items: center; gap: 8px;">
                        <span style="color: #e53935; font-weight: 900;">✗</span> {{ $na }}
                    </li>
                    @endforeach
                </ul>
            </div>
            @endif
        </div>
        @if(!empty($reseller['reseller_warning']))
        <div style="background: #fff3e0; border: 2px solid #ff9800; padding: 12px; margin-top: 12px; text-align: center; font-size: 0.88em; color: #e65100;">
            <strong>⚠ تنبيه:</strong> {{ $reseller['reseller_warning'] }}
        </div>
        @endif
    </div>
    @endif

    {{-- FAQ --}}
    @php $resellerFaq = json_decode(\App\SiteSetting::get('reseller_faq', '[]'), true) ?: []; @endphp
    @if(count($resellerFaq) > 0)
    <div style="margin-bottom: 30px;">
        <h3 style="text-align: center; font-weight: 900; color: #1a1a2e; margin-bottom: 20px; font-size: 1.4em;">الأسئلة الشائعة</h3>
        @foreach($resellerFaq as $faq)
        <div style="background: #f8f9ff; border: 2px solid #d0d4f0; padding: 15px 20px; margin-bottom: 10px;">
            <strong style="color: #1a1a2e; font-size: 1em;">{{ $faq['q'] }}</strong>
            <p style="margin: 8px 0 0; color: #555; font-size: 0.92em; line-height: 1.7;">{{ $faq['a'] }}</p>
        </div>
        @endforeach
    </div>
    @endif

    {{-- CTA / Contact --}}
    @if(!empty($reseller['reseller_contact']))
    <div style="background: linear-gradient(135deg, #e94560 0%, #c62828 100%); color: #fff; padding: 30px; text-align: center; margin-bottom: 25px;">
        <h3 style="font-weight: 900; color: #fff; margin-bottom: 8px; font-size: 1.5em;">{{ $reseller['reseller_cta_title'] ?? 'جاهز لتبدأ كموزع معتمد؟' }}</h3>
        <p style="opacity: 0.9; margin-bottom: 15px; font-size: 1em;">{{ $reseller['reseller_cta_desc'] ?? 'تواصل معنا الآن للحصول على رخصة إعادة البيع' }}</p>
        <div style="background: rgba(255,255,255,0.15); padding: 15px; display: inline-block; min-width: 300px; border-radius: 4px;">
            <p style="font-size: 1.1em; margin: 0;">{!! nl2br(e($reseller['reseller_contact'])) !!}</p>
        </div>
    </div>
    @endif

    {{-- Verify & Download Section --}}
    <div style="background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); padding: 30px; margin-bottom: 25px; border: 2px solid #e94560;">
        <h3 style="font-weight: 900; color: #fff; text-align: center; margin-bottom: 5px; font-size: 1.4em;">تحميل النسخة المرخصة</h3>
        <p style="text-align: center; color: #aaa; font-size: 0.9em; margin-bottom: 20px;">أدخل مفتاح الترخيص والبريد الإلكتروني لتحميل نسخة الموزع</p>

        @if(session('verify_error'))
        <div style="background: #e8d0d0; border: 2px solid #c88; padding: 12px; text-align: center; color: #a00; margin-bottom: 15px; max-width: 450px; margin-left: auto; margin-right: auto; font-weight: 700;">
            {{ session('verify_error') }}
        </div>
        @endif

        @if(session('verify_success'))
        <div style="background: #d0e8d0; border: 2px solid #8c8; padding: 20px; text-align: center; max-width: 450px; margin: 0 auto 15px;">
            <p style="color: #262; font-weight: 700; font-size: 1.1em; margin-bottom: 10px;">تم التحقق بنجاح! مرحباً {{ session('license')->buyer_name }}</p>
            <a href="/reseller/download?token={{ urlencode(session('download_token')) }}" style="display: inline-block; background: #e94560; color: #fff; padding: 12px 30px; font-weight: 700; font-size: 1.1em; text-decoration: none;">تحميل نسخة الموزع</a>
            <p style="color: #888; font-size: 0.8em; margin-top: 8px;">الرابط صالح لمدة ساعة واحدة</p>
        </div>
        @endif

        <form method="POST" action="/reseller/verify" style="max-width: 450px; margin: 0 auto;">
            @csrf
            <div class="form-group">
                <label style="color: #e94560; font-weight: 700;">مفتاح الترخيص:</label>
                <input type="text" name="license_key" class="form-control" placeholder="XXXX-XXXX-XXXX-XXXX" style="direction: ltr; text-align: center; font-size: 1.1em; letter-spacing: 2px; background: rgba(255,255,255,0.1); color: #fff; border: 2px solid #e94560;" required>
            </div>
            <div class="form-group">
                <label style="color: #e94560; font-weight: 700;">البريد الإلكتروني:</label>
                <input type="email" name="email" class="form-control" placeholder="your@email.com" style="direction: ltr; background: rgba(255,255,255,0.1); color: #fff; border: 2px solid #e94560;" required>
            </div>
            <button type="submit" class="btn btn-block" style="padding: 12px; font-size: 1.1em; font-weight: 700; background: #e94560; color: #fff; border: none;">
                التحقق والتحميل
            </button>
        </form>
    </div>

    {{-- Back to regular purchase --}}
    <div style="text-align: center; margin-bottom: 20px;">
        <a href="/purchase" style="color: #7777CC; font-size: 0.95em;">← العودة لصفحة شراء النسخة العادية</a>
    </div>

</div>
@endsection
