@extends('layouts.default')
@section('title', $page_title)
@section('content')
<div class="container-fluid">
    @include('admin.partials.page-header', ['actions' => new \Illuminate\Support\HtmlString('<a href="'.route('admin.accounts.'.str_replace("_", "-", $platform).'.create').'" class="btn btn-primary">Bağlantı Ekle</a>')])
    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-responsive-md align-middle">
                    <thead><tr><th>Müşteri</th><th>Bağlantı</th><th>Hesap ID</th><th>Token</th><th>Durum</th><th>Son Test/Senkron</th><th class="text-end">İşlem</th></tr></thead>
                    <tbody>
                    @forelse($connections as $connection)
                        <tr>
                            <td>{{ $connection->client?->company_name }}</td>
                            <td><a href="{{ route('admin.accounts.'.str_replace('_', '-', $platform).'.show', $connection) }}" class="text-black font-w600">{{ $connection->connection_name }}</a></td>
                            <td>{{ $connection->account_id ?: '-' }}</td>
                            <td>
                                @if($connection->secureCredential)
                                    @include('admin.partials.status-badge', ['status' => $connection->secureCredential->is_active ? 'active' : 'error'])
                                @else
                                    <span class="badge light badge-warning">Yok</span>
                                @endif
                            </td>
                            <td>@include('admin.partials.status-badge', ['status' => $connection->status])</td>
                            <td>{{ $connection->last_sync_at?->format('d.m.Y H:i') ?? '-' }}</td>
                            <td class="text-end">
                                <form action="{{ route('admin.accounts.connections.test', $connection) }}" method="POST" class="d-inline">@csrf<button class="btn btn-xs btn-outline-success">Test</button></form>
                                <a href="{{ route('admin.integrations.discovery.index', ['platform' => $platform, 'client_id' => $connection->client_id, 'connection_id' => $connection->id]) }}" class="btn btn-xs btn-outline-info">Keşif</a>
                                <a href="{{ route('admin.accounts.'.str_replace('_', '-', $platform).'.edit', $connection) }}" class="btn btn-xs btn-outline-primary">Düzenle</a>
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="7" class="text-center text-muted py-5">Henüz bağlantı yok.</td></tr>
                    @endforelse
                    </tbody>
                </table>
            </div>
            {{ $connections->links() }}
        </div>
    </div>
</div>
@endsection
