<?php
/**
 * ZR EXPRESS — Prepare Shipment
 * Variables available:
 * - $order
 * - $product
 */

$extra = is_array($order['extra'])
    ? $order['extra']
    : json_decode($order['extra'], true);

$shipping = $extra['shipping'] ?? [];
?>

<div class="container py-4">
    <h4 class="mb-4">
        <?= __('shipping.zrexpress.title', 'Prepare ZR EXPRESS Shipment'); ?>
    </h4>

    <form method="POST" action="/admin/orders/send-zr_express/<?= (int)$order['id']; ?>">

        <?= \Core\System\Csrf::field(); ?>

        <input type="hidden" name="shipping_provider" value="zr_express">

        <!-- Customer Name -->
        <div class="mb-3">
            <label class="form-label">
                <?= __('shipping.customer_name', 'Customer Name'); ?>
            </label>
            <input
                type="text"
                class="form-control"
                value="<?= htmlspecialchars($order['full_name'], ENT_QUOTES, 'UTF-8'); ?>"
                readonly
            >
        </div>

        <!-- Phone -->
        <div class="mb-3">
            <label class="form-label">
                <?= __('shipping.phone', 'Phone'); ?>
            </label>
            <input
                type="text"
                class="form-control"
                value="<?= htmlspecialchars($order['phone'], ENT_QUOTES, 'UTF-8'); ?>"
                readonly
            >
        </div>

        <!-- State -->
        <div class="mb-3">
            <label class="form-label">
                <?= __('shipping.state', 'State'); ?>
            </label>
            <input
                type="text"
                class="form-control"
                value="<?= htmlspecialchars($shipping['destination']['state_code'] ?? '', ENT_QUOTES, 'UTF-8'); ?>"
                readonly
            >
        </div>

        <!-- City -->
        <div class="mb-3">
            <label class="form-label">
                <?= __('shipping.city', 'City'); ?>
            </label>
            <input
                type="text"
                class="form-control"
                value="<?= htmlspecialchars($shipping['destination']['city_name'] ?? '', ENT_QUOTES, 'UTF-8'); ?>"
                readonly
            >
        </div>

        <!-- Address -->
        <div class="mb-3">
            <label class="form-label">
                <?= __('shipping.address', 'Address'); ?>
            </label>
            <input
                type="text"
                name="address"
                class="form-control"
                required
            >
        </div>

        <!-- Amount (COD) -->
        <div class="mb-3">
            <label class="form-label">
                <?= __('shipping.amount', 'Amount'); ?>
            </label>
            <input
                type="number"
                name="amount"
                class="form-control"
                step="0.01"
                value="<?= htmlspecialchars($extra['pricing']['total'] ?? 0, ENT_QUOTES, 'UTF-8'); ?>"
                required
            >
        </div>

        <!-- Weight -->
        <div class="mb-3">
            <label class="form-label">
                <?= __('shipping.weight', 'Weight'); ?>
            </label>
            <input
                type="number"
                name="weight"
                class="form-control"
                step="0.01"
                value="1"
                required
            >
        </div>

        <!-- Note -->
        <div class="mb-3">
            <label class="form-label">
                <?= __('shipping.note', 'Note'); ?>
            </label>
            <textarea
                name="note"
                class="form-control"
                rows="3"
            ></textarea>
        </div>

        <div class="mt-4">
            <button type="submit" class="btn btn-primary">
                <?= __('shipping.send', 'Send shipment'); ?>
            </button>

            <a href="/admin/orders/view/<?= (int)$order['id']; ?>" class="btn btn-outline-secondary">
                <?= __('actions.back', 'Back'); ?>
            </a>
        </div>

    </form>
</div>
