@extends('layouts.user')

@section('title')
My Account
@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">My Active AI Bots</h5>
                        </div>
                    </div>
                    @forelse($investments->where('status', 2) as $investment)
                    <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($investment->balance, 2) }} <span class="text-base font-medium uppercase text-bgray-500">USDT</span></h5>

                            @if ($investment->f_pfit > 0)
                            <h4 style="font-size: 0.75rem; font-weight: bold; color: #0e9f6e; font-family: monospace; letter-spacing: -0.04em;">&uarr; AI ATP: +${{ number_format($investment->f_pfit, 2) }}</h4>
                            @else
                            @if(\Carbon\Carbon::parse($investment->buy_date)->gt(\Carbon\Carbon::parse('2025-03-23 00:00:00')))
                            <h4 style="font-size: 0.75rem; font-weight: bold; color: #0e9f6e; font-family: monospace; letter-spacing: -0.04em;">&uarr; AI ATP: +${{ number_format($investment->pfit, 2) }}</h4>
                            @endif
                            @endif

                            <div class="flex items-center justify-start">
                                <img style="height: 25px;" src="{{ asset('images/bot.png') }}" />
                                <p class="mt-2 text-slate-400">&nbsp;{{ $investment->plan?->name }} - <a href="{{ route('ai-activity', [$investment->id, $investment->plan?->name]) }}" class="text-orange-500">View Bot Activity &rarr;</a></p>
                            </div>

                            <p class="mt-2 text-slate-400">&nbsp;Initial Deposit - <b>${{ number_format($investment->amount, 2) }}</b></p>
                        </div>
                        @if(($investment->funded == 1 && $investment->f_pfit == 0) || $investment->status == 3)
                            <a href="{{ route('withdraw-ai', $investment->id) }}" class="inline-block px-5 py-2 text-base font-semibold tracking-wide text-center text-orange-400 align-middle duration-500 rounded-md"
                                style="background-color: #660066;">
                                Withdraw To Wallet
                            </a>
                        @elseif($investment->funded == 0)  <!-- Show fund button if not funded -->
                            <a href="{{ route('fund-ai', $investment->id) }}" class="inline-block px-5 py-2 text-base font-semibold tracking-wide text-center text-white align-middle duration-500 bg-orange-500 rounded-md">
                                Fund AI Capital
                            </a>
                        @elseif($investment->f_pfit > 0 && $investment->status != 3)
                            <!-- Optionally add some other content here for funded investments with f_pfit > 0 -->
                        @else
                            <a href="{{ route('fund-ai', $investment->id) }}" class="inline-block px-5 py-2 text-base font-semibold tracking-wide text-center text-white align-middle duration-500 bg-orange-500 rounded-md">
                                Fund AI Capital
                            </a>
                        @endif
                    </div>
                    @empty
                    @endforelse
                </div>

                <div class="bg-white rounded-md shadow dark:shadow-gray-800 dark:bg-slate-900 mt-12">
                    <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">Completed AI Bots</h5>
                        </div>
                    </div>
                    @forelse($investments->where('status', 3) as $investment)
                    <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($investment->balance, 2) }} <span class="text-base font-medium uppercase text-bgray-500">USDT</span></h5>

                            @if ($investment->f_pfit > 0)
                            <h4 style="font-size: 0.75rem; font-weight: bold; color: #0e9f6e; font-family: monospace; letter-spacing: -0.04em;">&uarr; AI ATP: +${{ number_format($investment->f_pfit, 2) }}</h4>
                            @else
                            @if(\Carbon\Carbon::parse($investment->buy_date)->gt(\Carbon\Carbon::parse('2025-03-23 00:00:00')))
                            <h4 style="font-size: 0.75rem; font-weight: bold; color: #0e9f6e; font-family: monospace; letter-spacing: -0.04em;">&uarr; AI ATP: +${{ number_format($investment->pfit, 2) }}</h4>
                            @endif
                            @endif

                            <div class="flex items-center justify-start">
                                <img style="height: 25px;" src="{{ asset('images/bot.png') }}" />
                                <p class="mt-2 text-slate-400">&nbsp;{{ $investment->plan?->name }} - <a href="{{ route('ai-activity', [$investment->id, $investment->plan?->name]) }}" class="text-orange-500">View Bot Activity &rarr;</a></p>
                            </div>
                            <p class="mt-2 text-slate-400">&nbsp;Initial Deposit - <b>${{ number_format($investment->amount, 2) }}</b></p>
                        </div>
                        @if(($investment->funded == 1 && $investment->f_pfit == 0) || $investment->status == 3)
                        <a href="{{ route('withdraw-ai', $investment->id) }}" class="inline-block px-5 py-2 text-base font-semibold tracking-wide text-center text-orange-400 align-middle duration-500 rounded-md"
                            style="background-color: #660066;">
                            Withdraw To Wallet
                        </a>
                        @elseif($investment->funded == 0)  <!-- Show fund button if not funded -->
                            <a href="{{ route('fund-ai', $investment->id) }}" class="inline-block px-5 py-2 text-base font-semibold tracking-wide text-center text-white align-middle duration-500 bg-orange-500 rounded-md">
                                Fund AI Capital
                            </a>
                        @elseif($investment->f_pfit > 0 && $investment->status != 3)
                            <!-- Optionally add some other content here for funded investments with f_pfit > 0 -->
                        @else
                        <a href="{{ route('fund-ai', $investment->id) }}" class="inline-block px-5 py-2 text-base font-semibold tracking-wide text-center text-white align-middle duration-500 bg-orange-500 rounded-md">Fund AI Capital</a>
                        @endif
                    </div>
                    @empty
                    @endforelse
                </div>
            </div><!--end grid-->

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

@endsection