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

<div class="rs-card p-3">
<form method="post" action="<?= url('/AssetTypes/save') ?>">
    <input type="hidden" name="_csrf" value="<?= e($csrf) ?>">
    <input type="hidden" name="asset_type_id" value="<?= (int) ($type['asset_type_id'] ?? 0) ?>">
    <div class="row g-3">
        <div class="col-md-6"><label class="form-label">Name *</label><input type="text" class="form-control form-control-sm" name="name" required value="<?= e($type['name'] ?? '') ?>"></div>
        <div class="col-md-6"><label class="form-label">Code *</label><input type="text" class="form-control form-control-sm" name="code" required value="<?= e($type['code'] ?? '') ?>" placeholder="e.g. generator"></div>
        <div class="col-12"><label class="form-label">Description</label><textarea class="form-control form-control-sm" name="description" rows="2"><?= e($type['description'] ?? '') ?></textarea></div>
        <div class="col-md-4"><label class="form-label">Icon</label><input type="text" class="form-control form-control-sm" name="icon" value="<?= e($type['icon'] ?? '') ?>" placeholder="e.g. bolt"></div>
        <div class="col-md-4"><label class="form-label">Color</label><input type="color" class="form-control form-control-sm form-control-color" name="color" value="<?= e($type['color'] ?? '#0f172a') ?>"></div>
        <div class="col-md-2"><label class="form-label">Sort Order</label><input type="number" class="form-control form-control-sm" name="sort_order" value="<?= (int) ($type['sort_order'] ?? 0) ?>"></div>
        <div class="col-md-2"><label class="form-label">Status</label>
            <select name="status" class="form-select form-select-sm">
                <?php foreach (['active','inactive'] as $s): ?>
                    <option <?= ($type['status'] ?? 'active') === $s ? 'selected' : '' ?>><?= $s ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    </div>
    <div class="mt-3 d-flex gap-2">
        <button type="submit" class="btn btn-sm btn-primary"><i class="fas fa-save me-1"></i>Save</button>
        <?php if (!empty($type['asset_type_id'])): ?>
            <a class="btn btn-sm btn-outline-danger" href="<?= url('/AssetTypes/delete/' . (int) $type['asset_type_id']) ?>" onclick="return confirm('Delete?')"><i class="fas fa-trash me-1"></i>Delete</a>
        <?php endif; ?>
    </div>
</form>
</div>
