@extends('layouts.user')

@section('title')
    Member Info
@endsection

@section('content')

<!-- Start Hero -->
<section class="relative lg:pb-24 pb-16 md:mt-[84px] mt-[70px]">
            <div class="relative md:container container-fluid">
                <div class="relative overflow-hidden md:rounded-md shadow dark:shadow-gray-700 h-52 bg-[url('../../assets/images/hero/pages.html')] bg-center bg-no-repeat bg-cover" 
                style="background-image: url('{{ asset('images/profile-1.jpg') }}');"></div>
            </div><!--end container-->

            <div class="container relative mt-16 md:mt-24">
                <div class="md:flex">
                    <div class="lg:w-1/4 md:w-1/3 md:px-3">
                        <div class="relative -mt-32 md:-mt-48">
                            <div class="p-6 bg-white rounded-md shadow dark:shadow-gray-800 dark:bg-slate-900">
                                <div class="mb-5 text-center profile-pic">
                                    <!-- <input id="pro-img" name="profile-image" type="file" class="hidden" onchange="loadFile(event)" /> -->
                                    <div>
                                        <div class="relative mx-auto h-28 w-28">
                                            <img src="{{ asset('images/avatar-1.png') }}" class="rounded-full shadow dark:shadow-gray-800 ring-4 ring-slate-50 dark:ring-slate-800" id="profile-image" alt="">
                                            <label class="absolute inset-0 cursor-pointer" for="pro-img"></label>
                                        </div>

                                        <div class="mt-4">
                                            <h5 class="text-lg font-semibold">{{ auth()->user()->username }}</h5>
                                            <p class="text-slate-400">{{ auth()->user()->email }}</p>
                                        </div>
                                    </div>
                                </div>

                                <!-- Side Nav -->
                                <x-side-nav/>
                                
                            </div>
                        </div>
                    </div>

                    
                    <div class="mt-6 lg:w-3/4 md:w-2/3 md:px-3 md:mt-0">

                    <x-alert/>
                    
                    <div class="bg-white rounded-md shadow dark:shadow-gray-800 dark:bg-slate-900">
                            <div class="items-center justify-between p-6 border-b border-gray-100 md:flex dark:border-gray-700">
                                <div class="mb-4 md:mb-0">
                                    <h5 class="text-xl font-semibold">Member Info</h5>
                                </div>
                            </div>

                            <div class="p-6">
                                <h5 class="text-2xl font-semibold">${{ number_format(auth()->user()->rebates, 2) }} <span class="text-base font-medium uppercase text-bgray-500">USDT</span></h5>
                                <p class="mt-2 text-slate-400">Rebate Bonus</p>
                            </div>
                            <div class="items-center justify-between p-6 border-t border-b border-gray-100 md:flex dark:border-gray-700">
                                <div class="mb-4 md:mb-0">
                                    <h5 class="text-2xl font-semibold">${{ number_format(auth()->user()->balance, 2) }} <span class="text-base font-medium uppercase text-bgray-500">USDT</span></h5>
                                    <p class="mt-2 text-slate-400">Main Wallet</p>
                                </div>
                            </div>
                            <div class="items-center justify-between p-6 border-t border-b border-gray-100 md:flex dark:border-gray-700">
                                <div class="mb-4 md:mb-0">
                                    <h5 class="text-2xl font-semibold">{{ count($first) }} Members</h5>
                                    <p class="mt-2 text-slate-400">First Generation Total</p>
                                </div>
                            </div>
                            <div class="items-center justify-between p-6 border-t border-b border-gray-100 md:flex dark:border-gray-700">
                                <div class="mb-4 md:mb-0">
                                    <h5 class="text-2xl font-semibold">{{ count($second) }} Members</h5>
                                    <p class="mt-2 text-slate-400">Second Generation Total</p>
                                </div>
                            </div>
                            <div class="items-center justify-between p-6 border-t border-b border-gray-100 md:flex dark:border-gray-700">
                                <div class="mb-4 md:mb-0">
                                    <h5 class="text-2xl font-semibold">{{ count($third) }} Members</h5>
                                    <p class="mt-2 text-slate-400">Third Generation Total</p>
                                </div>
                            </div>
                        </div>

                    <div class="grid items-stretch grid-cols-12 mb-4 mt-8 p-4 border rounded-lg  ">
                        <div class="self-center col-span-12 lg:col-span-6">
                            <p class="text-gray-600 dark:text-gray-100"><span class="font-semibold">Store Name</span> &rarr; {{ ucfirst($user->username) }}</p>
                            <p class="text-gray-600 dark:text-gray-100"><span class="font-semibold">Generation </span>&rarr; 
                                @if($user->referrer->id == auth()->user()->id)
                                    First Generation
                                @elseif($user->referrer->referrer->id == auth()->user()->id)
                                    Second Generation
                                @elseif($user->referrer->referrer->referrer->id == auth()->user()->id)
                                    Third Generation
                                @endif
                            </p>
                        </div>
                    </div>


                <div class="grid md:grid-cols-12 grid-cols-1 mt-6 gap-6">
                    <div class="lg:col-span-12 md:col-span-12">
                        <div class="sticky top-20">
                            <ul class="flex-column p-6 bg-white dark:bg-slate-900 shadow dark:shadow-gray-800 rounded-md" id="myTab" data-tabs-toggle="#myTabContent" role="tablist">
                                <li role="presentation">
                                    <button class="px-4 py-2 text-start text-base font-semibold rounded-md w-full hover:text-orange-500 duration-500" id="description-tab" data-tabs-target="#description" type="button" role="tab" aria-controls="description" aria-selected="true">Your Rebate Bonuses From {{ $user->first_name }}</button>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <div class="lg:col-span-12 md:col-span-12">
                        <div id="myTabContent" class="bg-white dark:bg-slate-900 shadow dark:shadow-gray-800 rounded-md">
                            <div class="" id="description" role="tabpanel" aria-labelledby="profile-tab">
                                <div class="relative overflow-x-auto rounded-md shadow dark:shadow-gray-800">
                                    <table class="text-start text-slate-500 dark:text-slate-400" style="width: 150%;">
                                        <thead class="text-sm uppercase bg-slate-50 dark:bg-slate-800">
                                            <tr class="text-start">
                                                <th scope="col" class="px-2 py-3 text-start">From</th>
                                                <th scope="col" class="px-2 py-3 text-start">Amount</th>
                                                <th scope="col" class="px-2 py-3 text-start">Date</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        @forelse($user->transactions as $rebate)
                                            <tr class="bg-white dark:bg-slate-900 text-start">
                                                <td class="px-2 py-3 text-start">
                                                    <a>
                                                        <span>Rebate Bonus</span> <br>
                                                        <span class="text-xs">From: {{ ucfirst($rebate->user->username) }}</span>
                                                    </a>
                                                </td>
                                                <td class="px-2 py-3 text-green-600">
                                                    + $ 
                                                    @if($user->referrer->id == auth()->user()->id)
                                                        {{ auth()->user()->first_rebate/100 * $rebate->amount }}
                                                    @elseif($user->referrer->referrer->id == auth()->user()->id)
                                                        {{ auth()->user()->second_rebate/100 * $rebate->amount }}
                                                    @elseif($user->referrer->referrer->referrer->id == auth()->user()->id)
                                                        {{ auth()->user()->third_rebate/100 * $rebate->amount }}
                                                    @endif
                                                </td>
                                                <td class="px-2 py-3 text-start text-xs">
                                                    {{ date('M j Y', strtotime($rebate->created_at)) }}
                                                </td>
                                            </tr>
                                        @empty
                                        @endforelse
                                        
                                        @if(!count($user->transactions) > 0)
                                        <span class="text-slate-400 m-6 text-center">No Records Found!</span>
                                        @endif
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                        </div>
                    </div>
                </div><!--end grid-->
            </div><!--end container-->
        </section><!--end section-->
        <!-- End Hero -->

@endsection