<?php
// public/backyard/order-new.php

require_once __DIR__ . '/../app/auth.php';
require_once __DIR__ . '/../app/layout.php';
require_once __DIR__ . '/../app/orders.php';
require_once __DIR__ . '/../app/settings.php';

$user = sparrow_require_backyard_login();
$pdo = sparrow_db();

$is_admin = true;

$order_settings = sparrow_get_settings($pdo, [
    'default_order_status',
]);

$default_order_status = trim(
    (string) ($order_settings['default_order_status'] ?? '')
);

if ($default_order_status === '') {
    $default_order_status = 'Order Received';
}

$values = [
    'order_status' => $default_order_status,
];

sparrow_backyard_header('New Order');
?>

<section class="card">
    <h1>New Order</h1>

    <p class="muted">
        Create a new order from inside Backyard.
    </p>
</section>

<section class="card">
    <form
        method="post"
        action="<?php echo sparrow_escape(sparrow_url('/backyard/order-save.php')); ?>"
        enctype="multipart/form-data"
        class="sparrow-order-form"
    >
        <?php require __DIR__ . '/../app/order-form.php'; ?>
    </form>
</section>

<?php
sparrow_backyard_footer();
