@extends('layouts.marketer')

@section('title')
{{ $title }}
@endsection

@section('content')

<div class="dashboard-container">
    <!-- Breadcrumb -->
    <div class="breadcrumb-container">
        <a href="{{ route('marketer') }}" class="breadcrumb-link">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M19 12H5M12 19l-7-7 7-7"/>
            </svg>
            Back to Dashboard
        </a>
    </div>

    <!-- Header Section -->
    <div class="members-list-header">
        <div class="members-list-header-content">
            <div class="members-list-icon">
                <svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                    <path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
                    <circle cx="9" cy="7" r="4"></circle>
                    <path d="M23 21v-2a4 4 0 0 0-3-3.87"></path>
                    <path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
                </svg>
            </div>
            <div class="members-list-info">
                <h1 class="members-list-title">{{ $title }}</h1>
                <p class="members-list-subtitle">{{ $subtitle }}</p>
                <span class="members-list-count">{{ number_format($members->total()) }} members found</span>
            </div>
        </div>
    </div>

    <x-alert/>

    <!-- Members Table/Cards -->
    <div class="members-list-content">
        <!-- Mobile Cards View -->
        <div class="mobile-cards mobile-only">
            @forelse($members as $member)
            <div class="member-mobile-card">
                <div class="member-mobile-header">
                    <div class="member-avatar">
                        {{ strtoupper(substr($member->username ?? $member->first_name, 0, 2)) }}
                    </div>
                    <div class="member-mobile-info">
                        <h4>{{ ucfirst($member->username ?? $member->first_name . ' ' . $member->last_name) }}</h4>
                        <p>{{ $member->email }}</p>
                        
                        <!-- Email Verification Badge -->
                        @if(isset($member->email_verified_at))
                            @if($member->email_verified_at)
                                <span class="verification-badge badge-verified">
                                    <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                        <polyline points="20 6 9 17 4 12"></polyline>
                                    </svg>
                                    Email Verified
                                </span>
                            @else
                                <span class="verification-badge badge-unverified">
                                    <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                        <line x1="18" y1="6" x2="6" y2="18"></line>
                                        <line x1="6" y1="6" x2="18" y2="18"></line>
                                    </svg>
                                    Email Unverified
                                </span>
                            @endif
                        @endif

                        <!-- KYC Verification Badge -->
                        @if($member->kyc_status === 1)
                            <span class="verification-badge badge-verified">
                                <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                    <polyline points="20 6 9 17 4 12"></polyline>
                                </svg>
                                KYC Verified
                            </span>
                        @elseif($member->kyc_status === null)
                            <span class="verification-badge badge-unverified">
                                <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                    <line x1="18" y1="6" x2="6" y2="18"></line>
                                    <line x1="6" y1="6" x2="18" y2="18"></line>
                                </svg>
                                KYC Unverified
                            </span>
                        @endif
                    </div>
                </div>
                <div class="member-mobile-stats">
                    <div class="mobile-stat">
                        <span class="mobile-stat-label">Balance</span>
                        <span class="mobile-stat-value">${{ number_format($member->balance, 2) }}</span>
                    </div>
                    <div class="mobile-stat">
                        <span class="mobile-stat-label">Referrals</span>
                        <span class="team-size-badge">{{ number_format($member->referrals_count) }}</span>
                    </div>
                    <div class="mobile-stat">
                        <span class="mobile-stat-label">Joined</span>
                        <span class="mobile-stat-value text-muted">{{ date('M j, Y', strtotime($member->created_at)) }}</span>
                    </div>
                </div>
                @if($member->username)
                <div class="member-mobile-footer">
                    <a href="{{ route('member', $member->username) }}" class="action-btn action-btn-primary" target="_blank">
                        View Details
                    </a>
                </div>
                @endif
            </div>
            @empty
            <div class="empty-state">
                <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1">
                    <circle cx="12" cy="12" r="10"></circle>
                    <line x1="12" y1="8" x2="12" y2="12"></line>
                    <line x1="12" y1="16" x2="12.01" y2="16"></line>
                </svg>
                <h3>No Members Found</h3>
                <p>No members in this category</p>
            </div>
            @endforelse
        </div>

        <!-- Desktop Table View -->
        <div class="table-container desktop-only">
            <table class="data-table">
                <thead>
                    <tr>
                        <th>Member</th>
                        <th>Email</th>
                        <th>Balance</th>
                        <th>Referrals</th>
                        <th>Verification Status</th>
                        <th>Joined</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($members as $member)
                    <tr>
                        <td>
                            <div class="member-cell">
                                <div class="member-avatar">
                                    {{ strtoupper(substr($member->username ?? $member->first_name, 0, 2)) }}
                                </div>
                                <div class="member-info">
                                    <span class="member-name">
                                        {{ ucfirst($member->username ?? $member->first_name . ' ' . $member->last_name) }}
                                    </span>
                                    @if(!$member->username)
                                        <span class="member-badge">No Store</span>
                                    @endif
                                </div>
                            </div>
                        </td>
                        <td class="text-muted">{{ $member->email }}</td>
                        <td class="text-bold">${{ number_format($member->balance, 2) }}</td>
                        <td>
                            <span class="team-size-badge">{{ number_format($member->referrals_count) }}</span>
                        </td>
                        <td>
                            <div class="verification-badges">
                                <!-- Email Verification Badge -->
                                @if(isset($member->email_verified_at))
                                    @if($member->email_verified_at)
                                        <span class="verification-badge badge-verified">
                                            <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                                <polyline points="20 6 9 17 4 12"></polyline>
                                            </svg>
                                            Email
                                        </span>
                                    @else
                                        <span class="verification-badge badge-unverified">
                                            <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                                <line x1="18" y1="6" x2="6" y2="18"></line>
                                                <line x1="6" y1="6" x2="18" y2="18"></line>
                                            </svg>
                                            Email
                                        </span>
                                    @endif
                                @endif

                                <!-- KYC Verification Badge -->
                                @if($member->kyc_status === 1)
                                    <span class="verification-badge badge-verified">
                                        <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                            <polyline points="20 6 9 17 4 12"></polyline>
                                        </svg>
                                        KYC
                                    </span>
                                @elseif($member->kyc_status === null)
                                    <span class="verification-badge badge-unverified">
                                        <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                            <line x1="18" y1="6" x2="6" y2="18"></line>
                                            <line x1="6" y1="6" x2="18" y2="18"></line>
                                        </svg>
                                        KYC
                                    </span>
                                @endif
                            </div>
                        </td>
                        <td class="text-muted">{{ date('M j, Y', strtotime($member->created_at)) }}</td>
                        <td>
                            @if($member->username)
                                <a href="{{ route('member', $member->username) }}" class="action-btn action-btn-primary" target="_blank">
                                    View
                                </a>
                            @else
                                <span class="text-muted">N/A</span>
                            @endif
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="7" class="text-center">
                            <div class="empty-state">
                                <p>No members found</p>
                            </div>
                        </td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        <!-- Pagination -->
        @if($members->hasPages())
        <div class="pagination-wrapper">
            {{ $members->links('pagination::bootstrap-4') }}
        </div>
        @endif
    </div>
</div>

@include('marketer-styles')

@endsection