<?php include 'header.php'; ?>

<div class="container-fluid py-4">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card shadow-sm border-0">
                <div class="card-header bg-white py-3">
                    <h5 class="mb-0 fw-bold text-primary"><i class="fas fa-cog me-2"></i><?php echo __('general_settings'); ?></h5>
                </div>
                <div class="card-body p-4">
                    <form action="/admin/settings" method="POST" enctype="multipart/form-data">
                        <div class="mb-4">
                        <div class="mb-4">
                            <label class="form-label fw-semibold">Contact Email</label>
                            <input type="email" name="contact_email" class="form-control" value="<?php echo htmlspecialchars($settings['contact_email'] ?? ''); ?>" placeholder="support@yourdomain.com">
                        </div>
                            <label class="form-label fw-semibold"><?php echo __('site_name'); ?></label>
                            <input type="text" name="site_name" class="form-control form-control-lg" value="<?php echo htmlspecialchars($settings['site_name']); ?>" required>
                        </div>
                        
                        <div class="row mb-4">
                            <div class="col-md-6">
                                <label class="form-label fw-semibold"><?php echo __('site_icon'); ?></label>
                                <input type="file" name="site_icon_file" class="form-control" accept="image/*">
                                <?php if ($settings['site_icon']): ?>
                                    <div class="mt-2">
                                        <img src="/<?php echo $settings['site_icon']; ?>" alt="Icon" class="img-thumbnail" style="max-height: 50px;">
                                    </div>
                                <?php endif; ?>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-semibold"><?php echo __('site_favicon'); ?></label>
                                <input type="file" name="site_favicon_file" class="form-control" accept="image/*">
                                <?php if ($settings['site_favicon']): ?>
                                    <div class="mt-2">
                                        <img src="/<?php echo $settings['site_favicon']; ?>" alt="Favicon" class="img-thumbnail" style="max-height: 32px;">
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>

                        <div class="mb-4 p-3 bg-light rounded border">
                            <div class="form-check form-switch">
                                <input class="form-check-input" type="checkbox" name="maintenance_mode" value="1" id="maintenanceMode" <?php echo ($settings['maintenance_mode'] ?? '0') === '1' ? 'checked' : ''; ?>>
                                <label class="form-check-label fw-bold" for="maintenanceMode">
                                    <i class="fas fa-tools me-2 text-warning"></i>Maintenance Mode
                                </label>
                            </div>
                            <div class="form-text mt-1">When enabled, regular visitors will see a maintenance page. Admins can still access the site.</div>
                        </div>

                        <hr class="my-4">
                        <h5 class="fw-bold mb-3"><i class="fas fa-share-alt me-2"></i>Social Media Settings</h5>

                        <div class="row mb-3">
                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-semibold">Facebook URL</label>
                                <input type="url" name="facebook_url" class="form-control" value="<?php echo htmlspecialchars($settings['facebook_url'] ?? ''); ?>" placeholder="https://facebook.com/yourpage">
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-semibold">Twitter (X) URL</label>
                                <input type="url" name="twitter_url" class="form-control" value="<?php echo htmlspecialchars($settings['twitter_url'] ?? ''); ?>" placeholder="https://twitter.com/yourprofile">
                            </div>
                        </div>

                        <div class="row mb-3">
                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-semibold">Instagram URL</label>
                                <input type="url" name="instagram_url" class="form-control" value="<?php echo htmlspecialchars($settings['instagram_url'] ?? ''); ?>" placeholder="https://instagram.com/yourprofile">
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-semibold">GitHub URL</label>
                                <input type="url" name="github_url" class="form-control" value="<?php echo htmlspecialchars($settings['github_url'] ?? ''); ?>" placeholder="https://github.com/yourprofile">
                            </div>
                        </div>

                        <div class="row mb-3">
                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-semibold">Telegram URL</label>
                                <input type="url" name="telegram_url" class="form-control" value="<?php echo htmlspecialchars($settings['telegram_url'] ?? ''); ?>" placeholder="https://t.me/yourchannel">
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-semibold">WhatsApp URL</label>
                                <input type="url" name="whatsapp_url" class="form-control" value="<?php echo htmlspecialchars($settings['whatsapp_url'] ?? ''); ?>" placeholder="https://wa.me/yournumber">
                            </div>
                        </div>

                        <hr class="my-4">
                        <h5 class="fw-bold mb-3"><i class="fas fa-search me-2"></i>SEO Settings</h5>

                        <div class="mb-4">
                            <label class="form-label fw-semibold">Meta Description</label>
                            <textarea name="meta_description" class="form-control" rows="3"><?php echo htmlspecialchars($settings['meta_description'] ?? ''); ?></textarea>
                            <div class="form-text">Brief description of your site for search engines.</div>
                        </div>

                        <div class="mb-4">
                            <label class="form-label fw-semibold">Meta Keywords</label>
                            <input type="text" name="meta_keywords" class="form-control" value="<?php echo htmlspecialchars($settings['meta_keywords'] ?? ''); ?>">
                            <div class="form-text">Comma separated keywords (e.g. apk, games, mod).</div>
                        </div>

                        <hr class="my-4">
                        <h5 class="fw-bold mb-3"><i class="fas fa-code me-2"></i>Custom Scripts & Ads</h5>

                        <div class="mb-4">
                            <label class="form-label fw-semibold">Head JS (Ads/Analytics)</label>
                            <textarea name="head_js" class="form-control" rows="5" placeholder="<script>...</script>"><?php echo htmlspecialchars($settings['head_js'] ?? ''); ?></textarea>
                            <div class="form-text">Injected before &lt;/head&gt;.</div>
                        </div>

                        <div class="mb-4">
                            <label class="form-label fw-semibold">Body JS (Ads/Analytics)</label>
                            <textarea name="body_js" class="form-control" rows="5" placeholder="<script>...</script>"><?php echo htmlspecialchars($settings['body_js'] ?? ''); ?></textarea>
                            <div class="form-text">Injected before &lt;/body&gt;.</div>
                        </div>

                        <div class="d-grid mt-4">
                            <button type="submit" class="btn btn-primary btn-lg py-3 fw-bold">
                                <i class="fas fa-save me-2"></i><?php echo __('save_settings'); ?>
                            </button>
                        </div>
                    </form>
                </div>
            </div>

            <div class="card shadow-sm border-0 mt-4">
                <div class="card-header bg-white py-3">
                    <h5 class="mb-0 fw-bold text-primary"><i class="fas fa-language me-2"></i><?php echo __('select_language'); ?></h5>
                </div>
                <div class="card-body p-4 text-center">
                    <div class="btn-group w-100" role="group">
                        <a href="/lang/id" class="btn btn-outline-primary py-3 fw-bold <?php echo \App\Services\LanguageService::getLang() == 'id' ? 'active' : ''; ?>">
                            🇮🇩 <?php echo __('language_indonesia'); ?>
                        </a>
                        <a href="/lang/en" class="btn btn-outline-primary py-3 fw-bold <?php echo \App\Services\LanguageService::getLang() == 'en' ? 'active' : ''; ?>">
                            🇺🇸 <?php echo __('language_english'); ?>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include 'footer.php'; ?>
