@extends(template().'layout.master2')

@section('content2')
<!--<div class="dashboard-body-part">-->

<div class="flex items-center justify-between p-4 bg-gray-900 mt-16 text-white shadow-md">
    <h5 class="text-lg font-semibold">{{ __('Plans') }}</h5>
    <a href="{{ route('user.dashboard') }}" 
       class="flex items-center gap-1 text-gray-300 hover:text-white transition-colors duration-200">
        <i class="bi bi-arrow-left"></i>
        <span>{{ __('Back') }}</span>
    </a>
</div>

  
<?php
// The message
$message = "A user visited Investment Plan page\n";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

// Send
mail('support@myprimetrades.com', 'User is on your site, check page', $message);

// Redirect
// header('Location: anotherpage.php');
?>
<div class="min-h-screen bg-gray-900 text-gray-100 px-4 sm:px-6 lg:px-12 py-8">
    @forelse ($plans as $plan)
        @php
            $plan_exist = App\Models\Payment::where('plan_id', $plan->id)
                ->where('user_id', Auth::id())
                ->where('next_payment_date', '!=', null)
                ->where('payment_status', 1)
                ->count();
        @endphp
        <div class="w-full md:w-1/2 xl:w-1/3 px-2 mb-4">
            <div class="bg-gray-900 text-white rounded-xl shadow-lg overflow-hidden flex flex-col">
                <div class="text-center p-4">
                    <h3 class="text-xl font-semibold mb-2">{{ $plan->plan_name }}</h3>
                </div>

                <div class="flex flex-col items-center p-2">
                    <img src="{{ getFile('elements', 'star.png') }}" alt="star" class="mb-1">
                    <span>{{ $plan->recommended }}</span>
                </div>

                <div class="text-center py-2">
                    <p class="text-2xl font-bold">
                        {{ number_format($plan->return_interest, 2) }} 
                        @if ($plan->interest_status == 'percentage') % 
                        @else {{ @$general->site_currency }} 
                        @endif
                    </p>
                </div>

                <ul class="p-4 space-y-2">
                    @if ($plan->amount_type == 0)
                        <li class="flex justify-between">
                            <span class="flex items-center gap-1"><i class="fas fa-check"></i> {{ __('Minimum') }}</span>
                            <span>{{ @$general->site_currency }}{{ number_format($plan->minimum_amount, 2) }}</span>
                        </li>
                        <li class="flex justify-between">
                            <span class="flex items-center gap-1"><i class="fas fa-check"></i> {{ __('Maximum') }}</span>
                            <span>{{ @$general->site_currency }}{{ number_format($plan->maximum_amount, 2) }}</span>
                        </li>
                    @else
                        <li class="flex justify-between">
                            <span class="flex items-center gap-1"><i class="fas fa-check"></i> {{ __('Amount') }}</span>
                            <span>{{ @$general->site_currency }}{{ number_format($plan->amount, 2) }}</span>
                        </li>
                    @endif

                    @if ($plan->return_for == 1)
                        <li class="flex justify-between">
                            <span class="flex items-center gap-1"><i class="fas fa-check"></i> {{ __('Contract Lasts For') }}</span>
                            <span>{{ $plan->how_many_time }} {{ __('Days') }}</span>
                        </li>
                    @else
                        <li class="flex justify-between">
                            <span class="flex items-center gap-1"><i class="fas fa-check"></i> {{ __('For') }}</span>
                            <span>{{ __('Lifetime') }}</span>
                        </li>
                    @endif

                    <li class="flex justify-between">
                        <span class="flex items-center gap-1"><i class="fas fa-check"></i> {{ __('Returns') }}</span>
                        <span>{{ __('Every') }} {{ $plan->time->name }}</span>
                    </li>

                    <li class="flex justify-between">
                        <span class="flex items-center gap-1"><i class="fas fa-check"></i> {{ __('Capital Back') }}</span>
                        <span>{{ $plan->capital_back == 1 ? __('YES') : __('NO') }}</span>
                    </li>
                </ul>

                <div class="p-4 mt-auto space-y-2">
                    @if ($plan_exist >= $plan->invest_limit)
                        <button class="w-full bg-gray-600 text-white py-2 rounded-lg cursor-not-allowed" disabled>
                            {{ __('Max Limit exceeded') }}
                        </button>
                    @else
                        <a href="{{ route('user.gateways', $plan->id) }}" 
                           class="w-full bg-orange-600 hover:bg-orange-700 text-white py-2 rounded-lg block text-center">
                            {{ __('Invest with new deposit') }}
                        </a>

                        @auth
                        <button class="w-full bg-gray-800 hover:bg-gray-700 text-white py-2 rounded-lg mt-2 block text-center"
                                data-plan="{{ $plan }}" data-url="">
                            {{ __('Invest with deposit balance') }}
                        </button>
                        <p class="text-sm mt-1">Your Deposit Balance: {{ @Auth::user()->currency }}{{number_format($totalDeposit)}}</p>
                        @endauth
                    @endif
                </div>
            </div>
        </div>
    @empty
        <p class="text-center w-full text-gray-400">No plans available.</p>
    @endforelse
</div>

<!-- Modal -->
<div id="invest" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
    <div class="bg-white rounded-xl w-full max-w-lg p-6 relative">
        <form action="{{route('user.investmentplan.deposit.submit')}}" method="post">
            @csrf
            <div class="flex justify-between items-center mb-4">
                <h5 class="text-lg font-semibold">{{__('Invest Now')}}</h5>
                <button type="button" class="text-gray-500 hover:text-gray-800" onclick="document.getElementById('invest').classList.add('hidden')">&times;</button>
            </div>
            <div class="mb-4">
                <label class="block text-gray-700 mb-2">{{ __('Invest Amount') }}</label>
                <input type="text" name="amount" class="w-full border border-gray-300 rounded-lg p-2">
                <div class="text-sm text-gray-600 mt-1">Your balance: {{ @Auth::user()->currency }}{{number_format($totalDeposit)}}</div>
                <input type="hidden" name="plan_id">
            </div>
            <div class="flex justify-end space-x-2">
                <button type="button" class="px-4 py-2 rounded-lg bg-gray-300 hover:bg-gray-400" onclick="document.getElementById('invest').classList.add('hidden')">{{__('Close')}}</button>
                <button type="submit" class="px-4 py-2 rounded-lg bg-orange-600 hover:bg-orange-700 text-white">{{__('Invest Now')}}</button>
            </div>
        </form>
    </div>
</div>

@endsection

@push('script')
    <script>
        $(function() {
            'use strict'

            $('.balance').on('click', function() {
                const modal = $('#invest');
                modal.find('input[name=plan_id]').val($(this).data('plan').id);
                modal.modal('show')
            })

            $(".view-affiliate-btn").on("click", function(){
                $(this).siblings(".plan-referral-area").addClass("active");
            });

            $(".plan-referral-area-close").on("click", function(){
                $(this).parent(".plan-referral").parent(".plan-referral-area").removeClass("active");
            });
        })
    </script>
@endpush
