<?php

require_once __DIR__ . '/../app/auth.php';
require_once __DIR__ . '/../app/layout.php';
require_once __DIR__ . '/../app/customers.php';
require_once __DIR__ . '/../app/customer-portal-accounts.php';

$user = sparrow_require_backyard_login();

$customer_key = trim((string) ($_GET['key'] ?? ''));
$customer_key = sparrow_resolve_customer_key($customer_key);

if ($customer_key === '') {
    sparrow_redirect('/backyard/customers.php');
}

$portal_account = sparrow_get_portal_account_by_customer_key($customer_key);
$portal_error = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $action = $_POST['action'] ?? '';

    if ($action === 'create_portal_account') {
        try {
            sparrow_create_portal_account(
                $customer_key,
                trim((string) ($_POST['portal_username'] ?? '')),
                (string) ($_POST['temporary_password'] ?? ''),
                trim((string) ($_POST['portal_email'] ?? ''))
            );

            sparrow_redirect('/backyard/customer-view.php?key=' . urlencode($customer_key) . '&notice=portal_created');
        } catch (Throwable $e) {
            $portal_error = $e->getMessage();
        }
    }

    if ($action === 'reset_portal_password') {
        try {
            if (!$portal_account) {
                throw new RuntimeException('This customer does not have a portal account.');
            }

            sparrow_reset_portal_password(
                (int) $portal_account['id'],
                (string) ($_POST['temporary_password'] ?? '')
            );

            sparrow_redirect('/backyard/customer-view.php?key=' . urlencode($customer_key) . '&notice=portal_password_reset');
        } catch (Throwable $e) {
            $portal_error = $e->getMessage();
        }
    }

    if ($action === 'update_portal_email') {
        try {
            if (!$portal_account) {
                throw new RuntimeException('This customer does not have a portal account.');
            }

            sparrow_update_portal_email(
                (int) $portal_account['id'],
                trim((string) ($_POST['portal_email'] ?? ''))
            );

            sparrow_redirect('/backyard/customer-view.php?key=' . urlencode($customer_key) . '&notice=portal_email_saved');
        } catch (Throwable $e) {
            $portal_error = $e->getMessage();
        }
    }

    if ($action === 'set_portal_access') {
        try {
            if (!$portal_account) {
                throw new RuntimeException('This customer does not have a portal account.');
            }

            $make_active = ($_POST['make_active'] ?? '') === '1';

            sparrow_set_portal_account_active(
                (int) $portal_account['id'],
                $make_active
            );

            $notice = $make_active ? 'portal_activated' : 'portal_paused';

            sparrow_redirect('/backyard/customer-view.php?key=' . urlencode($customer_key) . '&notice=' . $notice);
        } catch (Throwable $e) {
            $portal_error = $e->getMessage();
        }
    }

    if ($action === 'save_customer_notes') {
        $customer_notes = trim((string) ($_POST['customer_notes'] ?? ''));

        sparrow_save_customer_notes($customer_key, $customer_notes);

        sparrow_redirect('/backyard/customer-view.php?key=' . urlencode($customer_key) . '&notice=notes_saved');
    }

    if ($action === 'merge_customer') {
        $target_key = trim((string) ($_POST['target_customer_key'] ?? ''));

        if ($target_key !== '' && $target_key !== $customer_key) {
            sparrow_merge_customer_key($customer_key, $target_key);

            sparrow_redirect('/backyard/customers.php?notice=customer_merged');
        }
    }
	
	if ($action === 'unmerge_customer') {
    $source_key = trim((string) ($_POST['source_customer_key'] ?? ''));

    if ($source_key !== '') {
        sparrow_unmerge_customer_key($source_key);

        sparrow_redirect('/backyard/customer-view.php?key=' . urlencode($customer_key) . '&notice=customer_unmerged');
    }
}

if ($action === 'save_customer_history_contact') {
    try {
        sparrow_update_customer_history_contact(
            $customer_key,
            trim(
                (string) (
                    $_POST['customer_name'] ?? ''
                )
            ),
            trim(
                (string) (
                    $_POST['customer_email'] ?? ''
                )
            ),
            trim(
                (string) (
                    $_POST['customer_phone'] ?? ''
                )
            )
        );

        sparrow_redirect(
            '/backyard/customer-view.php?key='
            . urlencode($customer_key)
            . '&notice=customer_info_saved'
        );
    } catch (Throwable $e) {
        $portal_error = $e->getMessage();
    }
}
}

