<x-layout>
    @section('title', $title.' - ')
    @section('page_title', $title)
    @include('admin/ar-css')
    @include('admin/ar-php-script')
    @include('admin/header_admin')
    
    <section id="dashboard" class="ar-dashboard-height">
        <div class="ar-dashboard-row" style="height:100%">
            <div id="ar-left-nav">
                @include('admin/left_nav')
            </div>
    
            <div id="ar-dashboard-content">
                <a class="btn-regular" href="booking-create">+ New Booking</a>
                <!--<a id="btn-invoice-new" class="btn-regular">Create New Invoice</a>-->

                <div class="table-container">
                    <table id="ar-table">
                        <tr>
                            <th style="width:1%">ID</th>
                            <th>Nama</th>
                            <th>Cust. ID</th>
                            <th>Phone</th>
                            <th>Tgl. Booking</th>
                            <th style="white-space:nowrap">Tgl. Appointment</th>
                            <th>Waktu</th>
                            <th>Status</th>
                            <th>Progress</th>
                            <th>Action</th>
                        </tr>
                            
                        <tbody>
                            <?
                                foreach($bookings as $booking)
                                {
                                    switch($booking->status){
                                        case 0: $status = 'REQUEST';
                                                $myClass = 'ar-request';
                                            break;
                                            
                                        case 1: $status = 'APPROVED';
                                                $myClass = 'ar-approved';
                                            break;
                                                
                                        case 2: $status = 'DONE';
                                                $myClass = '';
                                    }
                                        
                                    $appointmentDate = date('d-m-Y',strtotime($booking->appointment_date));
                                    $createdAt = date('d-m-Y H:i:s',strtotime($booking->created_at));
                                        
                            ?>
                                    <tr>
                                        <td><?=$booking->id?></td>
                                        <td><?=$booking->name?></td>
                                        <td><?=$booking->customer_id?></td>
                                        <td><?=$booking->phone?></td>
                                        <td style="width:1%;white-space:nowrap"><?=$createdAt?></td>
                                        <td style="width:1%;white-space:nowrap"><?=$appointmentDate?></td>
                                        <td style="width:1%;white-space:nowrap"><?=$booking->appointment_name?></td>
                                        <td><div class="<?=$myClass?>"><?=$status?></div></td>
                                        <td></td>
                                        <td style="width:1%">
                                            <div class="dropdown">
                                                <button class="dropdown-ar1" 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">
                                                    <? $formName='approve'.$booking->id ?>
                                                    <form id="<?=$formName ?>" method="post" action="/booking-approve">
                                                        @csrf
                                                        <input type="hidden" name="booking_id" value="<?=$booking->id?>">
                                                        <a onclick="submitLink('<?=$formName ?>');">Approve</a>
                                                    </form>
                                                            
                                                    <a href="/booking-edit?id=<?=$booking->id?>">Edit</a>
    
                                                    <? $formName='delete'.$booking->id ?>
                                                    <form id="<?=$formName ?>" method="post" action="/booking-delete">
                                                        @csrf
                                                        <input type="hidden" name="booking_id" value="<?=$booking->id?>">
                                                        <a onclick="checkDelete('<?=$formName ?>');">Delete</a>
                                                    </form>
                                                            
                                                    <a href="/booking-billing?id=<?=$booking->id?>">Create Billing</a>
                                                </div>
                                                        
                                                <a href="/booking-items?booking_id={{ $booking->id }}" style="cursor:pointer;margin-left:10px;color:#000000">
                                                    <i class="fa fa-arrow-right"></i>
                                                </a>
                                            </div>
                                                
                                        </td>
                                    </tr>
                            <?
                                }
                            ?>
                        </tbody>
                    </table>
                    <?
                        if($bookings != null){
                            echo createPageNavigator($bookings);
                        }
                    ?>
                </div>
            </div>
        </div>
    </section>

    <x-invoice_setup_form/>
    
    @include('admin/ar-script')
    <script>
        $("#btn-invoice-new").click(function(e){
            $("#modal-invoice").modal("show");
        });
        
        /*
        $("#btn-invoice-post").click(function(e){
            e.preventDefault();

            let formData = new FormData($('#frmInvoice')[0]);

            $.ajax({
                headers: {
                    'X-CSRF-Token': "{{ csrf_token() }}" 
                },
                url: "billing-item-discount",
                method: "POST",
                cache: false,
                contentType: false,
                processData: false,
                data: formData,
                success: function(response)
                {
                    window.location.reload();
                }
            });
        });
        */
        
    </script>

</x-layout>