<?php $company = $company ?? []; ?>
<div class="enterprise-settings-fields">
    <div class="enterprise-field" style="grid-column: 1 / -1;">
        <div class="form-check">
            <input type="checkbox" name="is_one_time" value="1" class="form-check-input" id="is_one_time"
                   <?= old('is_one_time', $company['is_one_time'] ?? 0) ? 'checked' : '' ?>>
            <label class="form-check-label" for="is_one_time">One-time customer</label>
        </div>
        <div class="form-text">Check if this is a one-time engagement; still choose product, service, or project below.</div>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Customer Type <span class="text-danger">*</span></label>
        <select name="customer_type" class="form-select" required>
            <option value="">— Select —</option>
            <?php foreach (['product' => 'Product based', 'service' => 'Service based', 'project' => 'Project based'] as $value => $label): ?>
                <option value="<?= $value ?>" <?= old('customer_type', $company['customer_type'] ?? '') === $value ? 'selected' : '' ?>>
                    <?= esc($label) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Customer Name <span class="text-danger">*</span></label>
        <input type="text" name="name" class="form-control" value="<?= esc(old('name', $company['name'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Code</label>
        <input type="text" name="code" class="form-control text-uppercase" maxlength="30" value="<?= esc(old('code', $company['code'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Customer Group</label>
        <select name="customer_group_id" class="form-select">
            <option value="">— None —</option>
            <?php foreach ($groups as $g): ?>
                <option value="<?= $g['id'] ?>" <?= (string) old('customer_group_id', $company['customer_group_id'] ?? '') === (string) $g['id'] ? 'selected' : '' ?>>
                    <?= esc($g['name']) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Site</label>
        <select name="site_id" class="form-select">
            <option value="">— None —</option>
            <?php foreach (($sites ?? []) as $s): ?>
                <option value="<?= $s['id'] ?>" <?= (string) old('site_id', $company['site_id'] ?? '') === (string) $s['id'] ? 'selected' : '' ?>>
                    <?= esc($s['name']) ?><?= $s['site_type'] ? ' (' . esc($s['site_type']) . ')' : '' ?>
                </option>
            <?php endforeach; ?>
        </select>
        <div class="form-text">Mall, complex, or location that groups multiple customers.</div>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Industry</label>
        <input type="text" name="industry" class="form-control" value="<?= esc(old('industry', $company['industry'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Email</label>
        <input type="email" name="email" class="form-control" value="<?= esc(old('email', $company['email'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Phone</label>
        <input type="text" name="phone" class="form-control" value="<?= esc(old('phone', $company['phone'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Website</label>
        <input type="url" name="website" class="form-control" placeholder="https://" value="<?= esc(old('website', $company['website'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Status</label>
        <select name="status" class="form-select">
            <?php foreach (['active', 'inactive'] as $s): ?>
                <option value="<?= $s ?>" <?= old('status', $company['status'] ?? 'active') === $s ? 'selected' : '' ?>><?= ucfirst($s) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Address</label>
        <input type="text" name="address" class="form-control" value="<?= esc(old('address', $company['address'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">City</label>
        <input type="text" name="city" class="form-control" value="<?= esc(old('city', $company['city'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Country</label>
        <input type="text" name="country" class="form-control" value="<?= esc(old('country', $company['country'] ?? '')) ?>">
    </div>
    <div class="enterprise-field" style="grid-column: 1 / -1;">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="3"><?= esc(old('notes', $company['notes'] ?? '')) ?></textarea>
    </div>
</div>