$orders = sparrow_get_customer_orders_by_key($customer_key);
$customer_profile = sparrow_get_customer_profile($customer_key);
$merge_options = sparrow_get_customer_merge_options($customer_key);
$merged_customers = sparrow_get_customers_merged_into($customer_key);

if (!$orders) {
    sparrow_backyard_header('Customer Not Found');
    ?>


    <section class="card">
        <h1>Customer Not Found</h1>
        <p class="muted">No orders were found for this customer.</p>
        <a class="button" href="<?= sparrow_escape(sparrow_url('/backyard/customers.php')) ?>">
            Back to Customers
        </a>
    </section>
    <?php
    sparrow_backyard_footer();
    exit;
}

$first_order = $orders[0];

$has_billing_address = (
    $portal_account
    && trim(
        (string) (
            $portal_account['billing_address_1'] ?? ''
        )
    ) !== ''
);

$has_shipping_address = (
    $portal_account
    && trim(
        (string) (
            $portal_account['shipping_address_1'] ?? ''
        )
    ) !== ''
);

$total_ordered = 0.00;
$total_paid = 0.00;
$total_balance = 0.00;
$total_blessings = 0.00;
$active_orders = 0;
$delivered_orders = 0;

foreach ($orders as $order) {
    $order_total = (float) ($order['total_amount'] ?? 0);
    $paid = (float) ($order['paid_amount'] ?? 0);
    $blessing = (float) ($order['blessing_amount'] ?? 0);
    $balance = sparrow_customer_order_balance($order);

    $total_ordered += $order_total;
    $total_paid += $paid;
    $total_balance += $balance;
    $total_blessings += $blessing;

    $status = trim((string) ($order['status'] ?? ''));

    if (in_array($status, ['Delivered', 'Completed', 'Complete'], true)) {
        $delivered_orders++;
    } else {
        $active_orders++;
    }
}

sparrow_backyard_header('Customer History');
?>

<?php if (
    ($_GET['notice'] ?? '') === 'customer_info_saved'
): ?>
    <div class="notice-success">
        Customer information updated across all orders
        in this history.
    </div>
<?php endif; ?>

    <?php if ($portal_error !== ''): ?>
        <div class="notice-error"><?= sparrow_escape($portal_error) ?></div>
    <?php endif; ?>

    <?php
    $portal_notices = [
        'portal_created' => 'Portal account created. Give the customer the username and temporary password you entered.',
        'portal_password_reset' => 'The temporary password was reset.',
        'portal_email_saved' => 'Portal email saved.',
        'portal_activated' => 'Portal access reactivated.',
        'portal_paused' => 'Portal access paused.',
    ];
    $portal_notice = (string) ($_GET['notice'] ?? '');
    ?>

    <?php if (isset($portal_notices[$portal_notice])): ?>
        <div class="notice-success">
            <?= sparrow_escape($portal_notices[$portal_notice]) ?>
        </div>
    <?php endif; ?>

<section class="card">
    <div class="page-heading-row">
        <div>
            <h2>Customer Information</h2>

            <p class="muted">
                <?= sparrow_escape($first_order['customer_name'] ?? 'Unknown Customer') ?>
            </p>
        </div>

        <div class="heading-actions">
		<button
    type="button"
    class="button button-secondary"
    id="toggle-customer-info-edit"
>
    Edit Customer Information
</button>
<a
    class="button button-secondary"
    href="<?= sparrow_escape(
        sparrow_url(
            '/backyard/customer-print.php?key='
            . urlencode($customer_key)
        )
    ) ?>"
>
    Print Customer History
