@extends('layouts.masterBackend')

@section('title', __('backend.order'))

@section('content')
  <!-- MAIN CONTENT -->
  <div class="container-fluid">
  	<div class="row">
  		<div class="col-xs-12">
        <div class="panel panel-primary">
          <div class="panel-heading">
            <h2>
              @lang('backend.email')
            </h2>
          </div>
          {!! Form::open(['url'=>route('updateEmailText'),'method'=>'post']) !!}
          <div class="panel-body">
            @if(Session::has('message-email'))
              <div class="alert {{ Session::get('alert-class') }} alert-dismissible" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <p>{{ Session::get('message-email') }}</p>
              </div>
            @endif
            <div class="row">
              {!! Form::hidden('email_text_id', isset($email_text->id)? $email_text->id : "") !!}
              @foreach (config('translatable.locales') as $lang => $language)
                @php
                  if(empty($email_text)){
                    $get = "";
                  }else{
                    $get = $email_text->locales()->where('locale',$lang)->first();
                  }

                  if(empty($get)){
                    $text = "";
                  }else{
                    $text = $get->media_content;
                  }

                  if(count(config('translatable.locales'))>1){
                    $lang_ext = $language;
                    $offset = "";
                  }else{
                    $lang_text = "";
                    $offset = "col-sm-offset-3";
                  }
                @endphp
                <div class="col-xs-12 col-sm-6 {{$offset}}">
                  <div class="panel panel-info">
                    <div class="panel-heading">
                      <h3>{{$lang_ext or ""}}</h3>
                    </div>
                    <div class="panel-body form-group">
                      {!! Form::label('email_text',__('backend.content'),['class'=>'control-label']) !!}
                      {!! Form::textarea('email_text['.$lang.']',isset($text)? $text : '',['class'=>'form-control not-tinymce']) !!}
                    </div>
                  </div>
                </div>
              @endforeach
            </div>
          </div>
          <div class="panel-footer text-center">
            <button type="submit" class="btn btn-primary">@lang('backend.update')</button>
          </div>
          {!! Form::close() !!}
        </div>
      </div>
    </div>
  </div>

  <div class="container-fluid">
  	<div class="row">
  		<div class="col-xs-12">
        <div class="panel panel-primary">
          <div class="panel-heading">
            <h2>
              @lang('backend.order-list')
            </h2>
          </div>
          <div class="panel-body">
            @if(Session::has('message-order'))
              <div class="alert {{ Session::get('alert-class') }} alert-dismissible" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <p>{{ Session::get('message-order') }}</p>
              </div>
            @endif
            <div class="table-responsive">
              <table id="orderTable" class="table table-hover">
                <thead>
                  <tr>
                    <th># @lang('backend.id')</th>
                    <th class="text-center">@lang('backend.name')</th>
                    {{-- <th class="text-center">Email</th>
                    <th class="text-center">Phone</th> --}}
                    <th class="text-center">@lang('backend.pay-amount')</th>
                    <th class="text-center">@lang('backend.payment-date')</th>
                    <th class="text-center">@lang('backend.method')</th>
                    <th class="text-center">@lang('backend.status')</th>
                    <th class="text-center">@lang('backend.options')</th>
                  </tr>
                </thead>
                <tbody>
                  @foreach ($order_list as $key => $value)
                    <tr>
                      <td>{{ $value->order_id }}</td>
                      <td class="text-center">{{ $value->checkout_fname }} {{ $value->checkout_lname }}</td>
                      {{-- <td class="text-center">
                        <a href="mailto:{{ $value->checkout_email }}">{{ $value->checkout_email }}</a>
                      </td>
                      <td class="text-center">{{ $value->checkout_phone }}</td> --}}
                      @php
                        if( $masterCurrency == "USD" ){
                          $total = number_format($value->checkout_total,2,".",",");
                        }elseif( $masterCurrency == "EUR" ){
                          $total = number_format($value->checkout_total,2,",",".");
                        }else{
                          $total = number_format($value->checkout_total,0,",",".");
                        }
                      @endphp
                      <td class="text-center">{{$masterCurrency}} {{ $total }} {{($masterCurrency == "IDR")?"( USD ".$value->checkout_total_paypal." )" : '' }}</td>
                      <td class="text-center">{{ date('d M Y', strtotime($value->created_at)) }}</td>
                      <td class="text-center">
                        @if($value->paypal_payment_id == "-")
                          Manual
                        @else
                          Online
                        @endif
                      </td>
                      <td class="text-center">
                        @if($value->checkout_status == "paid")
                          <span class="label label-primary">{{ title_case($value->checkout_status) }}</span>
                        @elseif ($value->checkout_status == "process")
                          <span class="label label-info">{{ title_case($value->checkout_status) }}</span>
                        @elseif ($value->checkout_status == "not paid yet")
                          <span class="label label-default">{{ title_case($value->checkout_status) }}</span>
                        @else
                          <span class="label label-success">{{ title_case($value->checkout_status) }}</span>
                        @endif
                      </td>
                      <td class="text-center">
                        <a href="{{ route('checkOrderBackend',['order_id'=>$value->order_id]) }}" class="btn btn-warning detail-order-btn">
                          <i class="fa fa-search" aria-hidden="true"></i>
                        </a>
                      </td>
                    </tr>
                  @endforeach
                </tbody>
              </table>
            </div>
          </div>
        </div>
		  </div>
  	</div>
  </div>
@endsection

@section('script')
<script type="text/javascript">
	$("#orderTable").DataTable( {
    "order": [[ 3, "asc" ]]
  } );
  $(".image-select").chosen();
</script>
@endsection
