<div class="modal-dialog modal-xl">
    <div class="modal-content">
        <div class="modal-header">
            <h5 class="modal-title" id="updateWordModalLabel">Update Word: <?= htmlspecialchars($word['original_word'] ?? 'Entry') ?></h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <form action="/dictionary/word/update?wordId=<?= $word['id'] ?>" method="post" enctype="multipart/form-data">
            
            <input type="hidden" name="translation_id" value="<?= $translation['id'] ?? '' ?>">

            <div class="modal-body">
                <div class="alert alert-info mb-3">
                    <small><i class="bi bi-info-circle"></i> Update the Gĩkũyũ entry on the left and its English translation on the right.</small>
                </div>

                <div class="row g-4">
                    <div class="col-md-6">
                        <div class="card h-100 border-primary-subtle">
                            <div class="card-header bg-primary-subtle">
                                <h6 class="mb-0 text-primary">Original Language (Gĩkũyũ)</h6>
                            </div>
                            <div class="card-body">
                                <div class="row g-3">
                                    <div class="col-md-6">
                                        <label class="form-label">Category *</label>
                                        <select class="form-select searchSelect" name="category_id" required>
                                            <?php foreach ($categories as $category): ?>
                                                <option value="<?= $category['id'] ?>" <?= $word['category_id'] == $category['id'] ? 'selected' : '' ?>>
                                                    <?= htmlspecialchars($category['name']) ?>
                                                </option>
                                            <?php endforeach; ?>
                                        </select>
                                    </div>

                                    <div class="col-md-6">
                                        <label class="form-label">Word Type *</label>
                                        <select class="form-select searchSelect" name="word_type_id" required>
                                            <?php foreach ($wordTypes as $type): ?>
                                                <option value="<?= $type['id'] ?>" <?= $word['word_type_id'] == $type['id'] ? 'selected' : '' ?>>
                                                    <?= htmlspecialchars($type['name']) ?>
                                                </option>
                                            <?php endforeach; ?>
                                        </select>
                                    </div>

                                    <div class="col-12">
                                        <label class="form-label">Word *</label>
                                        <input type="text" class="form-control fw-bold" name="original_word" 
                                            value="<?= htmlspecialchars($word['original_word'] ?? '') ?>" required>
                                    </div>

                                    <div class="col-12">
                                        <label class="form-label">Meaning *</label>
                                        <textarea class="form-control" name="original_meaning" rows="3" required><?= htmlspecialchars($word['original_meaning'] ?? '') ?></textarea>
                                    </div>
                                    
                                    <div class="col-12">
                                        <label class="form-label">Example Sentence</label>
                                        <textarea class="form-control" name="original_example" rows="3"><?= htmlspecialchars($word['original_example'] ?? '') ?></textarea>
                                    </div>

                                    <div class="col-md-6">
                                        <label class="form-label">Status *</label>
                                        <select class="form-select" name="status" required>
                                            <option value="published" <?= $word['status'] == 'published' ? 'selected' : '' ?>>Published</option>
                                            <option value="draft" <?= $word['status'] == 'draft' ? 'selected' : '' ?>>Draft</option>
                                        </select>
                                    </div>

                                    <div class="col-md-6">
                                        <label class="form-label">Word Image</label>
                                        <input class="form-control" type="file" name="word_image" accept="image/*">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="card h-100 border-success-subtle">
                            <div class="card-header bg-success-subtle">
                                <h6 class="mb-0 text-success">Translation (English)</h6>
                            </div>
                            <div class="card-body">
                                <div class="row g-3"> 
                                    <div class="col-12">
                                        <label for="translation_language" class="form-label">Target Language *</label>
                                        <select class="form-select searchSelect" id="translation_language" name="translation_language" required>
                                            <option value="">Select target language</option>
                                            <?php foreach ($languages as $lang): ?>
                                                <option value="<?= htmlspecialchars($lang['language_code']) ?>"
                                                    <?= (isset($translation['language_code']) && $translation['language_code'] == $lang['language_code']) ? 'selected' : '' ?>>
                                                    <?= htmlspecialchars($lang['language_name']) ?> (<?= htmlspecialchars($lang['language_code']) ?>)
                                                </option>
                                            <?php endforeach; ?>
                                        </select>
                                        <div class="form-text">Choose the language for the translation fields below.</div>
                                    </div>

                                    <div class="col-12">
                                        <label class="form-label">Translated Word</label>
                                        <input type="text" class="form-control" name="translated_word" 
                                            value="<?= htmlspecialchars($translation['translated_word'] ?? '') ?>">
                                    </div>

                                    <div class="col-12">
                                        <label class="form-label">Translated Meaning</label>
                                        <textarea class="form-control" name="translated_meaning" rows="3"><?= htmlspecialchars($translation['translated_meaning'] ?? '') ?></textarea>
                                    </div>

                                    <div class="col-12">
                                        <label class="form-label">Translated Example</label>
                                        <textarea class="form-control" name="translated_example" rows="3"><?= htmlspecialchars($translation['translated_example'] ?? '') ?></textarea>
                                    </div>

                                    <div class="col-md-6">
                                        <label class="form-label">Translation Status</label>
                                        <select class="form-select" name="trans_status">
                                            <option value="published" <?= ($translation['status'] ?? '') == 'published' ? 'selected' : '' ?>>Published</option>
                                            <option value="draft" <?= ($translation['status'] ?? '') == 'draft' ? 'selected' : '' ?>>Draft</option>
                                        </select>
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <label class="form-label">Translation Audio</label>
                                        <input class="form-control" type="file" name="trans_pronunciation" accept="audio/*">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-primary update-word-submit-btn" id="updateWord">
                    <i class="fa fa-pencil-square me-2" aria-hidden="true"></i>Update Word
                </button>
            </div>
        </form>
    </div>
</div>