@extends('adminlte::page')
@section('title', 'Change Plan')
@section('content')
<div class="wizard row">
    <div class="col-md-12 pd-4">
      <div class="box ">
        <!-- title of the page and heading-->
        <div class="box-header with-border main-box">
          <i class="ion ion-clipboard"></i>
          <h3 class="box-title">Change Plan</h3>
        </div> 
        <!--end title-->
        <!-- start body of the page--> 
        <!-- start box body --> 
        <div class="box-body">
          <div class="col-12">
              @php
                //dd($plans);
              @endphp
              @php
                $pname = $plan->plan_name;
              @endphp
              @foreach($slugname_arr as $slugname)
                  @if($pname==$slugname)
                      @php
                         $invoice_plan_name = $display_name_arr[$slugname];
                      @endphp
                  @endif
              @endforeach
              @if($plan->date_cancel_at!="")
                <div class="form-group col-md-12">
                    @if($plan->date_cancel_at)
                    <div class="box-header with-border">
                        <span style="color: red;font-size: 18px;">
                            <div class="form-group col-md-12">  
                                Your Cancellation Request for {{$invoice_plan_name}} is under processing.
                            </div>
                            <div class="form-group col-md-12">
                                Cancellation Initiated at : {{$plan->date_cancelled_at}}
                            </div>
                            <div class="form-group col-md-12">
                                It will be cancelled on {{$plan->date_cancel_at}}
                            </div>
                        </span>
                    </div>
                    @endif
                    <form id="payment-form" action="{{URL::to('/change_plan')}}" method="POST">
                      {!! csrf_field() !!}
                      <div class="form-group">
                          <div class="col-6">
                              <label style="color: blue;">Please Click the button to renew the plan.</label>
                              <br>
                              <input type="hidden" name="email" id="email" value="{{$plan->email}}">
                              <button type="submit" class="btn btn-primary btn-sm" onClick='return confirmRenewCheck();'>Renew Plan</button>
                          </div>
                      </div>
                    </form>
                </div>
              @endif
              @if($plan->date_cancel_at=="")
                @if($plan->stripe_status=="active")
                  <form id="payment-form" action="{{URL::to('/change_plan')}}" method="POST">
                    {!! csrf_field() !!}
                    <div class="form-group ">
                        <div class="col-12">
                            <span style="font-size: 18px;">
                                You have an active subscription of {{$plan->currency}} {{$plan->amount}} per {{$plan->payment_interval}} for <span style="color: blue;"> 
                                {{$invoice_plan_name}} </span> Plan
                            </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-12">
                            <span style="font-size: 18px;">
                                Subscription Activated From : {{$plan->subscription_start}}
                                <br>
                                Subscription Active Till {{$plan->subscription_end}}
                            </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-6">
                         
                            <label style="color: blue;">Please Click the button to change the plan.</label>
                            <br>
                            <input type="hidden" name="email" id="email" value="{{$plan->email}}">
                            <button type="submit" class="btn btn-primary btn-sm" onClick='return confirmChangeCheck();'>Change Plan</button>
                          
                        </div>
                    </div>
                  </form>
                @endif
              @endif
              @if($plan->stripe_status=="inactive")
                <form id="payment-form" action="{{URL::to('/change_plan')}}" method="POST">
                  {!! csrf_field() !!}
                  <div class="form-group ">
                      <div class="col-12">
                          <span style="font-size: 18px;">
                              You don't have any Active Subscription Plan. 
                          </span>
                      </div>
                  </div>
                  <div class="form-group">
                      <div class="col-6">
                       
                          <label style="color: blue;">Please Click the button to activate plan.</label>
                          <br>
                          <input type="hidden" name="email" id="email" value="{{$plan->email}}">
                          <button type="submit" class="btn btn-primary btn-sm" onClick='return confirmChangeCheck();'>Change Plan</button>
                        
                      </div>
                  </div>
                </form>
              @endif
          </div>
        </div>
      </div>
    </div>
</div>
<script>
  function confirmRenewCheck() 
  {
      var result = confirm('Are you sure you want to Renew Your Plan?');

      if (result) 
      {
          return true;
      } 
      else 
      {
          return false;
      }
  }
  function confirmChangeCheck() 
  {
      var result = confirm('Are you sure you want to Change Your Current Active Plan?');

      if (result) 
      {
          return true;
      } 
      else 
      {
          return false;
      }
  }
</script>
@endsection 