'use client'

import Link from 'next/link'
import { Card } from '@/libs/frontend-ui-primitives'
import PageIntro from '@/components/common/PageIntro'

const FACTORS = [
  ['Execution integrity', '25', 'Success/failure, receipt posture, and basic execution certainty.'],
  ['Decode clarity', '15', 'Whether the explorer can identify the method and its structured parameters.'],
  ['Counterparty traceability', '15', 'Visibility of sender, recipient or created contract, block, and timestamp anchoring.'],
  ['Asset posture', '20', 'Whether transferred assets look GRU-aware, x402-ready, and ISO-20022-aligned.'],
  ['Audit richness', '15', 'Presence of token transfers, internal calls, raw input, and decoded input.'],
  ['Exception hygiene', '10', 'Penalty when revert reasons or failed execution are visible.'],
]

export default function TransactionComplianceDocsPage() {
  return (
    <div className="container mx-auto px-4 py-6 sm:py-8">
      <PageIntro
        eyebrow="Explorer Documentation"
        title="Transaction Evidence Matrix"
        description="A practical explorer-side heuristic for scoring how well a transaction is evidenced, decoded, and aligned with GRU, x402, and ISO-20022 posture."
        actions={[
          { href: '/transactions', label: 'Browse transactions' },
          { href: '/docs/gru', label: 'GRU guide' },
          { href: '/search?q=cUSDT', label: 'Search cUSDT' },
          { href: '/search', label: 'Search explorer' },
        ]}
      />

      <div className="space-y-6">
        <Card title="What This Score Means">
          <div className="space-y-3 text-sm text-gray-600 dark:text-gray-400">
            <p>
              This is an explorer-visible review heuristic, not a legal, regulatory, or final compliance determination. It grades how much structured evidence
              the explorer can see around a transaction and how well the transferred assets align with the repo’s GRU, x402, and ISO-20022 posture.
            </p>
            <p>
              It is useful for triage, review, and operations. It should not be mistaken for a substitute for off-chain policy, regulated workflow approval,
              or settlement-finality review.
            </p>
            <p>
              A live example is available on transaction detail pages wherever the explorer has enough decoded context to score execution integrity, traceability,
              asset posture, and audit richness.
            </p>
            <p>
              The easiest way to verify the feature is to start from a live GRU token page such as
              {' '}<Link href="/tokens/0x93E66202A11B1772E55407B32B44e5Cd8eda7f22" className="text-primary-600 hover:underline">cUSDT</Link>,
              open a recent transfer, and inspect the review card on the transaction detail page.
            </p>
          </div>
        </Card>

        <Card title="Scoring Factors">
          <div className="space-y-3">
            {FACTORS.map(([label, max, summary]) => (
              <div key={label} className="rounded-2xl border border-gray-200 bg-gray-50 p-4 dark:border-gray-700 dark:bg-gray-900/40">
                <div className="flex items-center justify-between gap-3">
                  <div className="font-medium text-gray-900 dark:text-white">{label}</div>
                  <div className="text-sm text-gray-600 dark:text-gray-400">{max} points</div>
                </div>
                <div className="mt-2 text-sm text-gray-600 dark:text-gray-400">{summary}</div>
              </div>
            ))}
          </div>
        </Card>

        <Card title="Grades">
          <div className="space-y-2 text-sm text-gray-600 dark:text-gray-400">
            <div><strong className="text-gray-900 dark:text-white">A:</strong> 90-100, very strong explorer-visible evidence quality.</div>
            <div><strong className="text-gray-900 dark:text-white">B:</strong> 80-89, strong with minor evidence gaps.</div>
            <div><strong className="text-gray-900 dark:text-white">C:</strong> 70-79, broadly understandable but with gaps.</div>
            <div><strong className="text-gray-900 dark:text-white">D:</strong> 60-69, limited evidence comfort.</div>
            <div><strong className="text-gray-900 dark:text-white">E:</strong> below 60, weak explorer-visible evidence quality.</div>
          </div>
        </Card>

        <Card title="How To Verify It Live">
          <div className="space-y-3 text-sm text-gray-600 dark:text-gray-400">
            <p>1. Open a token detail page for a GRU-tracked asset.</p>
            <p>2. Follow one of the recent transfers into its transaction detail page.</p>
            <p>3. Confirm the transaction page shows decoded execution context, transfer posture, and the transaction review card.</p>
            <p>4. Use the GRU guide to cross-check why asset posture contributes to the score.</p>
          </div>
        </Card>

        <Card title="Further Reading">
          <div className="flex flex-wrap gap-3 text-sm">
            <Link href="/docs/gru" className="text-primary-600 hover:underline">
              GRU guide →
            </Link>
            <Link href="/search?q=cUSDT" className="text-primary-600 hover:underline">
              Search cUSDT →
            </Link>
            <Link href="/docs" className="text-primary-600 hover:underline">
              General documentation →
            </Link>
          </div>
        </Card>
      </div>
    </div>
  )
}