</a>
            <a class="button button-secondary" href="<?= sparrow_escape(sparrow_url('/backyard/customers.php')) ?>">
                Back to Customers
            </a>
        </div>
    </div>

    <div class="detail-grid">
        <div>
            <div class="detail-label">Customer</div>
            <div class="detail-value"><?= sparrow_escape($first_order['customer_name'] ?? '') ?></div>
        </div>

        <div>
            <div class="detail-label">Phone</div>
            <div class="detail-value"><?= sparrow_escape(sparrow_format_phone_number($first_order['customer_phone'] ?? '')) ?></div>
        </div>

        <div>
            <div class="detail-label">Email</div>
            <div class="detail-value"><?= sparrow_escape($first_order['customer_email'] ?? '') ?></div>
        </div>

        <div>
            <div class="detail-label">Orders</div>
            <div class="detail-value"><?= number_format(count($orders)) ?></div>
        </div>
    </div>
	
	<div
    class="inline-edit-box"
    id="customer-info-edit-box"
    style="display: none;"
>
    <h3>Edit Customer Information</h3>

    <p class="muted">
        Saving here will update this customer’s name,
        email, and phone across all orders in this
        customer history.
    </p>

    <form method="post">
        <input
            type="hidden"
            name="action"
            value="save_customer_history_contact"
        >

        <div class="form-grid">
            <div>
                <label for="customer_name">
                    Customer Name
                </label>

                <input
                    type="text"
                    id="customer_name"
                    name="customer_name"
                    value="<?= sparrow_escape(
                        $first_order['customer_name'] ?? ''
                    ) ?>"
                    required
                >
            </div>

            <div>
                <label for="customer_phone">
                    Phone
                </label>

                <input
                    type="text"
                    id="customer_phone"
                    name="customer_phone"
                    value="<?= sparrow_escape(
                        $first_order['customer_phone'] ?? ''
                    ) ?>"
                >
            </div>

            <div>
                <label for="customer_email">
                    Email
                </label>

                <input
                    type="email"
                    id="customer_email"
                    name="customer_email"
                    value="<?= sparrow_escape(
                        $first_order['customer_email'] ?? ''
                    ) ?>"
                >
            </div>
        </div>

        <div class="form-actions">
            <button
                type="submit"
                class="button"
            >
                Save Customer Information
            </button>

            <button
                type="button"
                class="button button-secondary"
                id="cancel-customer-info-edit"
            >
                Cancel
            </button>
        </div>
    </form>
</div>
</section>

<section class="card">
    <h2>Customer Addresses</h2>

    <?php if (!$portal_account): ?>
        <p class="muted">
            This customer does not have a portal account yet,
            so no saved addresses are available.
        </p>
    <?php else: ?>
        <div class="customer-address-grid">
            <div class="customer-address-box">
                <h3>Billing Address</h3>

                <?php if ($has_billing_address): ?>
                    <address>
                        <?php if (
                            !empty($portal_account['billing_name'])
                        ): ?>
                            <strong>
                                <?= sparrow_escape(
                                    $portal_account['billing_name']
                                ) ?>
                            </strong><br>
                        <?php endif; ?>

                        <?= sparrow_escape(
                            $portal_account['billing_address_1']
                        ) ?><br>

                        <?php if (
                            !empty(
                                $portal_account['billing_address_2']
                            )
                        ): ?>
                            <?= sparrow_escape(
                                $portal_account['billing_address_2']
                            ) ?><br>
                        <?php endif; ?>

                        <?= sparrow_escape(
                            $portal_account['billing_city'] ?? ''
                        ) ?>,
                        <?= sparrow_escape(
                            $portal_account['billing_state'] ?? ''
                        ) ?>
                        <?= sparrow_escape(
                            $portal_account[
                                'billing_postal_code'
                            ] ?? ''
                        ) ?>
                    </address>
                <?php else: ?>
                    <p class="muted">
                        No billing address has been saved.
                    </p>
                <?php endif; ?>
            </div>
            <div class="customer-address-box">
                <h3>Shipping Address</h3>

                <?php if ($has_shipping_address): ?>
                    <address>
                        <?php if (
                            !empty($portal_account['shipping_name'])
                        ): ?>
                            <strong>
                                <?= sparrow_escape(
                                    $portal_account['shipping_name']
                                ) ?>
                            </strong><br>
                        <?php endif; ?>

                        <?= sparrow_escape(
                            $portal_account['shipping_address_1']
                        ) ?><br>

                        <?php if (
                            !empty(
                                $portal_account[
                                    'shipping_address_2'
                                ]
                            )
                        ): ?>
                            <?= sparrow_escape(
                                $portal_account[
                                    'shipping_address_2'
                                ]
                            ) ?><br>
                        <?php endif; ?>

                        <?= sparrow_escape(
                            $portal_account['shipping_city'] ?? ''
                        ) ?>,
                        <?= sparrow_escape(
                            $portal_account['shipping_state'] ?? ''
                        ) ?>
                        <?= sparrow_escape(
                            $portal_account[
                                'shipping_postal_code'
                            ] ?? ''
                        ) ?>
                    </address>
                <?php else: ?>
                    <p class="muted">
                        No shipping address has been saved.
                    </p>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>
