<?php
include 'db.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $site_title = $_POST['site_title'];
    $slider_title_size = $_POST['slider_title_size'];
    $main_color = $_POST['main_color'];
    $news_title = $_POST['news_title'];
    $news_content = $_POST['news_content'];
    $contact_email = $_POST['contact_email'];

    // معالجة صورة السلايدر
    $hero_image = $settings['hero_image']; // القيمة الافتراضية
    if (isset($_FILES['hero_image']) && $_FILES['hero_image']['error'] == 0) {
        $path = "images/hero_" . time() . ".jpg";
        move_uploaded_file($_FILES['hero_image']['tmp_name'], $path);
        $hero_image = $path;
    }

    $sql = "UPDATE site_config SET 
            site_title = ?, 
            slider_title_size = ?, 
            main_color = ?, 
            news_title = ?, 
            news_content = ?, 
            contact_email = ?, 
            hero_image = ? 
            WHERE id = 1";

    $stmt = $conn->prepare($sql);
    $stmt->execute([$site_title, $slider_title_size, $main_color, $news_title, $news_content, $contact_email, $hero_image]);

    header("Location: admin_home_editor.php?status=success");
}