<?php
include '../includes/auth.php';
include '../includes/db.php';

$footer = $conn->query("SELECT * FROM footer_info WHERE element_name='footer'")->fetch_assoc();

if($_SERVER['REQUEST_METHOD'] == 'POST') {
    $address = $_POST['address'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $map_url = $_POST['map_embed_url'];
    $facebook = $_POST['facebook'];
    $twitter = $_POST['twitter'];
    $linkedin = $_POST['linkedin'];
    $instagram = $_POST['instagram'];
    $content = $_POST['content'];

    $sql = "UPDATE footer_info SET 
            address='$address',
            phone='$phone',
            email='$email',
            map_embed_url='$map_url',
            facebook='$facebook',
            twitter='$twitter',
            linkedin='$linkedin',
            instagram='$instagram',
            content='$content'
            WHERE element_name='footer'";

    if($conn->query($sql)) {
        $message = "✅ Footer updated successfully!";
    } else {
        $message = "❌ Error: ".$conn->error;
    }
}
?>

<h2>Edit Footer</h2>
<?php if(!empty($message)) echo "<p style='color:green;'>$message</p>"; ?>

<form method="post">
    <label>Address:</label><br>
    <input type="text" name="address" value="<?php echo $footer['address']; ?>" style="width:80%;"><br><br>

    <label>Phone:</label><br>
    <input type="text" name="phone" value="<?php echo $footer['phone']; ?>"><br><br>

    <label>Email:</label><br>
    <input type="email" name="email" value="<?php echo $footer['email']; ?>"><br><br>

    <label>Google Map Embed URL:</label><br>
    <input type="text" name="map_embed_url" value="<?php echo $footer['map_embed_url']; ?>" style="width:80%;"><br><br>

    <label>Facebook URL:</label><br>
    <input type="text" name="facebook" value="<?php echo $footer['facebook']; ?>"><br><br>

    <label>Twitter URL:</label><br>
    <input type="text" name="twitter" value="<?php echo $footer['twitter']; ?>"><br><br>

    <label>LinkedIn URL:</label><br>
    <input type="text" name="linkedin" value="<?php echo $footer['linkedin']; ?>"><br><br>

    <label>Instagram URL:</label><br>
    <input type="text" name="instagram" value="<?php echo $footer['instagram']; ?>"><br><br>

    <label>Additional HTML Content:</label><br>
    <textarea name="content" rows="5" cols="80"><?php echo htmlspecialchars($footer['content']); ?></textarea><br><br>

    <button type="submit">💾 Update Footer</button>
</form>


<style>
@import url('https://fonts.googleapis.com/css2?family=Vazir&display=swap');

body {
  font-family: 'Vazir', sans-serif;
  background: #f4f7fb;
  color: #333;
  margin: 0;
  padding: 0;
}

h2 {
  text-align: center;
  color: #1a237e;
  margin-top: 30px;
  font-size: 28px;
}

form {
  background: #fff;
  max-width: 900px;
  margin: 30px auto;
  padding: 40px 50px;
  border-radius: 20px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.1);
  direction: rtl;
}

label {
  font-weight: bold;
  color: #1a237e;
  display: block;
  margin-bottom: 8px;
}

input[type="text"],
input[type="file"],
textarea {
  width: 100%;
  padding: 10px 15px;
  margin-bottom: 20px;
  border: 1px solid #ccd1e4;
  border-radius: 10px;
  font-size: 15px;
  transition: 0.2s;
}

input:focus,
textarea:focus {
  border-color: #1a73e8;
  box-shadow: 0 0 5px rgba(26, 115, 232, 0.3);
  outline: none;
}

button {
  background: linear-gradient(90deg, #1a73e8, #0c47b7);
  color: #fff;
  border: none;
  padding: 14px 35px;
  border-radius: 30px;
  font-size: 16px;
  cursor: pointer;
  transition: 0.3s;
}

button:hover {
  background: linear-gradient(90deg, #0c47b7, #1a237e);
}

.alert {
  max-width: 900px;
  margin: 20px auto;
  padding: 15px 25px;
  border-radius: 10px;
  text-align: center;
  font-weight: bold;
}

.alert.success {
  background: #d7ffd9;
  color: #1b5e20;
  border: 1px solid #81c784;
}

.alert.error {
  background: #ffe0e0;
  color: #b71c1c;
  border: 1px solid #ef9a9a;
}

img {
  display: block;
  margin-top: 10px;
  border-radius: 15px;
  max-width: 250px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
</style>