@extends('layouts.backend-layout')
@section('content')
    <div class="page-wrapper">
        <div class="page-content">
            <!--breadcrumb-->
            <div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
                <div class="breadcrumb-title pe-3">Customer Profile</div>
                <div class="ps-3">
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb mb-0 p-0">
                            <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}"><i class="bx bx-home-alt"></i></a>
                            </li>
                            <li class="breadcrumb-item active" aria-current="page"> Profile</li>
                        </ol>
                    </nav>
                </div>
            </div>
            <!--end breadcrumb-->
            <div class="container">
                <div class="main-body">
                    <div class="row">
                        <div class="col-lg-4">
                            <div class="card">
                                <div class="card-body  p-5">
                                    <div class="d-flex flex-column align-items-center text-center">
                                        <img src="{{ asset($customer->image?$customer->image:'backend/assets/images/avatars/avatar-2.png') }}" alt="Admin" class="rounded-circle p-1 bg-primary" width="110">
                                        <div class="mt-3">
                                            <h4>{{ $customer->name }}</h4>
                                            <p class="text-secondary mb-1">{{ $customer->designation }}</p>
                                            <p class="text-muted font-size-sm">{{ $customer->address }}</p>
                                            <p class="text-muted font-size-sm">{{ $customer->email }}</p>
                                            <p class="text-muted font-size-sm">{{ $customer->phone }}</p>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                        <div class="col-lg-8">
                            <div class="card p-5"><a href="{{ url()->previous() }}" style="float:right;width: 100%; text-align: right"><button class="btn btn-sm btn-primary ">Back</button></a>
                                <div class="card-title d-flex align-items-center">
                                    <div><i class="bx bxs-plus-square me-1 font-22 text-primary"></i>
                                    </div>
                                    <h5 class="mb-0 text-primary">Order History</h5>
                                </div>
                                <hr>
                                <div   class="card-body">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="table-responsive">
                                                <table class="table table-bordered tablesorter" id="sortTable">
                                                    <thead class="table-light">
                                                    <tr>
                                                        <th># <i class="fas fa-angle-down"></i></th>
                                                        <th style="text-align: left !important;">Customer Info</th>
                                                        <th>Invoice ID</th>
                                                        <th>Payment Method</th>
                                                        <th>Total Amount</th>
                                                        <th>Order Time</th>
                                                        <th>Appx. Delivered Time</th>
                                                        <th>Status</th>
                                                        <th>Actions</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    @if(count($customer_orders))
                                                        @foreach($customer_orders as $key)
                                                            <tr>
                                                                <td>{{ $loop->index +1  }}</td>
                                                                <td style="text-align: left !important;">
                                                                    {{$key->customer->name}} <br />
                                                                    {{$key->customer->phone}} <br />
                                                                    {{$key->customer->address}}<br />
                                                                </td>
                                                                <td>{{ $key->invoice_id }}</td>
                                                                <td>{!! str_replace('_', ' ', $key->payment_method) !!}</td>
                                                                <td>৳{{ number_format((float)$key->total_amount + $key->shipping_charge - $key->coupon_discount, 2, '.', '')}}</td>
                                                                <td>{{ $key->created_at->format('d-m-Y h:i A') }}</td>
                                                                <td>
                                                                    @if($key->approximate_delivered_time)
                                                                        {{ date('d-m-Y h:i A', strtotime($key->approximate_delivered_time)) }}
                                                                    @endif
                                                                </td>
                                                                <td>
                                                                    @if($key->order_status =="Pending")
                                                                        <div class="badge rounded-pill text-warning bg-light-warning p-2 text-uppercase px-3">
                                                                        <i class='bx bxs-circle me-1'></i>Pending</div>
                                                                    @elseif($key->order_status =="Placed")
                                                                        <div class="badge rounded-pill text-info bg-light-info p-2 text-uppercase px-3">
                                                                            <i class='bx bxs-circle me-1'></i>Placed</div>
                                                                    @elseif($key->order_status =="Confirmed")
                                                                        <div class="badge rounded-pill text-success bg-light-success p-2 text-uppercase px-3">
                                                                            <i class='bx bxs-circle me-1'></i>Confirmed</div>
        
                                                                    @elseif($key->order_status =="Proceed")
                                                                        <div class="badge rounded-pill text-primary bg-light-primary p-2 text-uppercase px-3">
                                                                            <i class='bx bxs-circle me-1'></i>Proceed</div>
        
                                                                    @elseif($key->order_status =="Delivered")
                                                                        <div class="badge rounded-pill text-primary bg-light-primary p-2 text-uppercase px-3">
                                                                            <i class='bx bxs-circle me-1'></i>Delivered</div>
        
                                                                    @elseif($key->order_status =="Completed")
                                                                        <div class="badge rounded-pill text-primary bg-light-primary p-2 text-uppercase px-3">
                                                                            <i class='bx bxs-circle me-1'></i>Completed</div>
                                                                    @endif
                                                                </td>
                                                                <td>
                                                                    <div class="dropdown">
                                                                        <a class="dropdown-toggle dropdown-toggle-nocaret action-btn"  type="button" data-bs-toggle="dropdown" aria-expanded="false">...</a>
                                                                        <ul class="dropdown-menu" style="margin: 0px;">
                                                                            <li><a class="dropdown-item" href="{{ route('admin.customers-orders-details.show',['id'=>$key->invoice_id]) }}"><i class='bx bxs-notepad' style="color: blue"></i> View</a></li>
                                                                            <li><a class="dropdown-item deleteModalClass" data-value="{{ $key->id }}" href="#" data-bs-toggle="modal" data-bs-target="#deleteModal" title="Update Status"><i class='bx bxs-pencil' style="color: red"></i> Update Status</a> </li>
                                                                        </ul>
                                                                    </div>
                                                                </td>
                                                            </tr>
                                                        @endforeach
                                                    @endif
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="mt-3 text-right" style="float:right;">
                                            {{$customer_orders->links("pagination::bootstrap-4")}}
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="card p-5">
                                <div class="card-title d-flex align-items-center">
                                    <div><i class="bx bxs-plus-square me-1 font-22 text-primary"></i>
                                    </div>
                                    <h5 class="mb-0 text-primary">Billing and Shipping Address</h5>
                                </div>
                                <hr>
                                <div   class="card-body">
                                    <div class="row">
                                        <div class="col-md-6">
                                            <h6>Billing Address</h6>
                                            <table>
                                                <tr>
                                                    <td>Name</td>
                                                    <td>{{ $customer->billing?$customer->billing->name:"" }}</td>
                                                </tr>
                                                <tr>
                                                    <td>Email</td>
                                                    <td>{{ $customer->billing?$customer->billing->email:"" }}</td>
                                                </tr>
                                                <tr>
                                                    <td>Phone</td>
                                                    <td>{{ $customer->billing?$customer->billing->phone:"" }}</td>
                                                </tr>
                                                <tr>
                                                    <td>Address</td>
                                                    <td>{{ $customer->billing?$customer->billing->address:"" }}</td>
                                                </tr>
                                                <tr>
                                                    <td>City</td>
                                                    <td>{{ $customer->billing?$customer->billing->town_city:"" }}</td>
                                                </tr>
                                                <tr>
                                                    <td>Country</td>
                                                    <td>{{ $customer->billing?$customer->billing->country:"" }}</td>
                                                </tr>
                                                </tr>
                                                <tr>
                                                    <td>Zip Code</td>
                                                    <td>{{ $customer->billing?$customer->billing->zip_code:"" }}</td>
                                                </tr>
                                            </table>
                                        </div>
                                        <div class="col-md-6">
                                            <h6>Shipping Address</h6>
                                            <table>
                                                <tr>
                                                    <td>Name</td>
                                                    <td>{{ $customer->shipping?$customer->shipping->ship_name:"" }}</td>
                                                </tr>
                                                <tr>
                                                    <td>Email</td>
                                                    <td>{{ $customer->shipping?$customer->shipping->ship_email:"" }}</td>
                                                </tr>
                                                <tr>
                                                    <td>Phone</td>
                                                    <td>{{ $customer->shipping?$customer->shipping->ship_phone:"" }}</td>
                                                </tr>
                                                <tr>
                                                    <td>Address</td>
                                                    <td>{{ $customer->shipping?$customer->shipping->ship_address:"" }}</td>
                                                </tr>
                                                <tr>
                                                    <td>City</td>
                                                    <td>{{ $customer->shipping?$customer->shipping->ship_town_city:"" }}</td>
                                                </tr>
                                                <tr>
                                                    <td>Country</td>
                                                    <td>{{ $customer->shipping?$customer->shipping->ship_country:"" }}</td>
                                                </tr>
                                                </tr>
                                                <tr>
                                                    <td>Zip Code</td>
                                                    <td>{{ $customer->shipping?$customer->shipping->ship_zip_code:"" }}</td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="deleteModal" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog modal-confirm">
            <form action="{{ route('admin.customers-orders.change-status') }}" method="post" class="modal-content">
                @csrf
                <input name="delete_id" type="hidden">
                <div class="modal-header flex-column">
                    <div class="icon-box" style="border: 1px solid green">
                        <i class="bx bx-cart" style="color: green"></i>
                    </div>
                    <h4 class="modal-title w-100">Update Status</h4>
                </div>
                <div class="modal-body" style="text-align: left !important;">
                    <div class="form-group">
                        <label for="inputFirstName" class="form-label col-md-12">Select Size <span class="required">*</span></label>
                        <select name="order_status" class="form-control single-select" required>
                            <option value="">Select Status</option>
                            <option value="Pending">Pending </option>
                            <option value="Placed">Placed </option>
                            <option value="Confirmed">Confirmed </option>
                            <option value="Proceed">Proceed</option>
                            <option value="Delivered">Delivered</option>
                            <option value="Completed">Completed</option>
                        </select>
                    </div>
                    <div class="form-group mt-3">
                        <label for="inputFirstName" class="form-label col-md-12">Approximate Delivered Time </label>
                        <input type="datetime-local" name="approximate_delivered_time" class="form-control"/>
                    </div>
                </div>
                <div class="modal-footer justify-content-center">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-danger">Submit</button>
                </div>
            </form>
        </div>
    </div>
@endsection
