@extends('layouts.front')
@section('title', 'API Documentation - Fraud Checker')
@section('contents')

{{-- Font Awesome & Google Fonts (আপনার দেওয়া স্টাইল অনুযায়ী) --}}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
<style>
    @import url('https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@300;400;500;600;700&family=Inter:wght@300;400;500;600;700;800&display=swap');
    
    body { font-family: 'Hind Siliguri', 'Inter', sans-serif; background-color: #f8fafc; }

    /* --- সাইডবার স্টাইল (আপনার হুবহু ডিজাইন) --- */
    .sidebar-card { background: #fff; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); overflow: hidden; border: 1px solid #edf2f7; }
    .user-profile-box { text-align: center; padding: 35px 20px; background: #fff; border-bottom: 1px solid #f1f5f9; }
    .user-avatar-wrapper { position: relative; width: 100px; height: 100px; margin: 0 auto 15px; }
    .user-avatar { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; border: 3px solid #4e73df; background-color: #eee; }
    
    .menu-link { display: flex; align-items: center; padding: 14px 20px; color: #64748b; text-decoration: none; border-radius: 12px; margin: 5px 15px; transition: 0.3s; font-weight: 500; font-size: 15px; }
    .menu-link i { width: 30px; font-size: 18px; }
    .menu-link:hover, .menu-link.active { background: #eff6ff; color: #4e73df; }
    .menu-link.active i { color: #4e73df; }
    .menu-link.text-danger:hover { background: #fff1f2; color: #e11d48; }

    /* --- মেইন কন্টেন্ট স্টাইল --- */
    .main-content-card { background: #fff; border-radius: 24px; padding: 40px; box-shadow: 0 20px 40px rgba(0,0,0,0.03); border: 1px solid #edf2f7; }
    
    .api-key-box { background: #f8fafc; border: 2px dashed #cbd5e1; border-radius: 15px; padding: 25px; text-align: center; margin-bottom: 30px; }
    .code-block { background: #1e293b; color: #f8fafc; padding: 20px; border-radius: 12px; position: relative; font-family: 'Courier New', Courier, monospace; font-size: 14px; overflow-x: auto; }
    .endpoint-badge { background: #4e73df; color: #fff; padding: 5px 12px; border-radius: 6px; font-size: 13px; font-weight: 700; margin-right: 10px; }
    .copy-btn { position: absolute; top: 10px; right: 10px; background: rgba(255,255,255,0.1); border: none; color: #fff; padding: 5px 10px; border-radius: 5px; cursor: pointer; transition: 0.3s; }
    .copy-btn:hover { background: rgba(255,255,255,0.2); }

    /* সাব-মেনু স্টাইল */
    .submenu-container {
        background: #fdfdfd; 
        border-radius: 12px;
        margin: 2px 15px;
    }
    .ps-5 {
        padding-left: 45px !important; 
        font-size: 14px !important;    
    }
    .menu-link i.fa-chevron-down {
        transition: transform 0.3s ease;
    }
    .menu-link.open i.fa-chevron-down {
        transform: rotate(180deg);
    }
</style>

<div class="section-padding py-5">
    <div class="container">
        <div class="row g-4">
            
            {{-- সাইডবার --}}
            <div class="col-lg-3">
                <div class="sidebar-card">
                    <div class="user-profile-box">
                        <div class="user-avatar-wrapper">
                            <img src="{{ Auth::user()->photo ? asset('assets/images/users/'.Auth::user()->photo) : 'https://cdn-icons-png.flaticon.com/512/149/149071.png' }}" class="user-avatar">
                        </div>
                        <h6 class="fw-bold text-dark mb-0">{{ Auth::user()->name }}</h6>
                        <span class="badge bg-light text-primary border mt-2">ক্লায়েন্ট</span>
                    </div>
                    <div class="py-3">
                        <a href="{{ route('user.dashboard') }}" class="menu-link"><i class="fa-solid fa-table-columns"></i> ড্যাশবোর্ড</a>
                        
                        <a href="{{ route('user.domains.index') }}" class="menu-link {{ request()->routeIs('user.domains.index') ? 'active' : '' }}">
                            <i class="fa-solid fa-globe"></i> আমার ডোমেইন
                        </a>
                        <a href="{{ route('user.hostings.index') }}" class="menu-link {{ request()->routeIs('user.hostings.index') ? 'active' : '' }}">
                            <i class="fa-solid fa-server"></i> আমার হোস্টিং
                        </a>

                        <div class="menu-item-group">
                            <a href="javascript:void(0);" class="menu-link d-flex justify-content-between align-items-center" onclick="toggleSubMenu(event, 'fraudSubMenu')">
                                <span><i class="fa-solid fa-shield-halved"></i> ফ্রড সার্ভিস</span>
                                <i class="fa-solid fa-chevron-down mt-1" style="font-size: 12px;"></i>
                            </a>
                            
                            <div id="fraudSubMenu" class="submenu-container" style="{{ request()->is('user/fraud*') || request()->is('user/api*') ? 'display: block;' : 'display: none;' }}">
                                <a href="{{ route('user.fraud.check') }}" class="menu-link ps-5 {{ request()->routeIs('user.fraud.check') ? 'active' : '' }}">
                                    <i class="fa-solid fa-user-shield"></i> ফ্রড চেকার
                                </a>
                                
                                <a href="{{ route('user.fraud.pricing') }}" class="menu-link ps-5 {{ request()->routeIs('user.fraud.pricing') ? 'active' : '' }}">
                                    <i class="fa-solid fa-tags"></i> প্যাকেজ কিনুন
                                </a>
                                
                                <a href="{{ route('user.api.docs') }}" class="menu-link ps-5 {{ request()->routeIs('user.api.docs') ? 'active' : '' }}">
                                    <i class="fa-solid fa-code"></i> API ডকুমেন্টেশন
                                </a>
                            </div>
                        </div>

                        <div class="menu-item-group">
                            <a href="javascript:void(0);" class="menu-link d-flex justify-content-between align-items-center {{ request()->is('user/sms*') || request()->is('user/recharge*') ? 'open' : '' }}" onclick="toggleSubMenu(event, 'smsSubMenu')">
                                <span><i class="fa-solid fa-comment-sms"></i> এসএমএস সার্ভিস</span>
                                <i class="fa-solid fa-chevron-down mt-1" style="font-size: 12px;"></i>
                            </a>
                            
                            <div id="smsSubMenu" class="submenu-container" style="{{ request()->is('user/sms*') || request()->is('user/recharge*') ? 'display: block;' : 'display: none;' }}">
                                <a href="{{ route('user.sms.panel') }}" class="menu-link ps-5 {{ request()->routeIs('user.sms.panel') ? 'active' : '' }}">
                                    <i class="fa-solid fa-paper-plane"></i> এসএমএস পাঠান
                                </a>
                                <a href="{{ route('user.sms.history') }}" class="menu-link ps-5 {{ request()->routeIs('user.sms.history') ? 'active' : '' }}">
                                    <i class="fa-solid fa-history"></i> এসএমএস হিস্ট্রি
                                </a>
                                <a href="{{ route('user.recharge.index') }}" class="menu-link ps-5 {{ request()->routeIs('user.recharge.index') ? 'active' : '' }}">
                                    <i class="fa-solid fa-wallet"></i> রিচার্জ করুন
                                </a>
                                <a href="{{ route('user.sms.api_docs') }}" class="menu-link ps-5 {{ request()->routeIs('user.sms.api_docs') ? 'active' : '' }}">
                                    <i class="fa-solid fa-code"></i> এপিআই ডকুমেন্টেশন
                                </a>
                            </div>
                        </div>
                        
                        <a href="{{ route('user.licenses') }}" class="menu-link"><i class="fa-solid fa-key"></i> আমার লাইসেন্স</a>
                        <a href="{{ route('user.support') }}" class="menu-link"><i class="fa-solid fa-headset"></i> সাপোর্ট টিকেট</a>
                        <a href="{{ route('user.profile') }}" class="menu-link"><i class="fa-solid fa-user-gear"></i> প্রোফাইল সেটিংস</a>
                        <a href="{{ route('user.logout') }}" class="menu-link text-danger mt-4"><i class="fa-solid fa-right-from-bracket"></i> লগআউট</a>
                    </div>
                </div>
            </div>

            {{-- মেইন কন্টেন্ট --}}
            <div class="col-lg-9">
                <div class="main-content-card">
                    
                    <div class="text-center mb-5">
                        <h2 class="fw-bold mb-2" style="color: #2d3436;">API ইন্টিগ্রেশন গাইড</h2>
                        <p class="text-muted">আপনার নিজস্ব ওয়েবসাইট বা সফটওয়্যারে আমাদের ফ্রড চেকার যুক্ত করুন।</p>
                    </div>

                    {{-- মেসেজ শো করা --}}
                    @if(Session::has('success'))
                    <div class="alert alert-success border-0 shadow-sm rounded-4 mb-4">
                        <i class="fas fa-check-circle me-2"></i> {{ Session::get('success') }}
                    </div>
                    @endif

                    <div class="api-key-box">
                        <h5 class="fw-bold text-dark mb-3">আপনার ব্যক্তিগত API Key</h5>
                        @if(Auth::user()->api_key)
                            <div class="d-flex justify-content-center align-items-center mb-3">
                                <code class="fs-5 fw-bold text-primary bg-white px-4 py-2 rounded shadow-sm border" id="apiKeyDisplay">{{ Auth::user()->api_key }}</code>
                                <button class="btn btn-light ms-2 border" onclick="copyToClipboard('apiKeyDisplay')"><i class="fa-regular fa-copy"></i></button>
                            </div>
                        @else
                            <div class="alert alert-warning py-2 small">আপনার কোনো API Key তৈরি করা নেই।</div>
                        @endif

                        <form action="{{ route('user.generate.api_key') }}" method="POST">
                            @csrf
                            <button type="submit" class="btn btn-primary px-4 rounded-pill shadow-sm">
                                <i class="fa-solid fa-rotate"></i> {{ Auth::user()->api_key ? 'রিসেট এপিআই কি' : 'নতুন কি জেনারেট করুন' }}
                            </button>
                        </form>
                    </div>

                    <hr class="my-5">

                    <div class="docs-section">
                        <h4 class="fw-bold mb-4"><i class="fa-solid fa-book-open text-primary me-2"></i> এপিআই রেফারেন্স</h4>
                        
                        <div class="mb-4">
                            <h6 class="fw-bold text-dark">অথেন্টিকেশন (Authentication)</h6>
                            <p class="text-muted small">রিকোয়েস্টের হেডারে নিচের কি-টি পাঠাতে হবে:</p>
                            <div class="code-block">
                                x-api-key: {{ Auth::user()->api_key ?? 'YOUR_API_KEY' }}
                            </div>
                        </div>

                        <div class="mb-4">
                            <h6 class="fw-bold text-dark">এন্ডপয়েন্ট (Endpoint)</h6>
                            <div class="d-flex align-items-center bg-light p-3 rounded border">
                                <span class="endpoint-badge">POST</span>
                                <code class="text-dark">{{ url('/api/v1/check-fraud') }}</code>
                            </div>
                        </div>

                        <div class="mb-4">
                            <h6 class="fw-bold text-dark">পিএইচপি কোড স্যাম্পল (PHP cURL)</h6>
                            <div class="code-block">
                                <button class="copy-btn" onclick="copyToClipboard('phpCode')">Copy</button>
                                <pre id="phpCode" class="mb-0 text-white">
$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_URL => "{{ url('/api/v1/check-fraud') }}",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode(['phone' => '017XXXXXXXX']),
    CURLOPT_HTTPHEADER => [
        'x-api-key: {{ Auth::user()->api_key ?? 'YOUR_API_KEY' }}',
        'Content-Type: application/json'
    ],
]);
$response = curl_exec($curl);
echo $response;</pre>
                            </div>
                        </div>

                        <div>
                            <h6 class="fw-bold text-dark">রেসপন্স স্যাম্পল (JSON)</h6>
                            <div class="code-block">
                                <pre class="mb-0 text-info">
{
    "status": "success",
    "is_fraud": true,
    "message": "Reported as fraud",
    "remaining_limit": 49
}</pre>
                            </div>
                        </div>
                    </div>

                    {{-- ================= WORDPRESS PLUGIN SECTION START ================= --}}
                    <hr class="my-5">
                    
                    <div class="plugin-section-wrapper bg-light p-4 rounded-4 border">
                        <div class="row align-items-center">
                            <div class="col-lg-7 mb-4 mb-lg-0">
                                <div class="d-inline-flex align-items-center gap-2 px-3 py-1 rounded-pill bg-white border mb-3">
                                    <i class="fab fa-wordpress text-primary"></i>
                                    <span class="small fw-bold text-dark">Easy Integration</span>
                                </div>
                                <h3 class="fw-bold mb-3" style="color: #2d3436;">
                                    WooCommerce <span class="text-primary">Plugin</span>
                                </h3>
                                <p class="text-muted mb-4">
                                    কোনো কোডিং নলেজ ছাড়াই আপনার ওয়ার্ডপ্রেস সাইটে আমাদের ফ্রড চেকার যুক্ত করুন। আমাদের অফিসিয়াল প্লাগিন ব্যবহার করুন।
                                </p>
                                
                                <div class="d-flex gap-3 flex-wrap">
                                    <span class="badge bg-white text-dark border px-3 py-2"><i class="fas fa-bolt text-warning me-1"></i> Super Fast</span>
                                    <span class="badge bg-white text-dark border px-3 py-2"><i class="fas fa-shield-alt text-success me-1"></i> Secure API</span>
                                    <span class="badge bg-white text-dark border px-3 py-2"><i class="fas fa-sync text-info me-1"></i> Auto Update</span>
                                </div>
                            </div>

                            <div class="col-lg-5">
                                <div class="bg-white p-4 rounded-4 shadow-sm border text-center position-relative">
                                    <img src="https://upload.wikimedia.org/wikipedia/commons/9/98/WordPress_blue_logo.svg" alt="WordPress" width="60" class="mb-3">
                                    
                                    <h5 class="fw-bold mb-1">Fraud Check Plugin</h5>
                                    <p class="text-muted small mb-3">Version: 1.0.2 | Compatible with WP 6.0+</p>

                                    <a href="{{ asset('assets/fraud/creative-design-fraud-checker.zip') }}" class="btn btn-dark w-100 rounded-pill fw-bold py-2" download>
                                        <i class="fas fa-download me-2"></i> প্লাগিন ডাউনলোড
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    {{-- ================= WORDPRESS PLUGIN SECTION END ================= --}}

                </div>
            </div>
        </div>
    </div>
</div>

<script>
    function toggleSubMenu(event, menuId) {
        event.preventDefault();
        const menu = document.getElementById(menuId);
        const link = event.currentTarget;
        
        if (menu.style.display === "none") {
            menu.style.display = "block";
            link.classList.add('open');
        } else {
            menu.style.display = "none";
            link.classList.remove('open');
        }
    }

    function copyToClipboard(elementId) {
        var text = document.getElementById(elementId).innerText;
        navigator.clipboard.writeText(text).then(function() {
            alert("কপি হয়েছে!");
        }, function(err) {
            console.error('Could not copy text: ', err);
        });
    }
</script>

@endsection