<div class="d-flex justify-content-between align-items-center mb-3">
    <h5 class="fw-bold mb-0"><i class="fas fa-building me-2 text-primary"></i><?= $customer ? 'Edit Customer' : 'New Customer' ?></h5>
    <a class="btn btn-sm btn-outline-secondary" href="<?= url('/Customers') ?>"><i class="fas fa-arrow-left me-1"></i>Back</a>
</div>

<?php if (!empty($flash)): ?><div class="alert alert-info py-2 small"><?= e($flash) ?></div><?php endif; ?>

<form method="post" action="<?= url('/Customers/save') ?>" class="rs-card p-3">
    <input type="hidden" name="_csrf" value="<?= e($csrf) ?>">
    <input type="hidden" name="customer_id" value="<?= (int) ($customer['customer_id'] ?? 0) ?>">

    <div class="row g-3">
        <div class="col-md-6">
            <label class="form-label small fw-bold">Name <span class="text-danger">*</span></label>
            <input type="text" name="name" class="form-control" value="<?= e($customer['name'] ?? '') ?>" required>
        </div>
        <div class="col-md-6">
            <label class="form-label small fw-bold">Contact Person</label>
            <input type="text" name="contact_person" class="form-control" value="<?= e($customer['contact_person'] ?? '') ?>">
        </div>
        <div class="col-md-4">
            <label class="form-label small fw-bold">Email</label>
            <input type="email" name="email" class="form-control" value="<?= e($customer['email'] ?? '') ?>">
        </div>
        <div class="col-md-4">
            <label class="form-label small fw-bold">Phone</label>
            <input type="text" name="phone" class="form-control" value="<?= e($customer['phone'] ?? '') ?>">
        </div>
        <div class="col-md-4">
            <label class="form-label small fw-bold">Status</label>
            <select name="status" class="form-select">
                <option value="active" <?= ($customer['status'] ?? 'active') === 'active' ? 'selected' : '' ?>>Active</option>
                <option value="inactive" <?= ($customer['status'] ?? '') === 'inactive' ? 'selected' : '' ?>>Inactive</option>
            </select>
        </div>
        <div class="col-md-6">
            <label class="form-label small fw-bold">Tax ID (VAT/TIN)</label>
            <input type="text" name="tax_id" class="form-control" value="<?= e($customer['tax_id'] ?? '') ?>">
        </div>
        <div class="col-md-12">
            <label class="form-label small fw-bold">Address</label>
            <textarea name="address" class="form-control" rows="2"><?= e($customer['address'] ?? '') ?></textarea>
        </div>
        <div class="col-md-12">
            <label class="form-label small fw-bold">Notes</label>
            <textarea name="notes" class="form-control" rows="2"><?= e($customer['notes'] ?? '') ?></textarea>
        </div>
    </div>

    <div class="d-flex gap-2 mt-3">
        <button type="submit" class="btn btn-primary"><?= $customer ? 'Update' : 'Create' ?> Customer</button>
        <?php if ($customer): ?>
            <a href="<?= url('/Customers/delete/' . (int) $customer['customer_id']) ?>" class="btn btn-outline-danger" onclick="return confirm('Delete this customer?')"><i class="fas fa-trash me-1"></i>Delete</a>
        <?php endif; ?>
    </div>
</form>