<?php
$location = $location ?? [];
?>
<div class="enterprise-settings-fields">
    <div class="enterprise-field">
        <label class="enterprise-field-label">Name <span class="text-danger">*</span></label>
        <input type="text" name="name" class="form-control" maxlength="200" required
               value="<?= esc(old('name', $location['name'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Code</label>
        <input type="text" name="code" class="form-control" maxlength="30"
               value="<?= esc(old('code', $location['code'] ?? '')) ?>"
               placeholder="Short identifier">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Location Type</label>
        <select name="location_type" class="form-select">
            <option value="">Select type</option>
            <?php foreach (['depot', 'stop', 'hub', 'warehouse', 'customer', 'other'] as $t): ?>
                <option value="<?= $t ?>" <?= old('location_type', $location['location_type'] ?? '') === $t ? 'selected' : '' ?>>
                    <?= esc(ucfirst($t)) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field enterprise-field--full">
        <label class="enterprise-field-label">Address</label>
        <input type="text" name="address" class="form-control" maxlength="255"
               value="<?= esc(old('address', $location['address'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">City</label>
        <input type="text" name="city" class="form-control" maxlength="100"
               value="<?= esc(old('city', $location['city'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Country</label>
        <input type="text" name="country" class="form-control" maxlength="100"
               value="<?= esc(old('country', $location['country'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Contact Name</label>
        <input type="text" name="contact_name" class="form-control" maxlength="120"
               value="<?= esc(old('contact_name', $location['contact_name'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Contact Phone</label>
        <input type="text" name="contact_phone" class="form-control" maxlength="30"
               value="<?= esc(old('contact_phone', $location['contact_phone'] ?? '')) ?>">
    </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', $location['status'] ?? 'active') === $s ? 'selected' : '' ?>>
                    <?= esc(ucfirst($s)) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field enterprise-field--full">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="3"><?= esc(old('notes', $location['notes'] ?? '')) ?></textarea>
    </div>
</div>

<?= view('Modules\Transport\Views\partials\map_picker', [
    'mapSettings' => $mapSettings ?? [],
    'latitude'    => old('latitude', $location['latitude'] ?? ''),
    'longitude'   => old('longitude', $location['longitude'] ?? ''),
    'mapId'       => 'location-map-picker',
]) ?>
