<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
    <meta charset="utf-8">
    <title>ACC Shop API — مستندات توسعه‌دهنده</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/acc-engine/assets/css/base/fonts-local.css?v=2">
    <link rel="stylesheet" href="/acc-engine/assets/css/platform-landing.css?v=1">
    <style>
        .docs{max-width:900px;margin:0 auto;padding:40px 24px 80px}
        .docs h1{color:#fff;margin-bottom:8px}
        .docs h2{color:#4ade80;margin:32px 0 12px;font-size:1.1rem;border-bottom:1px solid #334155;padding-bottom:8px}
        .docs table{width:100%;border-collapse:collapse;font-size:.82rem;margin:12px 0}
        .docs th,.docs td{padding:10px 12px;border-bottom:1px solid #1e293b;text-align:right}
        .docs th{background:#1e293b;color:#94a3b8}
        .docs code{font-family:'JetBrains Mono',monospace;background:#0f172a;padding:2px 6px;border-radius:4px;font-size:.78rem;color:#fbbf24;direction:ltr}
        .docs pre{background:#0f172a;padding:16px;border-radius:12px;overflow-x:auto;font-size:.75rem;direction:ltr;text-align:left;color:#86efac;border:1px solid #334155}
        .method{display:inline-block;padding:2px 8px;border-radius:4px;font-size:.7rem;font-weight:700;margin-left:8px}
        .method--get{background:#1e3a5f;color:#60a5fa}
        .method--post{background:#14532d;color:#4ade80}
        .method--put{background:#713f12;color:#fbbf24}
    </style>
</head>
<body>
    <header class="pl-header">
        <a href="/acc-engine/platform.php" class="pl-logo">ACC <span>Shop API</span></a>
        <nav class="pl-nav">
            <a href="/acc-engine/platform.php">پلتفرم</a>
            <a href="/acc-engine/shop.php">دمو</a>
        </nav>
    </header>
    <main class="docs" id="docs-root">
        <h1>مستندات REST API</h1>
        <p style="color:#64748b">بارگذاری…</p>
    </main>
    <script>
    (async () => {
        const root = document.getElementById('docs-root');
        try {
            const r = await fetch('/acc-engine/api.php/acc/v1/public/platform/docs');
            const j = await r.json();
            const d = j.data || {};
            root.innerHTML = `
            <h1>مستندات REST API</h1>
            <p style="color:#64748b;margin-bottom:24px">Base URL: <code>${d.base_url}</code></p>

            <h2>احراز هویت</h2>
            <ul style="color:#cbd5e1;font-size:.85rem">
                <li><b>Public:</b> ${d.auth?.public || ''}</li>
                <li><b>JWT:</b> ${d.auth?.jwt || ''}</li>
                <li><b>API Key:</b> ${d.auth?.api_key || ''}</li>
            </ul>

            <h2>Endpoints</h2>
            <table>
                <thead><tr><th>Method</th><th>Path</th><th>توضیح</th></tr></thead>
                <tbody>${(d.endpoints||[]).map(e => `
                <tr>
                    <td><span class="method method--${e[0].toLowerCase()}">${e[0]}</span></td>
                    <td><code>${e[1]}</code></td>
                    <td>${e[2]}</td>
                </tr>`).join('')}</tbody>
            </table>

            <h2>Webhook Events</h2>
            <pre>${(d.webhooks||[]).join('\n')}</pre>

            <h2>نمونه — ثبت سفارش</h2>
            <pre>POST ${d.base_url}/public/arag/orders/create
Content-Type: application/json

{
  "items": [{ "package_id": 1, "qty": 2 }],
  "billing": { "name": "علی", "phone": "09121234567", "city": "تهران" },
  "shipping_method": "post",
  "payment_method": "zarinpal"
}</pre>

            <h2>Webhook Payload</h2>
            <pre>POST https://your-server.com/hook
X-ACC-Event: order.paid
X-ACC-Signature: sha256={hmac}

{
  "event": "order.paid",
  "timestamp": "2026-07-14T15:00:00+00:00",
  "data": { "id": 42, "order_number": "10042", "total": 350000, ... }
}</pre>
            <p style="margin-top:32px"><a href="/acc-engine/platform.php" class="pl-link">← بازگشت به پلتفرم</a></p>`;
        } catch (e) {
            root.innerHTML = '<h1>خطا</h1><p>' + e.message + '</p>';
        }
    })();
    </script>
</body>
</html>
