@version(2)
@load('css/shop.css')

<div class="shp shp-narrow">
	<div class="shp-top"><h2 class="shp-title">{{ $lang->shop_my_orders }}</h2></div>

	@if ($is_member)
		<div class="shp-summary" style="margin-bottom:16px">
			@if (!empty($my_grade))
			<div class="shp-summary-row"><span>{{ $lang->shop_grade }}</span><span><strong class="shp-accent">{{ $my_grade->title }}</strong> <small class="shp-sub-text">({{ sprintf($lang->shop_grade_total, shop_money_base($my_grade->total_spend)) }})</small></span></div>
			@endif
			<div class="shp-summary-row is-total"><span>{{ $lang->shop_credit_balance }}</span><span>{{ shop_money_base($credit_balance) }}</span></div>
		</div>

		@if (empty($orders))
		<p class="shp-empty">{{ $lang->shop_no_orders }}</p>
		@else
		<table class="shp-table">
			<thead><tr><th>{{ $lang->shop_order_code }}</th><th>{{ $lang->shop_total }}</th><th>{{ $lang->shop_status }}</th><th></th></tr></thead>
			<tbody>
				@foreach ($orders as $o)
				<tr>
					<td><strong>{{ $o->order_code }}</strong><br /><small class="shp-sub-text">{{ zdate($o->regdate, 'Y.m.d H:i') }}</small></td>
					<td>{{ shop_money_in($o->payment_price, $o->currency ?? 'KRW') }}</td>
					<td>@php $shp_ds = $o->display_status ?? $o->status; @endphp<span class="shp-st shp-st-{{ $shp_ds }}">{{ $lang->{'shop_status_' . $shp_ds} ?? $shp_ds }}</span></td>
					<td style="white-space:nowrap"><a href="{{ getUrl('', 'mid', $mid, 'act', 'dispCommerceOrderResult', 'code', $o->order_code) }}" class="shp-accent">{{ $lang->shop_view }}</a>@if ($shp_ds === 'confirmed' && !empty($o->needs_review)) <a href="{{ getUrl('', 'mid', $mid, 'act', 'dispCommerceOrderResult', 'code', $o->order_code, 'review', '1') }}" class="shp-ok-link">{{ $lang->shop_write_review }}</a>@endif</td>
				</tr>
				@if ($shp_ds === 'pending')
				<tr class="shp-pending-row">
					<td colspan="4">
						<p class="shp-pending-msg">{{ !empty($o->pending_deadline) ? sprintf($lang->shop_pending_notice, zdate($o->pending_deadline, 'Y.m.d A g:i')) : $lang->shop_pending_notice_nodate }}</p>
						@if (!empty($o->resume_pay_url))
						<a class="shp-btn shp-btn-primary shp-btn-sm" href="{{ escape($o->resume_pay_url) }}">{{ $lang->shop_resume_pay }}</a>
						@else
						<span class="shp-pending-msg">{{ $lang->shop_pending_expired }}</span>
						@endif
						<form action="{{ getUrl('') }}" method="post" style="display:inline" onsubmit="return confirm('{{ $lang->shop_pending_cancel_ask }}')">
							<input type="hidden" name="module" value="commerce" />
							<input type="hidden" name="mid" value="{{ $mid }}" />
							<input type="hidden" name="act" value="procCommerceClaim" />
							<input type="hidden" name="order_code" value="{{ $o->order_code }}" />
							<button type="submit" class="shp-btn shp-btn-sm">{{ $lang->shop_cancel_order }}</button>
						</form>
					</td>
				</tr>
				@endif
				@endforeach
			</tbody>
		</table>
		@endif

		@if (!empty($credit_logs))
		<h3 style="margin:24px 0 8px;font-size:15px">{{ $lang->shop_credit_history }}</h3>
		<table class="shp-table">
			<thead><tr><th>{{ $lang->shop_credit_date }}</th><th>{{ $lang->shop_credit_change }}</th><th>{{ $lang->shop_credit_balance }}</th><th>{{ $lang->shop_credit_type }}</th></tr></thead>
			<tbody>
				@foreach ($credit_logs as $cl)
				<tr>
					<td><small>{{ zdate($cl->regdate, 'Y.m.d H:i') }}</small></td>
					<td class="{{ $cl->amount >= 0 ? 'shp-amt-plus' : 'shp-amt-minus' }}">{{ $cl->amount >= 0 ? '+' : '' }}{{ number_format($cl->amount) }}</td>
					<td>{{ number_format($cl->balance_after) }}</td>
					<td>{{ $lang->{'shop_credit_type_' . $cl->type} ?? $cl->type }}</td>
				</tr>
				@endforeach
			</tbody>
		</table>
		@endif
	@else
	<p class="shp-detail-summary">{{ $lang->shop_guest_lookup_help }}</p>
	<form action="{{ getUrl('') }}" method="post" class="shp-form">
		<input type="hidden" name="act" value="procCommerceGuestLookup" />
		<input type="hidden" name="mid" value="{{ $mid }}" />
		<fieldset>
			<div class="shp-row"><label>{{ $lang->shop_order_code }}</label><input type="text" name="order_code" required /></div>
			<div class="shp-row"><label>{{ $lang->shop_guest_password }}</label><input type="password" name="guest_password" required autocomplete="off" /></div>
			<button type="submit" class="shp-btn shp-btn-primary" style="width:100%">{{ $lang->shop_lookup }}</button>
		</fieldset>
	</form>
	@endif

	<p class="shp-foot-links">
		<a href="{{ getUrl('', 'mid', $mid, 'act', 'dispCommerceList') }}">{{ $lang->shop_back_list }}</a>
	</p>
</div>
