<?php $period = $period ?? []; ?>
<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" value="<?= esc(old('name', $period['name'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Code <span class="text-danger">*</span></label>
        <input type="text" name="code" class="form-control text-uppercase" maxlength="30"
               value="<?= esc(old('code', $period['code'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Start Date <span class="text-danger">*</span></label>
        <input type="date" name="start_date" class="form-control"
               value="<?= esc(old('start_date', $period['start_date'] ?? date('Y-01-01'))) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">End Date <span class="text-danger">*</span></label>
        <input type="date" name="end_date" class="form-control"
               value="<?= esc(old('end_date', $period['end_date'] ?? date('Y-12-31'))) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Status</label>
        <select name="status" class="form-select">
            <?php foreach (['open', 'closed'] as $s): ?>
                <option value="<?= $s ?>" <?= old('status', $period['status'] ?? 'open') === $s ? 'selected' : '' ?>><?= ucfirst($s) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Current Period</label>
        <?php $current = old('is_current', isset($period['is_current']) ? (string) (int) $period['is_current'] : '0'); ?>
        <div class="form-check mt-2">
            <input type="hidden" name="is_current" value="0">
            <input class="form-check-input" type="checkbox" name="is_current" value="1" id="is_current"
                   <?= $current === '1' || $current === 'on' ? 'checked' : '' ?>>
            <label class="form-check-label" for="is_current">Mark as the current financial period</label>
        </div>
    </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', $period['notes'] ?? '')) ?></textarea>
    </div>
</div>
