<?php
    const STATUS_PENDING = '<span style="color:red">PENDING</span>';
    const STATUS_PAID = '<span style="color:green">PAID</span>';
    
    function convertPaymentStatus($paymentStatus){
        switch($paymentStatus){
            case 1: return STATUS_PENDING;
                break;
            case 2: return STATUS_PAID;
                break;
            case 3: return 'EXPIRED';
        }
    }
    
    function convertPaymentType($paymentType){
        switch($paymentType){
            case 1: return 'COD';
                break;
            case 2: return 'NON TUNAI';
                break;
        }
    }

    function convertDeliveryStatus($statusId){
    	switch($statusId){
    		case 0: return '<span style="color:red">PENDING</span>';
    		    break;
    		case 'SCHEDULED':
    		case '101': return('<span style="color:orange">PROSES</span>');
    		case '102': return('<span style="color:green">SUKSES</span>');
    		case '103': return('<span style="color:red">RETUR</span>');
    		case '104': return("BATAL");
    		default : return($statusId);
    	}
    }
    
    function convertOrderCategory($orderId){
        switch($orderId){
            case 1: return 'AR-FASHION';
                break;
            case 2: return 'AR-CARE';
                break;
        }
    }
    
    function convertOrderStatus($status){
        switch($status){
            case 0: return '<span style="color:red">PENDING</span>';
                break;
            case 1: return '<span style="color:orange">PROSES</span>';
                break;
            case 2: return '<span style="color:green">SELESAI</span>';
                break;
        }
    }

?>


<x-layout>
    @section('title', $title.' - ')
    @section('page_title', $title)

    @include('../admin/ar-css')
    @include('../admin/ar-php-script')
    @include('member/header_member')
    <div class="p-4">
        
        @if(Auth::check())
            <div><span>Member Name: </span>{{ Auth::user()->name }}</div>
            <div><span>Referral Code: </span>{{ Auth::user()->referral_code }}</div>
            <div><span>Referral Link: </span><a href="#">https://by-arsolution.com/?ref_id={{ Auth::user()->referral_code }}</a></div>

            <!-- Order Section -->
            <section class="ar-dashboard-height">
                <div class="ar-dashboard-row">
                    <div id="ar-dashboard-content">
        
                        <div style="overflow:scroll;margin:3px">
                            @if(isset($orders))
                            <table id="ar-table" class="table">
                                <tr>
                                    <th>ID</th>
                                    <th>Order Number</th>
                                    <th style="white-space:nowrap">Order Date</th>
                                    <th>Category</th>
                                    <th>Customer</th>
                                    <th>Phone</th>
                                    <th>Address</th>
                                    <th>Kota / Kecamatan</th>
                                    <th>Jumlah (Rp.)</th>
                                    <th>Biaya Kirim (Rp.)</th>
                                    <th>Payment Type</th>
                                    <th>Payment Status</th>
                                    <th>Delivery Status</th>
                                    <th>Order Status</th>
                                    <th></th>
                                </tr>
                                
                                <tbody id="ar-table-body">
                                    @foreach($orders as $item)
                                        <tr id="<?//='index_'.$item->id?>">
                                            <td>{{ $item->id }}</td>
                                            <td>{{ $item->number }}</td>
                                            <td>{!! date('d-m-Y H:i:s',strtotime($item->created_at)) !!}</td>
                                            <td style="white-space:nowrap">{!! convertOrderCategory($item->category) !!}</td>
                                            <td style="white-space:nowrap">{{ $item->customer }}</td>
                                            <td>{{ $item->phone }}</td>
                                            <td style="min-width:200px">{{ $item->address }}</td>
                                            <td>{{ $item->wilayah }}</td>
                                            <td>{{ rupiahBasic($item->total_price) }}</td>
                                            <td>{{ rupiahBasic($item->shipping_cost) }}</td>
                                            <td>{!! convertPaymentType($item->payment_type) !!}</td>
                                            <td>{!! convertPaymentStatus($item->payment_status) !!}</td>
                                            <td>{!! convertDeliveryStatus($item->delivery_status) !!}</td>
                                            <td>{!! convertOrderStatus($item->completed) !!}</td>
                                            <!--td>
                                                <div class="dropdown" style="white-space:nowrap">
                                                    <button class="dropdown-ar1_exp" style="outline:none;border:none;padding:5px;border-radius:50%" data-toggle="dropdown">
                                                        <i class="fa fa-ellipsis-v"></i>
                                                    </button>
                                                    <div class="dropdown-menu dropdown-menu-right dropdown-content1">
                                                        <a href="javascript:void(0)" id="order-edit" data-id="{{ $item->id }}">Update Status</a>
                                                    </div>
                                                    
                                                    <a href="/order-items?order_number={{$item->number}}&category={{$item->category}}" style="cursor:pointer;margin-left:10px;color:#000000">
                                                        <i class="fa fa-arrow-right"></i>
                                                    </a>
                                                </div>
                                            </td-->
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            {!! createPageNavigator($orders) !!}
                            @endif
                        </div>
                        
                    </div>
                </div>
                
            </section>            
            <!-- -->

        @endif
        
    </div>
    <!-- Feather icons-->
    <script src="https://unpkg.com/feather-icons"></script>
    <!-- Feather Icons -->
    <script>
        feather.replace();
    </script>
    
</x-layout>
