@extends('layouts.master')

@section('title', 'My Transactions')

@section('content')
<div class="tw-bg-gray-50 tw-min-h-screen tw-py-8">
    <div class="container">
        <div class="row g-4">
            <!-- Sidebar -->
            <div class="col-lg-3">
                @include('seller.partials.sidebar')
            </div>

            <!-- Main Content -->
            <div class="col-lg-9">
                <div class="d-flex justify-content-between align-items-center mb-4">
                    <h4 class="fw-bold mb-0">My Transactions</h4>
                </div>

                <div class="card shadow-sm border-0">
                    <div class="card-body p-0">
                        <div class="table-responsive">
                            <table class="table table-hover align-middle mb-0">
                                <thead class="bg-light">
                                    <tr>
                                        <th class="ps-4 py-3">Date</th>
                                        <th class="py-3">Transaction ID</th>
                                        <th class="py-3">Type</th>
                                        <th class="py-3">Amount</th>
                                        <th class="py-3">Payment Method</th>
                                        <th class="py-3">Status</th>
                                        <th class="text-end pe-4 py-3">Details</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @forelse($transactions as $transaction)
                                    <tr>
                                        <td class="ps-4">
                                            <div class="fw-bold">{{ $transaction->created_at->format('M d, Y') }}</div>
                                            <small class="text-muted">{{ $transaction->created_at->format('h:i A') }}</small>
                                        </td>
                                        <td class="font-monospace small">
                                            @if($transaction->payment_gateway === 'manual')
                                                {{ $transaction->payment_id ?? 'N/A' }} <span class="badge bg-light text-dark border">Ref</span>
                                            @else
                                                {{ $transaction->payment_id ?? 'N/A' }}
                                            @endif
                                        </td>
                                        <td>
                                            @if($transaction->transaction_type === 'subscription')
                                                <span class="badge bg-info bg-opacity-10 text-info">Subscription</span>
                                                <div class="small text-muted mt-1">{{ $transaction->metadata['plan_name'] ?? 'Plan' }}</div>
                                            @elseif($transaction->transaction_type === 'promotion')
                                                <span class="badge bg-primary bg-opacity-10 text-primary">Promotion</span>
                                                <div class="small text-muted mt-1">{{ $transaction->metadata['package_name'] ?? 'Package' }}</div>
                                            @else
                                                <span class="badge bg-secondary">{{ ucfirst($transaction->transaction_type) }}</span>
                                            @endif
                                        </td>
                                        <td class="fw-bold">₹{{ number_format($transaction->total_amount, 2) }}</td>
                                        <td>
                                            <div class="text-capitalize">
                                                {{ str_replace('_', ' ', $transaction->payment_method ?? 'N/A') }}
                                            </div>
                                            <small class="text-muted">{{ ucfirst($transaction->payment_gateway) }}</small>
                                        </td>
                                        <td>
                                            <span class="badge {{ $transaction->getStatusBadgeClass() }}">
                                                {{ ucfirst(str_replace('_', ' ', $transaction->status)) }}
                                            </span>
                                            @if($transaction->status === 'failed' && $transaction->failure_reason)
                                                <i class="bi bi-info-circle text-danger ms-1" data-bs-toggle="tooltip" title="{{ $transaction->failure_reason }}"></i>
                                            @endif
                                        </td>
                                        <td class="text-end pe-4">
                                            @if($transaction->status === 'pending_approval')
                                                <span class="text-muted small fst-italic">Waiting Approval</span>
                                            @elseif($transaction->status === 'success')
                                                <span class="text-success small"><i class="bi bi-check-circle-fill"></i> Completed</span>
                                            @endif
                                        </td>
                                    </tr>
                                    @empty
                                    <tr>
                                        <td colspan="7" class="text-center py-5">
                                            <div class="text-muted">
                                                <i class="bi bi-receipt fs-1 d-block mb-3"></i>
                                                No transactions found.
                                            </div>
                                        </td>
                                    </tr>
                                    @endforelse
                                </tbody>
                            </table>
                        </div>
                    </div>
                    @if($transactions->hasPages())
                    <div class="card-footer bg-white">
                        {{ $transactions->links() }}
                    </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
