@extends('shop.layout')
@section('title', __('portal.shop.checkout_title'))
@section('content')
@php
    $currency = $tenant->settings['currency'] ?? 'MDL';
    $labels = \App\Models\Tenant\OnlineOrder::DELIVERY;
@endphp

<h1 style="font-size:22px;margin-bottom:16px;">{{ __('portal.shop.checkout_title') }}</h1>

@if ($errors->any())
    <div class="card" style="border-color:#fca5a5;background:#fef2f2;margin-bottom:14px;">
        <ul style="margin:0;padding-left:18px;color:#991b1b;font-size:14px;">
            @foreach ($errors->all() as $e)<li>{{ $e }}</li>@endforeach
        </ul>
    </div>
@endif

<div style="display:grid;grid-template-columns:1fr 320px;gap:18px;align-items:start;">
    <form method="POST" action="/shop/checkout" class="card">
        @csrf
        <div class="field">
            <label>{{ __('portal.shop.full_name') }}</label>
            <input type="text" name="customer_name" value="{{ old('customer_name', ($customer ?? null)?->name) }}" required>
        </div>
        <div class="field">
            <label>{{ __('portal.shop.phone_req') }}</label>
            <input type="text" name="customer_phone" value="{{ old('customer_phone', ($customer ?? null)?->phone) }}" required placeholder="+373…">
        </div>
        <div class="field">
            <label>{{ __('portal.common.email') }}</label>
            <input type="email" name="customer_email" value="{{ old('customer_email', ($customer ?? null)?->email) }}">
        </div>
        <div class="field">
            <label>{{ __('portal.shop.delivery_req') }}</label>
            <select name="delivery_method" required>
                @foreach ($deliveryOptions as $opt)
                    <option value="{{ $opt }}">{{ $labels[$opt] ?? $opt }}</option>
                @endforeach
            </select>
        </div>
        <div class="field">
            <label>{{ __('portal.shop.address_delivery') }}</label>
            <input type="text" name="address" value="{{ old('address') }}">
        </div>
        <div class="field">
            <label>{{ __('portal.shop.notes') }}</label>
            <textarea name="notes" rows="2">{{ old('notes') }}</textarea>
        </div>
        <button class="btn block" type="submit">{{ __('portal.shop.place_order') }}</button>
    </form>

    <div class="card">
        <h3 style="font-size:15px;margin-bottom:10px;">{{ __('portal.shop.summary') }}</h3>
        <table class="cart">
            @foreach ($cart as $item)
                <tr>
                    <td>{{ $item['name'] }} <span class="muted">×{{ $item['qty'] }}</span></td>
                    <td class="r">{{ number_format($item['price'] * $item['qty'], 2) }}</td>
                </tr>
            @endforeach
        </table>
        <div style="margin-top:12px;font-size:18px;font-weight:700;text-align:right;">
            {{ number_format($subtotal, 2) }} {{ $currency }}
        </div>
        <p class="muted" style="margin-top:6px;">{{ __('portal.shop.delivery_fee_note') }}</p>
    </div>
</div>

<style>@media (max-width:720px){ .wrap div[style*="grid-template-columns:1fr 320px"]{ grid-template-columns:1fr !important; } }</style>
@endsection
