@extends('layouts.app')
@section('title','API URLs - NGBVD')

@section('content')
@include('integrations.partials.settings_style')
@php
    $base = url('/');
    $endpoints = $endpoints ?? [
        ['method'=>'GET','url'=>$base.'/api/v2/health','scope'=>'Public / health check','description'=>'Confirms that the API service is available.'],
        ['method'=>'GET','url'=>$base.'/api/v2/reference-data','scope'=>'reference_data.read','description'=>'Returns approved reference values for districts, incidents, gender, national status and related lookups.'],
        ['method'=>'GET','url'=>$base.'/api/v2/incidents/statistics','scope'=>'incident_statistics.read','description'=>'Returns corrected aggregate statistics with metadata and consistent disaggregation.'],
        ['method'=>'POST','url'=>$base.'/api/v2/incidents/push/ubos','scope'=>'ubos.push','description'=>'Pushes an approved case payload to the UBOS GBV Portal.'],
        ['method'=>'POST','url'=>$base.'/api/v2/cases/push/nsr','scope'=>'nsr.push','description'=>'Pushes a granular NGBVD case payload to the National Single Registry.'],
    ];
@endphp
<div class="ni-shell">
    <div class="ni-hero">
        <div>
            <span class="ni-kicker">API Reference</span>
            <h2 class="ni-title">API URLs</h2>
            <p class="ni-subtitle">Use these endpoints for approved integrations. Authenticated endpoints require <strong>X-Client-Key</strong> and <strong>X-Client-Secret</strong> headers.</p>
        </div>
        <div class="ni-actions">
            <a href="{{ url('/integrations') }}" class="btn ngbvd-btn-soft"><i class="ti-arrow-left"></i> Overview</a>
            <a href="{{ url('/integrations/api-clients') }}" class="btn ngbvd-btn-primary"><i class="ti-key"></i> API Clients</a>
        </div>
    </div>

    <div class="ni-layout-wide">
        <div class="ni-card">
            <div class="ni-card-body">
                <div class="ni-heading">
                    <div><h4>Available Endpoints</h4><p>Copy the endpoint URL and use the correct scope for the API client.</p></div>
                    <span class="ni-heading-icon"><i class="ti-link"></i></span>
                </div>
                <div class="row">
                    @foreach($endpoints as $endpoint)
                        <div class="col-md-6 mb-3">
                            <div class="ni-nav-card" style="height:100%;">
                                <span class="ni-nav-icon"><i class="{{ ($endpoint['method'] ?? 'GET') === 'POST' ? 'ti-upload' : 'ti-download' }}"></i></span>
                                <div style="min-width:0;width:100%;">
                                    <div class="d-flex justify-content-between align-items-start mb-2">
                                        <h5>{{ $endpoint['method'] ?? 'GET' }} Endpoint</h5>
                                        <span class="ni-badge {{ ($endpoint['method'] ?? 'GET') === 'POST' ? 'ni-warning' : 'ni-blue' }}">{{ $endpoint['method'] ?? 'GET' }}</span>
                                    </div>
                                    <code class="ni-code d-block mb-2">{{ $endpoint['url'] ?? '' }}</code>
                                    <p>{{ $endpoint['description'] ?? '' }}</p>
                                    <small class="text-muted"><strong>Scope:</strong> {{ $endpoint['scope'] ?? 'N/A' }}</small><br>
                                    <button class="ni-copy-btn mt-2" data-ni-copy="{{ $endpoint['url'] ?? '' }}"><i class="ti-files"></i> Copy</button>
                                </div>
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
        </div>

        <div class="ni-card ni-panel">
            <div class="ni-card-body">
                <div class="ni-heading">
                    <div><h4>Testing Headers</h4><p>Use these headers in Postman or PowerShell.</p></div>
                    <span class="ni-heading-icon"><i class="ti-terminal"></i></span>
                </div>
                <div class="ni-code-panel mb-3"><div class="ni-code-title">Required Headers</div><pre>Accept: application/json
X-Client-Key: YOUR_CLIENT_KEY
X-Client-Secret: YOUR_CLIENT_SECRET</pre></div>
                <div class="ni-info mb-3"><i class="ti-lock"></i><span>Never share client secrets over email or screenshots. If exposed, disable the client and create a new one.</span></div>
                <a href="{{ url('/integrations/logs') }}" class="btn ngbvd-btn-soft btn-block"><i class="ti-list"></i> View Sharing Logs</a>
            </div>
        </div>
    </div>
</div>
@endsection