</section>

<section class="card">
    <h2>Portal Account</h2>

    <?php if (!$portal_account): ?>
        <p class="muted">
            Create a private login connected to this customer history. The account uses this customer's unique history key, not the email or phone saved on orders.
        </p>

        <form method="post">
            <input type="hidden" name="action" value="create_portal_account">

            <div class="form-grid two">
                <div class="form-field">
                    <label for="portal_username">Username</label>
                    <input
                        type="text"
                        id="portal_username"
                        name="portal_username"
                        maxlength="100"
                        autocomplete="off"
                        value="<?= sparrow_escape($_POST['portal_username'] ?? '') ?>"
                        required
                    >
                    <p class="muted">Letters, numbers, periods, underscores, and hyphens only.</p>
                </div>

                <div class="form-field">
                    <label for="temporary_password">Temporary Password</label>
                    <input
                        type="password"
                        id="temporary_password"
                        name="temporary_password"
                        minlength="8"
                        maxlength="200"
                        autocomplete="new-password"
                        required
                    >
                    <p class="muted">Use at least 8 characters. The customer will change it later.</p>
                </div>

                <div class="form-field">
                    <label for="portal_email">Real Portal Email (optional)</label>
                    <input
                        type="email"
                        id="portal_email"
                        name="portal_email"
                        maxlength="190"
                        autocomplete="off"
                        value="<?= sparrow_escape($_POST['portal_email'] ?? '') ?>"
                    >
                    <p class="muted">Leave blank if you do not have the customer's real email.</p>
                </div>
            </div>

            <div class="form-actions">
                <button type="submit" class="button">Create Portal Account</button>
            </div>
        </form>
    <?php else: ?>
        <div class="detail-grid">
            <div>
                <div class="detail-label">Username</div>
                <div class="detail-value"><?= sparrow_escape($portal_account['username']) ?></div>
            </div>

            <div>
                <div class="detail-label">Access</div>
                <div class="detail-value">
                    <?php if (!empty($portal_account['is_active'])): ?>
                        <span class="status-pill approval-status-approved">Active</span>
                    <?php else: ?>
                        <span class="status-pill approval-status-changes_requested">Paused</span>
                    <?php endif; ?>
                </div>
            </div>

            <div>
                <div class="detail-label">Password</div>
                <div class="detail-value">
                    <?= !empty($portal_account['must_change_password']) ? 'Temporary password must be changed' : 'Customer password set' ?>
                </div>
            </div>

            <div>
                <div class="detail-label">Last Login</div>
                <div class="detail-value">
                    <?= !empty($portal_account['last_login_at']) ? sparrow_escape($portal_account['last_login_at']) : 'Never' ?>
                </div>
            </div>
        </div>

        <hr>

        <form method="post">
            <input type="hidden" name="action" value="update_portal_email">

            <div class="form-field">
                <label for="portal_email">Real Portal Email (optional)</label>
                <input
                    type="email"
                    id="portal_email"
                    name="portal_email"
                    maxlength="190"
                    value="<?= sparrow_escape($portal_account['email'] ?? '') ?>"
                >
            </div>

            <div class="form-actions">
                <button type="submit" class="button button-secondary">Save Portal Email</button>
            </div>
        </form>

        <hr>

        <form method="post">
            <input type="hidden" name="action" value="reset_portal_password">

            <div class="form-field">
                <label for="new_temporary_password">New Temporary Password</label>
                <input
                    type="password"
                    id="new_temporary_password"
                    name="temporary_password"
                    minlength="8"
                    maxlength="200"
                    autocomplete="new-password"
                    required
                >
            </div>

            <div class="form-actions">
                <button type="submit" class="button button-secondary">Reset Password</button>
            </div>
        </form>

        <hr>

        <form method="post" onsubmit="return confirm('<?= !empty($portal_account['is_active']) ? 'Pause this customer’s portal access?' : 'Reactivate this customer’s portal access?' ?>');">
            <input type="hidden" name="action" value="set_portal_access">
            <input type="hidden" name="make_active" value="<?= !empty($portal_account['is_active']) ? '0' : '1' ?>">

            <div class="form-actions">
                <button type="submit" class="button <?= !empty($portal_account['is_active']) ? 'button-danger' : 'button-secondary' ?>">
                    <?= !empty($portal_account['is_active']) ? 'Pause Portal Access' : 'Reactivate Portal Access' ?>
                </button>
            </div>
        </form>
    <?php endif; ?>
