@extends('layouts.dashboard')

@section('content')

<!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
      <div class="container-full">
        <!-- Content Header (Page header) -->
        <div class="content-header">
            <div class="d-flex align-items-center">
                <div class="me-auto">
                    <h3 class="page-title">User Details</h3>
                    <div class="d-inline-block align-items-center">
                        <nav>
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="#"><i class="mdi mdi-home-outline"></i></a></li>
                                <li class="breadcrumb-item" aria-current="page">User</li>
                                <li class="breadcrumb-item active" aria-current="page">Details</li>
                            </ol>
                        </nav>
                    </div>
                </div>
                
            </div>
        </div>
        <style type="text/css">
            .col_padding
            {
                padding: 10px;
            }
            .delete
            {
                width: 200px;
            }
            .delete1
            {
                width: 150px;
            }
        </style>
        <!-- Main content -->
        <section class="content">

          <div class="row">
            <div class="col-lg-12">
                <div class="box" style="background: none;box-shadow: none">
                    <div class="box-body">
                        <div class="row" style="justify-content: end;">
                            @include('layouts.flash-message')
                            
                            <a class="delete btn btn-warning" style="margin-bottom: 10px;" onclick='ViewTaskModel1({{ $user_details->id }})'>Send Money</a>
                            <?php $total_earn_amount = 0;$total_with_amount = 0; ?>
                            @if($user_details->payment_details)
                                @foreach($user_details->payment_details as $key => $value)
                                    <?php 
                                        $total_earn_amount += $value->discount; 
                                    ?>
                                @endforeach
                            @endif
                            @if($user_details->transaction_history)
                                @foreach($user_details->transaction_history as $key => $value1)
                                    <?php 
                                        $total_with_amount += $value1->amount; 
                                    ?>
                                @endforeach
                            @endif
                            <div class="row">
                                
                                <div class="col-md-6">
                                    <div class="card">
                                        <div class="card-body">
                                            <h4>Customer Details</h4>
                                            
                                            <P>
                                                <strong>Name : </strong>{{ $user_details->address_details->name ?? '' }}<br/>
                                                <strong>Email  : </strong>{{ $user_details->address_details->email ?? '' }}<br/>
                                                <strong>Mobile No. : </strong>{{ $user_details->address_details->phone ?? '' }}<br/>
                                                <strong>Address. : </strong>{{ $user_details->address_details->address ?? '' }}, {{ $user_details->address_details->city_details->name ?? '' }}, {{ $user_details->address_details->state_details->name ?? '' }}, {{ $user_details->address_details->country_details->name ?? '' }}, {{ $user_details->address_details->pincode ?? '' }}<br/>
                                                <strong>Landmark. : </strong>{{ $user_details->address_details->landmark ?? '' }}<br/>
                                            </P>
                                            
                                        </div>
                                    </div>
                                </div>
                                
                                <div class="col-md-6">
                                    <div class="card">
                                        <div class="card-body">
                                            <h4>Wallet Details</h4>
                                            
                                            <P>
                                                <strong>Total Earn Amount  : </strong><span style="float:right;">{{ number_format($total_earn_amount, 2) }}</span><br/>
                                                <strong>Total Withdraw Amount  : </strong><span style="float:right;">{{ number_format($total_with_amount, 2) }}</span><br/>
                                                <strong>Total Wallet Amount : </strong><span style="float:right;">{{ number_format($user_details->wallet_amount, 2) }}</span><br/>
                                            </P>
                                            
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="card">
                                        <div class="card-body">
                                            <h4>Bank Details</h4>
                                            
                                            <P>
                                                <strong>Bank Name : </strong>{{ $user_details->bank_name ?? '' }}<br/>
                                                <strong>Account Number  : </strong>{{ $user_details->account_number ?? '' }}<br/>
                                                <strong>Ifsc Code : </strong>{{ $user_details->bank_ifsc ?? '' }}<br/>
                                            </P>
                                            
                                        </div>
                                    </div>
                                </div>
                                
                            </div>
                            
                            <div class="nav-tabs-custom">
                                <ul class="nav nav-tabs">
                                
                                    <li><a class="active" href="#activity1" data-bs-toggle="tab">Earn Amounts</a></li>
                                    <li><a href="#activity2" data-bs-toggle="tab">Withdraw Details</a></li>
                                  
                                </ul>

                                <div class="tab-content">
                                  
                                  <div class="active tab-pane" id="activity1">       
                                    
                                    <div class="row">
                                        <!--<h5></h5>-->
                                        <div class="table-responsive">
                                          <table id="example1" class="table table-bordered table-striped">
                                            <thead>
                                                <tr>
                                                    <th>S No</th>
                                                    <th>Order Id</th>
                                                    <th>Earn Percentage</th>
                                                    <th>Earn Amount</th>
                                                    
                                                    <!--<th>Action</th>-->
                                                </tr>
                                            </thead>
                                            <tbody>
                                                
                                                @if($user_details->payment_details)
                                                @foreach($user_details->payment_details as $key => $value)
                                                
                                                <tr>
                                                    <td> {{ $key + 1 }}</td>
                                                    <td>{{ $value->order_id}}</td>
                                                    <td>{{ $value->discount_per }}</td>
                                                    <td>{{ number_format($value->discount, 2) }}</td>
                                                    <!--<td>-->
                                                        
                                                    <!--</td>-->
                                                </tr>
                                                @endforeach
                                                @endif
                                            </tbody>
                                          </table>
                                        </div>
                                    </div>
                            
                                  </div>
                                  <div class="tab-pane" id="activity2">       
                                    
                                    <div class="row">
                                        <!--<h5></h5>-->
                                        <div class="table-responsive">
                                          <table id="example2" class="table table-bordered table-striped">
                                            <thead>
                                                <tr>
                                                    <th>S No</th>
                                                    <th>Amount</th>
                                                    <th>Reference</th>
                                                    <th>Proof ID</th>
                                                    
                                                    <!--<th>Action</th>-->
                                                </tr>
                                            </thead>
                                            <tbody>
                                                
                                                @if($user_details->transaction_history)
                                                @foreach($user_details->transaction_history as $key => $value1)
                                                
                                                <tr>
                                                    <td> {{ $key + 1 }}</td>
                                                    <td>{{ number_format($value1->amount, 2) }}</td>
                                                    <td>{{ $value1->reference_number }}</td>
                                                    <td>
                                                        @if($value1->proof_image)
                                                            <a href="{{ url('') }}/public/transaction/{{ $value1->proof_image }}" target="_blank"> Proof</a>
                                                        @endif
                                                    </td>
                                                    <!--<td>-->
                                                        
                                                    <!--</td>-->
                                                </tr>
                                                @endforeach
                                                @endif
                                            </tbody>
                                          </table>
                                        </div>
                                    </div>
                                    
                                  </div>
                                  <!-- /.tab-pane -->
                                </div>
                                <!-- /.tab-content -->
                            </div>
                            
                            
                            
        
                        </div>
                    </div>              
                </div>
            </div>
        </div>

        </section>
        <!-- /.content -->
      </div>
  </div>
  <!-- /.content-wrapper -->
    <script src="<?php echo url('');?>/public/admin_assets/js/vendors.min.js"></script>
    <script>
        function ViewTaskModel1(id) {
            var user_id = id;
            
            if (user_id) {
                $('#modal-default1').modal('show');
                $("#user_id").val(user_id);
            }
        }
    </script>
    
    <div class="modal fade" id="modal-default1">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h4 class="modal-title">Send Money</h4>
            <span class="btn-close" data-bs-dismiss="modal" aria-label="Close"></span>
          </div>
          <div class="modal-body" id="load_html">
            <form action="{{ route('admin.user.transaction.history') }}" method="post" enctype="multipart/form-data">
                @csrf
                <input type="hidden" name="user_id" id="user_id">
                <div class="row">
                    
                    <div class="col-md-12">
                        <input type="text" class="form-control" id="with_amount" name="with_amount" placeholder="Enter Amount" required>
                    </div>
                    <div class="col-md-12" style="display: none" id="error_code_en">
                        <p style="color:red;">Please Enter the Amount less than User Wallet Amount</p>
                    </div>
                    <br><br>
                    <div class="col-md-12">
                        <input type="text" class="form-control" id="refer_number" name="refer_number" placeholder="Bank Reference Number">
                    </div>
                    <br><br>
                    <div class="col-md-12">
                        <input type="file" class="form-control" id="screen_shot" name="screen_shot" placeholder="Bank Reference Number" required>
                    </div>
                    <br><br>
                    <div class="col-md-4">
                        <input type="submit" name="submit" id="mp_cashout_1" class="btn btn-primary" value="Submit">
                    </div>
                </div>
            </form>
          </div>
          <!-- <div class="modal-footer">
            <span class="btn btn-danger" data-bs-dismiss="modal">Close</span>
          </div> -->
        </div>
        <!-- /.modal-content -->
      </div>
      <!-- /.modal-dialog -->
    </div>
    <script>
        $(document).ready(function () {
            
            var user_amount = "{{ $user_details->wallet_amount }}";
            $('#with_amount').on('keyup', function () {
                
                var with_amount = $("#with_amount").val();
                
                if(parseFloat(user_amount) <= parseFloat(with_amount))
                {
                    $("#error_code_en").show();
                    $('#mp_cashout_1').attr('disabled','disabled');
                }
                else
                {
                    $("#error_code_en").hide();
                    $('#mp_cashout_1').removeAttr('disabled','disabled');
                }
                
                
            });
        });
    </script>
@endsection