@extends('layouts.user')
@section('content')

<div class="main-content">
        <div class="page-content dark:bg-zinc-700" style="padding-bottom: 500px;">
            <div class="container-fluid px-[0.625rem]">

                <div class="grid grid-cols-1 mb-5">
                    <div class="flex items-center justify-between">
                        <h4 class="mb-sm-0 text-lg font-semibold grow text-gray-800 dark:text-gray-100">Marketers Dashboard</h4>
                        <nav class="flex" aria-label="Breadcrumb">
                        </nav>
                    </div>
                </div>

                <div class="grid grid-cols-1 gap-5 px-0">
                    <div class="grid items-stretch grid-cols-12">
                        <div class="self-center col-span-12 lg:col-span-6">
                            <h5 class="text-gray-600 text-15 dark:text-gray-100">Team Total: {{ count($team) }}</h5>
                        </div>
                    </div>

                    <form method="get" action="{{ route('marketer') }}">
                        @csrf
                        <div class="w-full md:w-[80%] lg:w-[50%] mt-4 mx-auto">
                            <label class="block mb-2 font-medium dark:text-gray-100 ">Filter By Email Or Username :</label>
                            <div class="flex mb-3 border border-gray-100 rounded dark:border-zinc-600 dark:text-zinc-100">
                                <select name="filter" class="border-0 ltr:pl-1.5 rtl:pr-1.5 focus:border-violet-100 focus:ring focus:ring-violet-50/60 focus:z-40 dark:border-zinc-600 dark:bg-zinc-700 dark:text-zinc-100 dark:focus:ring-gray-500/10" style="max-width: 130px;">
                                    <option value="email" selected="">Email</option>
                                    <option value="username" selected="">Username</option>
                                </select>
                                <input type="text" id="value" required name="value" class=" border-0 w-full py-1.5 focus:border-violet-100 focus:ring focus:ring-violet-50/60 dark:bg-zinc-700 dark:placeholder:text-gray-200 dark:focus:ring-gray-500/10" placeholder="Enter Search">
                            </div>
                        </div> 
                        <div class="w-full md:w-[80%] lg:w-[50%] mx-auto">
                            <button type="submit" class="btn w-fit order-2 border-transparent text-white" style="background-color: #ec595a">Filter Search</button>
                        </div> 
                    </form>

                    <div class="mt-4">
                        <a href="{{ route('marketer') }}" class="text-green-500">&larr; Back To All</a>
                    </div>

                    <div class="card dark:bg-zinc-800 dark:border-zinc-600">
                        <div class="nav-tabs border-b-tabs">
                            <div class="card-body pb-0 flex border-b border-gray-50 dark:border-zinc-700">
                                <div class="flex-shrink-0 text-violet-500">
                                    <ul class="nav flex" role="tablist">
                                        <li class="nav-item">
                                            <a class="inline-block px-4 pb-3 font-medium active" href="javascript:void(0);" data-tw-toggle="tab" data-tw-target="buy-tab1" role="tab">Team Performance</a>
                                        </li>
                                        <li class="nav-item">
                                            <a class="inline-block px-4 pb-3 font-medium" href="javascript:void(0);" data-tw-toggle="tab" data-tw-target="sell-tab1" role="tab">Rebate Record</a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                            <div class="card-body px-0">
                                <div class="tab-content">
                                    <div class="tab-pane active" id="buy-tab1" role="tabpanel">
                                        <div class="px-1" data-simplebar style="max-height: 352px;">
                                            <table class="table w-full">
                                                <tbody>
                                                    @forelse($members as $member)
                                                        @if(in_array($member->id, $team))
                                                            <tr>
                                                                <td class="p-3">
                                                                    <a href="{{ route('member', $member->username) }}">
                                                                        <div>
                                                                            <h5 class="text-sm mb-1 text-gray-600 dark:text-zinc-100">{{ $member->first_name }} {{ $member->last_name }} [{{ $member->username }}]</h5>
                                                                            <p class="text-gray-500 dark:text-zinc-200 mb-0 text-xs">{{ $member->email }}</p>
                                                                        </div>
                                                                    </a>
                                                                </td>
            
                                                                <td class="p-3">
                                                                    <div class="text-end">
                                                                        <a href="{{ route('member', $member->username) }}"><small class="mb-0 text-sm text-gray-600 dark:text-zinc-100 flex justify-end items-end">More ></small></a>
                                                                        @if(count($member->investment) > 0 && count($member->referrals) > 0)
                                                                        <p class="text-green-500 mb-0 text-xs">
                                                                            Active
                                                                        </p>
                                                                        @else
                                                                        <p class="text-red-500 mb-0 text-xs">
                                                                            In-active
                                                                        </p>
                                                                        @endif
                                                                    </div>
                                                                </td>
                                                            </tr>
                                                        @else
                                                        @endif
                                                    @empty
                                                    @endforelse
                                                    @php
                                                        $memberIds = $members->pluck('id')->toArray();
                                                        if(!collect($memberIds)->intersect($team)->count()){
                                                            $notFound = true;
                                                        }else{
                                                            $notFound = false;
                                                        }
                                                    @endphp
                                                    @if($notFound)
                                                        <p class="text-gray-400 dark:text-zinc-400 my-12 text-center">No Records Found!</p>
                                                    @endif
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
    
                                    <div class="tab-pane hidden" id="sell-tab1" role="tabpanel">
                                        <div class="px-3" data-simplebar style="max-height: 352px;">
                                            <table class="table w-full">
                                                <tbody>
                                                @forelse($rebates as $rebate)
                                                        @if(in_array($rebate->user_id, $team))
                                                            <tr>
                                                                <td class="p-3"  style="width: 50px;">
                                                                    <div class="text-22 text-green-500">
                                                                        <i class="bx bx-down-arrow-circle d-block"></i>
                                                                    </div>
                                                                </td>
            
                                                                <td class="p-3">
                                                                    <div>
                                                                        <h5 class="text-sm mb-1 text-gray-700 dark:text-gray-100">Rebate Bonus Received</h5>
                                                                        <p class="text-gray-600 dark:text-zinc-100 mb-0 text-xs">From: {{ $rebate->user->username }}</p>
                                                                    </div>
                                                                </td>
            
                                                                <td class="p-3">
                                                                    <div class="text-end">
                                                                        <h5 class="text-sm mb-0 text-green-500">USDT 
                                                                            @if(in_array($rebate->user_id, $first))
                                                                                {{ auth()->user()->first_rebate/100 * $rebate->amount }}
                                                                            @elseif(in_array($rebate->user_id, $second))
                                                                                {{ auth()->user()->second_rebate/100 * $rebate->amount }}
                                                                            @elseif(in_array($rebate->user_id, $third))
                                                                                {{ auth()->user()->third_rebate/100 * $rebate->amount }}
                                                                            @endif
                                                                        </h5>
                                                                        <p class="text-gray-600 dark:text-zinc-100 mb-0 text-xs">{{ date('M j Y', strtotime($rebate->created_at)) }}</p>
                                                                    </div>
                                                                </td>
                                                            </tr>
                                                        @else
                                                        @endif
                                                    @empty
                                                    @endforelse
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
    
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

        </div>

@endsection