</section>

<section class="card">
    <h2>Customer Notes</h2>

    <?php if (($_GET['notice'] ?? '') === 'notes_saved'): ?>
        <div class="notice-success">Customer notes saved.</div>
    <?php endif; ?>

    <form method="post">
        <input type="hidden" name="action" value="save_customer_notes">

        <textarea
            name="customer_notes"
            rows="5"
            placeholder="Preferred sizes, colors, contact notes, usual delivery details, anything helpful..."
        ><?= sparrow_escape($customer_profile['customer_notes'] ?? '') ?></textarea>

        <div class="form-actions">
            <button type="submit" class="button">
                Save Customer Notes
            </button>
        </div>
    </form>
</section>

<section class="dashboard-kpi-grid">
    <div class="dashboard-kpi-card">
        <span>Total Ordered</span>
        <strong>$<?= number_format($total_ordered, 2) ?></strong>
    </div>

    <div class="dashboard-kpi-card dashboard-kpi-money-blue">
        <span>Paid</span>
        <strong>$<?= number_format($total_paid, 2) ?></strong>
    </div>

    <div class="dashboard-kpi-card dashboard-kpi-money-red">
        <span>Balance</span>
        <strong>$<?= number_format($total_balance, 2) ?></strong>
    </div>

    <div class="dashboard-kpi-card dashboard-kpi-money-purple">
        <span>Blessings</span>
        <strong>$<?= number_format($total_blessings, 2) ?></strong>
    </div>

    <div class="dashboard-kpi-card dashboard-kpi-blue">
        <span>Active</span>
        <strong><?= number_format($active_orders) ?></strong>
    </div>

    <div class="dashboard-kpi-card dashboard-kpi-green">
        <span>Delivered</span>
        <strong><?= number_format($delivered_orders) ?></strong>
    </div>
</section>

<section class="card">
    <h2>Orders</h2>

    <div class="table-wrap">
        <table class="customer-history-table">
            <thead>
                <tr>
                    <th>Order</th>
                    <th>Date</th>
                    <th>Status</th>
                    <th>Qty</th>
                    <th>Total</th>
                    <th>Paid</th>
                    <th>Discount</th>
                    <th>Balance</th>
                    <th>Open</th>
                </tr>
            </thead>

            <tbody>
                <?php foreach ($orders as $order): ?>
                    <?php
                    $order_total = (float) ($order['total_amount'] ?? 0);
                    $paid = (float) ($order['paid_amount'] ?? 0);
                    $discount = (float) ($order['order_discount_amount'] ?? 0);
                    $balance = sparrow_customer_order_balance($order);
                    ?>
                    <tr>
                        <td><strong><?= sparrow_escape($order['order_number'] ?? '') ?></strong></td>
                        <td><?= sparrow_escape($order['order_date'] ?? '') ?></td>
                        <td><?= sparrow_escape($order['status'] ?? '') ?></td>
                        <td><?= number_format((int) ($order['total_quantity'] ?? $order['quantity'] ?? 0)) ?></td>
                        <td>$<?= number_format($order_total, 2) ?></td>
                        <td>$<?= number_format($paid, 2) ?></td>
                        <td>$<?= number_format($discount, 2) ?></td>
                        <td>$<?= number_format($balance, 2) ?></td>
                        <td>
                            <a
                                class="button button-small"
                                href="<?= sparrow_escape(sparrow_url('/backyard/order-view.php?id=' . (int) $order['id'])) ?>"
                            >
                                View
                            </a>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</section>

<details
    class="card customer-management-card"
    <?php if (
        ($_GET['notice'] ?? '') === 'customer_unmerged'
    ): ?>
        open
    <?php endif; ?>
