<div class="page-header">
    <h1>Edit Territory</h1>
    <a class="button button-secondary button-sm" href="/territories/<?= e($territory['id']) ?>">← Back</a>
</div>

<div class="section-panel">
    <?php if (!empty($errors['_token'])): ?>
        <div class="alert alert-error"><?= e($errors['_token'][0]) ?></div>
    <?php endif; ?>

    <form method="POST" action="/territories/<?= e($territory['id']) ?>" novalidate>
        <?= csrf_field() ?>

        <div class="form-grid">
            <div class="field" style="grid-column:1/-1">
                <label for="name">Name <span style="color:#c0392b">*</span></label>
                <input class="input <?= isset($errors['name']) ? 'input-error' : '' ?>"
                       type="text" id="name" name="name"
                       value="<?= e((string) ($territory['name'] ?? '')) ?>" required autofocus>
                <?php if (isset($errors['name'])): ?>
                    <span class="field-error"><?= e($errors['name'][0]) ?></span>
                <?php endif; ?>
            </div>

            <div class="field" style="grid-column:1/-1">
                <label for="description">Description</label>
                <textarea class="input" id="description" name="description"
                          rows="3"><?= e((string) ($territory['description'] ?? '')) ?></textarea>
            </div>

            <div class="field" style="grid-column:1/-1">
                <label for="coordinates">Coordinates</label>
                <textarea class="input" id="coordinates" name="coordinates"
                          rows="3"><?= e((string) ($territory['coordinates'] ?? '')) ?></textarea>
            </div>
        </div>

        <div class="form-actions" style="margin-top:1.5rem">
            <button class="button button-primary" type="submit">Save Changes</button>
            <a class="button button-secondary" href="/territories/<?= e($territory['id']) ?>">Cancel</a>
        </div>
    </form>
</div>
