<?php require ROOT_PATH . '/admin/templates/header.php'; ?>

<div class="container-fluid py-3 languages-edit-page">

    <!-- Page Title -->
    <div class="row mb-3">
        <div class="col-12">
            <h2 class="page-title">
                <i class="bi bi-pencil-square me-2"></i>
                <?= __('languages.edit', 'Edit Language') ?>
            </h2>
        </div>
    </div>

    <!-- Edit Language Form -->
    <div class="card shadow-sm">
        <div class="card-body">

            <form action="/admin/languages/update/<?= (int)($language['id'] ?? 0); ?>"
                  method="post"
                  class="admin-form">
                <?= \Core\System\Csrf::field(); ?>

                <!-- Language Code -->
                <div class="mb-3">
                    <label for="code" class="form-label">
                        <?= __('languages.code', 'Language Code') ?>
                    </label>

                    <input type="text"
                           name="code"
                           id="code"
                           class="form-control"
                           value="<?= htmlspecialchars($language['code'] ?? '', ENT_QUOTES); ?>"
                           required>
                </div>

                <!-- Language Name -->
                <div class="mb-3">
                    <label for="name" class="form-label">
                        <?= __('languages.name', 'Language Name') ?>
                    </label>

                    <input type="text"
                           name="name"
                           id="name"
                           class="form-control"
                           value="<?= htmlspecialchars($language['name'] ?? '', ENT_QUOTES); ?>"
                           required>
                </div>

                <!-- Language Direction -->
                <div class="mb-3">
                    <label for="direction" class="form-label">
                        <?= __('languages.direction', 'Text Direction') ?>
                    </label>

                    <?php $direction = $language['direction'] ?? 'ltr'; ?>

                    <select name="direction" id="direction" class="form-select">
                        <option value="ltr" <?= $direction === 'ltr' ? 'selected' : '' ?>>
                            <?= __('languages.ltr', 'Left To Right (LTR)') ?>
                        </option>

                        <option value="rtl" <?= $direction === 'rtl' ? 'selected' : '' ?>>
                            <?= __('languages.rtl', 'Right To Left (RTL)') ?>
                        </option>
                    </select>
                </div>

                <!-- Default Language Checkbox -->
                <?php $isDefault = (int)($language['is_default'] ?? 0); ?>

                <div class="form-check mb-3">
                    <input type="checkbox"
                           name="is_default"
                           value="1"
                           id="is_default"
                           class="form-check-input"
                           <?= $isDefault === 1 ? 'checked' : ''; ?>>

                    <label for="is_default" class="form-check-label">
                        <?= __('languages.set_default', 'Set as default language') ?>
                    </label>
                </div>

                <!-- Submit Button -->
                <button type="submit" class="btn btn-primary">
                    <i class="bi bi-save me-1"></i>
                    <?= __('actions.save_changes', 'Update Language') ?>
                </button>

            </form>

        </div>
    </div>

</div>

<?php require ROOT_PATH . '/admin/templates/footer.php'; ?>