>
    <summary>
        Customer Merge Tools
    </summary>

    <p class="muted">
        Merge duplicate customer histories or undo a previous
        merge. Old orders will not be changed.
    </p>

    <?php if (
        ($_GET['notice'] ?? '') === 'customer_unmerged'
    ): ?>
        <div class="notice-success">
            Customer was unmerged.
        </div>
    <?php endif; ?>

    <div class="customer-merge-grid">
        <section class="customer-merge-box">
            <h3>Merge Customer</h3>

            <p class="muted">
                Group this customer with another customer history.
            </p>

            <?php if (!$merge_options): ?>
                <p class="muted">
                    No other customers are available to merge into.
                </p>
            <?php else: ?>
                <form
                    method="post"
                    onsubmit="return confirm(
                        'Merge this customer into the selected '
                        + 'customer history?'
                    );"
                >
                    <input
                        type="hidden"
                        name="action"
                        value="merge_customer"
                    >

                    <label for="target_customer_key">
                        Merge this customer into:
                    </label>

                    <select
                        id="target_customer_key"
                        name="target_customer_key"
                        required
                    >
                        <option value="">
                            Choose customer...
                        </option>

                        <?php foreach (
                            $merge_options as $option
                        ): ?>
                            <option
                                value="<?= sparrow_escape(
                                    $option['customer_key']
                                ) ?>"
                            >
                                <?= sparrow_escape(
                                    $option['customer_name']
                                    ?: 'Unknown Customer'
                                ) ?>

                                <?php if (
                                    !empty($option['customer_phone'])
                                ): ?>
                                    —
                                    <?= sparrow_escape(
                                        sparrow_format_phone_number(
                                            $option['customer_phone']
                                        )
                                    ) ?>
                                <?php endif; ?>

                                <?php if (
                                    !empty($option['customer_email'])
                                ): ?>
                                    —
                                    <?= sparrow_escape(
                                        $option['customer_email']
                                    ) ?>
                                <?php endif; ?>
                            </option>
                        <?php endforeach; ?>
                    </select>

                    <div class="form-actions">
                        <button
                            type="submit"
                            class="button button-secondary"
                        >
                            Merge Customer
                        </button>
                    </div>
                </form>
            <?php endif; ?>
        </section>

        <section class="customer-merge-box">
            <h3>Unmerge Customers</h3>

            <p class="muted">
                Separate a customer who was previously merged
                into this history.
            </p>

            <?php if (empty($merged_customers)): ?>
                <p class="muted">
                    No customers are currently merged into this
                    customer.
                </p>
            <?php else: ?>
                <?php foreach (
                    $merged_customers as $merged_customer
                ): ?>
                    <form
                        method="post"
                        class="customer-unmerge-row"
                        onsubmit="return confirm(
                            'Unmerge this customer history?'
                        );"
                    >
                        <input
                            type="hidden"
                            name="action"
                            value="unmerge_customer"
                        >

                        <input
                            type="hidden"
                            name="source_customer_key"
                            value="<?= sparrow_escape(
                                $merged_customer['customer_key']
                            ) ?>"
                        >

                        <span>
                            <?= sparrow_escape(
                                $merged_customer['customer_key']
                            ) ?>
                        </span>

                        <button
                            type="submit"
                            class="button button-secondary"
                        >
                            Unmerge
                        </button>
                    </form>
                <?php endforeach; ?>
            <?php endif; ?>
        </section>
    </div>
</details>

<script>
document.addEventListener('DOMContentLoaded', function () {
    const toggleButton =
        document.getElementById(
            'toggle-customer-info-edit'
        );

    const cancelButton =
        document.getElementById(
            'cancel-customer-info-edit'
        );

    const editBox =
        document.getElementById(
            'customer-info-edit-box'
        );

    if (toggleButton && editBox) {
        toggleButton.addEventListener(
            'click',
            function () {
                editBox.style.display =
                    editBox.style.display === 'none'
                        ? 'block'
                        : 'none';
            }
        );
    }

    if (cancelButton && editBox) {
        cancelButton.addEventListener(
            'click',
            function () {
                editBox.style.display = 'none';
            }
        );
    }
});
</script>

<?php sparrow_backyard_footer(); ?>
