@extends('views.layouts.master')
<link rel="stylesheet" href="{{ csset('/themes/pro/modunawa/resources/css/orderlist.css') }}">
@section('content')

<!--=====================================
BANNER PART START
=======================================-->
<section class="inner-section single-banner">
	<div class="container">
		<h2>주문내역</h2>
		<ol class="breadcrumb">
			<li class="breadcrumb-item"><a href="/">Home</a></li>
			<li class="breadcrumb-item active" aria-current="page">주문내역</li>
		</ol>
	</div>
</section>
<!--=====================================
BANNER PART END
=======================================-->


<!--=====================================
ORDERLIST PART START
=======================================-->
<section class="inner-section orderlist-part">
	<div class="container">
		<div class="row">
			<div class="col-lg-12">
				<form method="GET" class="orderlist-filter">
					<h5>총 주문수 <span>- ({{ $orderCharge['count'] }})</span></h5>
					<div class="filter-short">
						<label class="form-label">필터:</label>
						<select class="form-select" name="filter" onchange="$(this).closest('form').submit()">
							<option value="" selected>전체</option>
                            @forelse ($codeTitle['status']['sorder'] ?? [] as $key => $status)
                                @if ($status['Code'] >= '0' && $status['Code'] <= '4')
							    <option value="{{ $status['Code'] }}" {{ request('filter') === $status['Code'] ? 'selected' : '' }}>
                                    {{ $status['Title'] }}
                                </option>
                                @endif
                            @empty
                            @endforelse
						</select>
                        <input type="hidden" name="page" value="1">
					</div>
				</form>
			</div>
		</div>
		<div class="row">
			<div class="col-lg-12">
                @forelse ($hd['Page'] ?? [] as $index => $order)
                    @php
                        $sorderCharge['sub_total'] = collect($order['BdPage'])->sum('C8');
                        $sorderCharge['total'] = $sorderCharge['sub_total'] + $order['D7'];
                        $sorderCharge['count'] = collect($order['BdPage'])->count();
                    @endphp
                    <div class="orderlist">
{{--                        <div class="mt-2 d-flex align-items-center justify-content-end">--}}
{{--                            <button type="submit">--}}
{{--                                <u>배송조회</u>--}}
{{--                            </button>--}}
{{--                        </div>--}}
                        <form class="orderlist-head tracking-form" action="//info.sweettracker.co.kr/tracking/4" method="post" target="DRMOKWindow">
                            <h5>order#{{ $order['C1'] }}</h5>
                            <input type="hidden" name="t_key">
                            <input type="hidden" name="t_code">
                            <input type="hidden" name="t_invoice">
                            <button type="submit">
                                <u class="value-color-green">
                                    <div class="value-color-green">{{ DataConverter::execute($order['C9'], "status('sorder')") }}</div>
                                </u>
                            </button>
                        </form>
                        <div class="orderlist-body">
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="order-track">
                                        <ul class="order-track-list">
                                            @forelse ($codeTitle['status']['sorder'] ?? [] as $key => $status)
                                                @if ($status['Code'] >= '1' && $status['Code'] <= '4')
                                                    @if ($order['C9'] === 'F')
                                                        <li class="order-track-item">
                                                            <i class="icofont-close"></i>
                                                            <span>{{ $status['Title'] }}</span>
                                                        </li>
                                                    @elseif ($status['Code'] <= $order['C9'])
                                                        <li class="order-track-item active">
                                                            <i class="icofont-check"></i>
                                                            <span>{{ $status['Title'] }}</span>
                                                        </li>
                                                    @else
                                                        <li class="order-track-item">
                                                            <i class="icofont-close"></i>
                                                            <span>{{ $status['Title'] }}</span>
                                                        </li>
                                                    @endif
                                                @endif
                                            @empty
                                            @endforelse
    {{--										<li class="order-track-item active">--}}
    {{--											<i class="icofont-check"></i>--}}
    {{--											<span>주문완료</span>--}}
    {{--										</li>--}}
    {{--										<li class="order-track-item">--}}
    {{--											<i class="icofont-close"></i>--}}
    {{--											<span>배송 준비</span>--}}
    {{--										</li>--}}
    {{--										<li class="order-track-item">--}}
    {{--											<i class="icofont-close"></i>--}}
    {{--											<span>배송 중</span>--}}
    {{--										</li>--}}
    {{--										<li class="order-track-item">--}}
    {{--											<i class="icofont-close"></i>--}}
    {{--											<span>배송 완료</span>--}}
    {{--										</li>--}}
                                        </ul>
                                    </div>
                                </div>
                                <div class="col-lg-5">
                                    <ul class="orderlist-details">
                                        <li>
                                            <h6>order no</h6>
                                            <p>{{ $order['C1'] }}</p>
                                        </li>
                                        <li>
                                            <h6>상품 갯수</h6>
                                            <p>{{ $sorderCharge['count'] }} 개</p>
                                        </li>
                                        <li>
                                            <h6>주문 시간</h6>
                                            <p>{{ DataConverter::createFromTimestamp($order['C3'], 'Y-m-d H:i:s') }}</p>
                                        </li>
                                        <li>
                                            <h6>배송 시간</h6>
                                            <p></p>
                                        </li>
                                    </ul>
                                </div>
                                <div class="col-lg-4">
                                    <ul class="orderlist-details">
                                        <li>
                                            <h6>합계</h6>
                                            <p>{{ number_format($sorderCharge['sub_total']) }} 원</p>
                                        </li>
                                        <li>
                                            <h6>할인</h6>
                                            <p>{{ number_format($order['D4']) }} 원</p>
                                        </li>
                                        <li>
                                            <h6>배송비</h6>
                                            <p>{{ number_format($order['D7']) }} 원</p>
                                        </li>
                                        <li>
                                            <h6>총 합계<small>(부가세 포함)</small></h6>
                                            <p>{{ number_format($sorderCharge['total']) }} 원</p>
                                        </li>
                                    </ul>
                                </div>
                                <div class="col-lg-3">
                                    <div class="orderlist-deliver">
                                        <h6>배송지</h6>
                                        <p>{{ $order['C6'] }}</p>
                                    </div>
                                </div>
                                <div class="col-lg-12">
                                    <div class="table-scroll">
                                        <table class="table-list">
                                            <thead>
                                                <tr>
                                                    <th scope="col">품목코드</th>
                                                    <th scope="col">상품</th>
                                                    <th scope="col">상품명</th>
                                                    <th scope="col">가격</th>
                                                    <th scope="col">브랜드</th>
                                                    <th scope="col">수량</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            @forelse ($order['BdPage'] ?? [] as $index => $orderBd)
                                                <tr>
                                                    <td class="table-serial"><h6>{{ $orderBd['C3'] }}</h6></td>
                                                    <td class="table-image"><img src="{{ env('MEDIA_URL') . $orderBd['C2'] }}" alt="product"></td>
                                                    <td class="table-name"><h6>{{ $orderBd['C4'] }}</h6></td>
                                                    <td class="table-price"><h6>{{ number_format($orderBd['C6']) }}원</h6></td>
                                                    <td class="table-brand"><h6>{{ $orderBd['C5'] }}</h6></td>
                                                    <td class="table-quantity"><h6>{{ (int)$orderBd['C7'] }}</h6></td>
                                                </tr>
                                            @empty
                                                <tr>
                                                    <td class="text-center" colspan="6">상품이 비어있습니다</td>
                                                </tr>
                                            @endforelse
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
				</div>
                @empty
                    <div>주문내역이 비어있습니다</div>
                @endforelse

			</div>
		</div>
		<div class="row">
			<div class="col-lg-12">
                <div class="bottom-paginate d-flex justify-content-center">
                    {{ $hd['Page']->appends(['limit' => request('limit'), 'sort' => request('sort')])->links() }}
                </div>
			</div>
		</div>
	</div>
</section>
<!--=====================================
ORDERLIST PART END
=======================================-->

@endsection

@push('js')
    <script>
        $('.tracking-form').on('submit', function(event) {
            event.preventDefault();

            open_window()
            this.submit()
        });

        function open_window() {
            DRMOK_window = window.open('', 'DRMOKWindow', 'width=425, height=550, resizable=0, scrollbars=no, status=0, titlebar=0, toolbar=0, left=435, top=250' );

            if (DRMOK_window == null) {
                alert("@lang('※ 윈도우 XP SP2 또는 인터넷 익스플로러 7 사용자일 경우에는 \n 화면 상단에 있는 팝업 차단 알림줄을 클릭하여 팝업을 허용해 주시기 바랍니다. \n\n※ MSN,야후,구글 팝업 차단 툴바가 설치된 경우 팝업허용을 해주시기 바랍니다.')");
            }
        }

        let DRMOK_window;
    </script>
@endpush
