<?php

// Filigran sınıfını dahil ediyoruz
require_once __DIR__ . '/../Core/ImageUploader.php';

class AdminController extends Controller {

    public function __construct() {
        if (session_status() == PHP_SESSION_NONE) {
            session_start();
        }

        $url = $_GET['url'] ?? '';
        if ($url != 'admin/login' && !isset($_SESSION['admin_id'])) {
            header('Location: ' . BASE_URL . '/admin/login');
            exit;
        }
    }

    private function checkAdmin() {
        if (!isset($_SESSION['admin_id'])) {
            header('Location: ' . BASE_URL . '/admin/login');
            exit;
        }
    }

    private function requireAdminRole() {
        if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
            header('Location: ' . BASE_URL . '/admin/dashboard');
            exit;
        }
    }

    public function index() {
        $this->dashboard();
    }

    // GİRİŞ İŞLEMİ
    public function login() {
        if (isset($_SESSION['admin_id'])) {
            header('Location: ' . BASE_URL . '/admin/dashboard');
            exit;
        }

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $email = trim($_POST['email']);
            $password = trim($_POST['password']);

            $userModel = $this->model('User');
            $loggedInUser = $userModel->login($email, $password);

            if ($loggedInUser) {
                $_SESSION['admin_id'] = $loggedInUser->id;
                $_SESSION['admin_email'] = $loggedInUser->email;
                $_SESSION['admin_name'] = $loggedInUser->name;
                $_SESSION['role'] = $loggedInUser->role;

                header('Location: ' . BASE_URL . '/admin/dashboard');
                exit;
            } else {
                $this->view('admin/login', ['error' => 'Hatalı e-posta veya şifre!']);
            }
        } else {
            $this->view('admin/login');
        }
    }

    public function logout() {
        session_destroy();
        header('Location: ' . BASE_URL . '/admin/login');
        exit;
    }

    // DASHBOARD
    public function dashboard() {
        $this->checkAdmin();

        $propertyModel = $this->model('Property');
        $messageModel = $this->model('Message');
        $userModel = $this->model('User');

        $stats = [];
        $latest_properties = [];
        $latest_messages = [];

        if (isset($_SESSION['role']) && $_SESSION['role'] == 'admin') {
            $allProps = $propertyModel->getAllProperties();
            $allMsgs = $messageModel->getAllMessagesWithProperty();

            $stats['total_properties'] = count($allProps);
            $stats['unread_messages'] = $messageModel->getUnreadCount();
            $stats['total_agents'] = count($userModel->getAllConsultants());
            $stats['monthly_views'] = '12.5K';

            $latest_properties = array_slice($allProps, 0, 5);
            $latest_messages = array_slice($allMsgs, 0, 5);
        } else {
            $myProps = $propertyModel->getPropertiesByUser($_SESSION['admin_id']);
            $myMsgs = $messageModel->getMessagesByUserId($_SESSION['admin_id']);

            $stats['total_properties'] = count($myProps);
            $stats['unread_messages'] = $messageModel->getUnreadCountByUser($_SESSION['admin_id']);
            $stats['total_agents'] = 1;
            $stats['monthly_views'] = '-';

            $latest_properties = array_slice($myProps, 0, 5);
            $latest_messages = array_slice($myMsgs, 0, 5);
        }

        $this->view('admin/layouts/main', [
            'title' => 'Dashboard',
            'active' => 'dashboard',
            'viewContent' => '../app/Views/admin/dashboard.php',
            'stats' => $stats,
            'latest_properties' => $latest_properties,
            'latest_messages' => $latest_messages
        ]);
    }

    // İLANLAR
    public function properties() {
        $this->checkAdmin();
        $propertyModel = $this->model('Property');

        if (isset($_SESSION['role']) && $_SESSION['role'] == 'admin') {
            $properties = $propertyModel->getAllProperties();
        } else {
            $properties = $propertyModel->getPropertiesByUser($_SESSION['admin_id']);
        }

        $this->view('admin/layouts/main', [
            'title' => 'İlan Yönetimi',
            'active' => 'properties',
            'viewContent' => '../app/Views/admin/properties.php',
            'properties' => $properties
        ]);
    }

    public function property_add() {
        $this->checkAdmin();

        global $db;
        require_once __DIR__ . '/../Models/CategoryModel.php';
        $catModel = new CategoryModel($db);
        $categories = $catModel->getAll();

        $this->view('admin/layouts/main', [
            'title' => 'Yeni İlan Ekle',
            'active' => 'properties',
            'viewContent' => '../app/Views/admin/property-add.php',
            'categories' => $categories
        ]);
    }

    public function property_save() {
        $this->checkAdmin();

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $_POST['title']))) . '-' . time();

            $data = [
                'user_id' => $_SESSION['admin_id'],
                'title' => $_POST['title'],
                'slug' => $slug,
                'price' => $_POST['price'],
                'type' => $_POST['type'],
                'category' => $_POST['category'] ?? null,
                'location' => $_POST['location'],
                'description' => $_POST['description'],
                'features' => json_encode($_POST['features']),
                'status' => ((isset($_SESSION['role']) && $_SESSION['role'] === 'admin') ? 'approved' : 'pending'),
                'approved_by' => ((isset($_SESSION['role']) && $_SESSION['role'] === 'admin') ? $_SESSION['admin_id'] : null),
                'approved_at' => ((isset($_SESSION['role']) && $_SESSION['role'] === 'admin') ? date('Y-m-d H:i:s') : null)
            ];

            $propertyModel = $this->model('Property');
            $property_id = $propertyModel->addProperty($data);

            if ($property_id) {
                if (isset($_FILES['images'])) {
                    $fileCount = count($_FILES['images']['name']);
                    $watermarkText = defined('SITENAME') ? SITENAME : 'EMLAK KONUT';

                    for ($i = 0; $i < $fileCount; $i++) {
                        if ($_FILES['images']['error'][$i] == 0) {
                            $targetDir = "../public/assets/uploads/";
                            if (!file_exists($targetDir)) mkdir($targetDir, 0777, true);

                            $fileData = [
                                'name' => $_FILES['images']['name'][$i],
                                'tmp_name' => $_FILES['images']['tmp_name'][$i]
                            ];

                            $dbPath = ImageUploader::uploadAndWatermark($fileData, $targetDir, $watermarkText);

                            if ($dbPath) {
                                $is_cover = ($i == 0) ? 1 : 0;
                                $propertyModel->addPropertyImage($property_id, $dbPath, $is_cover);

                                if ($i == 0) {
                                    $propertyModel->updateCoverImage($property_id, $dbPath);
                                }
                            }
                        }
                    }
                }

                header('Location: ' . BASE_URL . '/admin/properties?success=1');
                exit;
            } else {
                die("İlan veritabanına kaydedilemedi.");
            }
        }
    }

    public function property_edit($id) {
        $this->checkAdmin();
        $propertyModel = $this->model('Property');

        $property = $propertyModel->getPropertyById($id);
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $_POST['title']))) . '-' . time();

            $data = [
                'id' => $id,
                'title' => $_POST['title'],
                'slug' => $slug,
                'price' => $_POST['price'],
                'type' => $_POST['type'],
                'category' => $_POST['category'] ?? ($property->category ?? null),
                'location' => $_POST['location'],
                'description' => $_POST['description'],
                'features' => json_encode($_POST['features'])
            ];

            if ($propertyModel->updateProperty($data)) {
                if (isset($_FILES['images'])) {
                    $fileCount = count($_FILES['images']['name']);
                    $watermarkText = defined('SITENAME') ? SITENAME : 'EMLAK KONUT';

                    for ($i = 0; $i < $fileCount; $i++) {
                        if ($_FILES['images']['error'][$i] == 0) {
                            $targetDir = "../public/assets/uploads/";
                            if (!file_exists($targetDir)) mkdir($targetDir, 0777, true);

                            $fileData = [
                                'name' => $_FILES['images']['name'][$i],
                                'tmp_name' => $_FILES['images']['tmp_name'][$i]
                            ];

                            $dbPath = ImageUploader::uploadAndWatermark($fileData, $targetDir, $watermarkText);

                            if ($dbPath) {
                                $propertyModel->addPropertyImage($id, $dbPath, 0);
                            }
                        }
                    }
                }
                header('Location: ' . BASE_URL . '/admin/properties?updated=1');
                exit;
            } else {
                die("Güncelleme hatası.");
            }

        } else {
        $property = $propertyModel->getPropertyById($id);
            $images = $propertyModel->getPropertyImages($id);

            $this->view('admin/layouts/main', [
                'title' => 'İlanı Düzenle',
                'active' => 'properties',
                'viewContent' => '../app/Views/admin/property-edit.php',
                'property' => $property,
                'images' => $images
            ]);
        }
    }

    public function property_delete($id) {
        $this->checkAdmin();
        $propertyModel = $this->model('Property');

        $images = $propertyModel->getPropertyImages($id);
        foreach ($images as $img) {
            $filePath = '../public/' . $img->image_path;
            if (file_exists($filePath)) {
                unlink($filePath);
            }
        }

        $property = $propertyModel->getPropertyById($id);
        if ($property && !empty($property->image)) {
            $coverPath = '../public/' . $property->image;
            if (file_exists($coverPath)) {
                unlink($coverPath);
            }
        }

        if ($propertyModel->deleteProperty($id)) {
            header('Location: ' . BASE_URL . '/admin/properties?deleted=1');
            exit;
        } else {
            die("Silme hatası.");
        }
    }

    public function image_delete($img_id, $prop_id) {
        $this->checkAdmin();
        $propertyModel = $this->model('Property');

        $image = $propertyModel->getImageById($img_id);
        if ($image) {
            $filePath = '../public/' . $image->image_path;
            if (file_exists($filePath)) {
                unlink($filePath);
            }
            $propertyModel->deleteImageById($img_id);
        }

        header('Location: ' . BASE_URL . '/admin/property-edit/' . $prop_id);
        exit;
    }

    public function property_approve($id) {
        $this->checkAdmin();
        $this->requireAdminRole();
        $propertyModel = $this->model('Property');
        $propertyModel->updateStatus($id, 'approved', $_SESSION['admin_id']);
        header('Location: ' . BASE_URL . '/admin/properties?approved=1');
        exit;
    }

    public function property_reject($id) {
        $this->checkAdmin();
        $this->requireAdminRole();
        $propertyModel = $this->model('Property');
        $propertyModel->updateStatus($id, 'rejected', $_SESSION['admin_id']);
        header('Location: ' . BASE_URL . '/admin/properties?rejected=1');
        exit;
    }

    public function property_import() {
        $this->checkAdmin();
        $this->requireAdminRole();
        $this->view('admin/layouts/main', [
            'title' => 'CSV İçe Aktarma',
            'active' => 'properties',
            'viewContent' => '../app/Views/admin/property-import.php'
        ]);
    }

    public function property_import_save() {
        $this->checkAdmin();
        $this->requireAdminRole();

        if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['csv_file'])) {
            $tmp = $_FILES['csv_file']['tmp_name'];
            if (!file_exists($tmp)) {
                header('Location: ' . BASE_URL . '/admin/property-import?error=1');
                exit;
            }

            $handle = fopen($tmp, 'r');
            $firstLine = fgets($handle);
            $delimiter = (substr_count($firstLine, ';') > substr_count($firstLine, ',')) ? ';' : ',';
            rewind($handle);

            $header = fgetcsv($handle, 0, $delimiter);
            if (!$header) {
                fclose($handle);
                header('Location: ' . BASE_URL . '/admin/property-import?error=1');
                exit;
            }

            $header = array_map(fn($h) => strtolower(trim($h)), $header);

            $propertyModel = $this->model('Property');
            $inserted = 0;
            $skipped = 0;

            while (($row = fgetcsv($handle, 0, $delimiter)) !== false) {
                if (count($row) != count($header)) {
                    $skipped++;
                    continue;
                }

                $rowData = array_combine($header, $row);
                $title = trim($rowData['title'] ?? '');
                if ($title === '') {
                    $skipped++;
                    continue;
                }

                $slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $title))) . '-' . time() . '-' . rand(100, 999);
                $features = $rowData['features_json'] ?? '';
                if ($features && json_decode($features) === null) {
                    $features = '';
                }

                if (!$features) {
                    $featArr = [];
                    foreach (['oda', 'banyo', 'm2', 'yas'] as $k) {
                        if (!empty($rowData[$k])) {
                            $featArr[$k] = $rowData[$k];
                        }
                    }
                    $features = json_encode($featArr);
                }

                $data = [
                    'user_id' => $_SESSION['admin_id'],
                    'title' => $title,
                    'slug' => $slug,
                    'price' => $rowData['price'] ?? 0,
                    'type' => $rowData['type'] ?? '',
                    'category' => $rowData['category'] ?? null,
                    'location' => $rowData['location'] ?? '',
                    'description' => $rowData['description'] ?? '',
                    'features' => $features,
                    'status' => 'approved',
                    'approved_by' => $_SESSION['admin_id'],
                    'approved_at' => date('Y-m-d H:i:s')
                ];

                if ($propertyModel->addProperty($data)) {
                    $inserted++;
                } else {
                    $skipped++;
                }
            }

            fclose($handle);
            header('Location: ' . BASE_URL . '/admin/property-import?imported=' . $inserted . '&skipped=' . $skipped);
            exit;
        }

        header('Location: ' . BASE_URL . '/admin/property-import?error=1');
        exit;
    }

    // MESAJLAR
    public function messages() {
        $this->checkAdmin();
        $messageModel = $this->model('Message');

        if (isset($_SESSION['role']) && $_SESSION['role'] == 'admin') {
            $messages = $messageModel->getAllMessagesWithProperty();
        } else {
            $messages = $messageModel->getMessagesByUserId($_SESSION['admin_id']);
        }

        $this->view('admin/layouts/main', [
            'title' => 'Mesaj Kutusu',
            'active' => 'messages',
            'viewContent' => '../app/Views/admin/messages.php',
            'messages' => $messages
        ]);
    }

    public function message_update($id) {
        $this->checkAdmin();
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $tag = trim($_POST['tag'] ?? '');
            $note = trim($_POST['note'] ?? '');
            $messageModel = $this->model('Message');
            $messageModel->updateTagNote($id, $tag, $note);
        }
        header('Location: ' . BASE_URL . '/admin/messages');
        exit;
    }

    // PROJELER
    public function projects() {
        $this->checkAdmin();
        global $db;
        require_once __DIR__ . '/../Models/ProjectModel.php';
        $model = new ProjectModel($db);

        $projects = $model->getAll();
        if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
            $projects = array_values(array_filter($projects, fn($p) => (int)$p->user_id === (int)$_SESSION['admin_id']));
        }

        $this->view('admin/layouts/main', [
            'title' => 'Proje Yönetimi',
            'active' => 'projects',
            'projects' => $projects,
            'viewContent' => '../app/Views/admin/projects.php'
        ]);
    }

    public function project_add() {
        $this->checkAdmin();
        $this->view('admin/layouts/main', [
            'title' => 'Yeni Proje Ekle',
            'active' => 'projects',
            'viewContent' => '../app/Views/admin/project-add.php'
        ]);
    }

    public function project_save() {
        $this->checkAdmin();
        global $db;
        require_once __DIR__ . '/../Models/ProjectModel.php';
        $model = new ProjectModel($db);

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $imagePath = '';
            if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) {
                $uploadDir = '../public/assets/uploads/projects/';
                if (!file_exists($uploadDir)) { mkdir($uploadDir, 0777, true); }

                $fileName = time() . '_' . basename($_FILES['image']['name']);
                $targetPath = $uploadDir . $fileName;
                move_uploaded_file($_FILES['image']['tmp_name'], $targetPath);
                $imagePath = 'assets/uploads/projects/' . $fileName;
            }

            $slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $_POST['title'])));

            $data = [
                'user_id' => $_SESSION['admin_id'],
                'title' => $_POST['title'],
                'slug' => $slug,
                'description' => $_POST['description'],
                'location' => $_POST['location'],
                'status' => $_POST['status'],
                'type' => $_POST['type'],
                'delivery_date' => $_POST['delivery_date'],
                'image' => $imagePath
            ];

            if ($model->add($data)) {
                header('Location: ' . BASE_URL . '/admin/projects?success=1');
                exit;
            }
        }
    }

    public function project_edit($id) {
        $this->checkAdmin();
        global $db;
        require_once __DIR__ . '/../Models/ProjectModel.php';
        $model = new ProjectModel($db);
        $project = $model->getById($id);

        $this->view('admin/layouts/main', [
            'title' => 'Projeyi Düzenle',
            'active' => 'projects',
            'project' => $project,
            'viewContent' => '../app/Views/admin/project-edit.php'
        ]);
    }

    public function project_edit_save($id) {
        $this->checkAdmin();
        global $db;
        require_once __DIR__ . '/../Models/ProjectModel.php';
        $model = new ProjectModel($db);

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $data = [
                'title' => $_POST['title'],
                'slug' => strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $_POST['title']))),
                'description' => $_POST['description'],
                'location' => $_POST['location'],
                'status' => $_POST['status'],
                'type' => $_POST['type'],
                'delivery_date' => $_POST['delivery_date']
            ];

            if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) {
                $uploadDir = '../public/assets/uploads/projects/';
                if (!file_exists($uploadDir)) { mkdir($uploadDir, 0777, true); }

                $fileName = time() . '_' . basename($_FILES['image']['name']);
                $targetPath = $uploadDir . $fileName;
                move_uploaded_file($_FILES['image']['tmp_name'], $targetPath);
                $data['image'] = 'assets/uploads/projects/' . $fileName;
            }

            if ($model->update($id, $data)) {
                header('Location: ' . BASE_URL . '/admin/project-edit/' . $id . '?success=1');
                exit;
            }
        }
    }

    public function project_delete($id) {
        $this->checkAdmin();
        global $db;
        require_once __DIR__ . '/../Models/ProjectModel.php';
        $model = new ProjectModel($db);
        $model->delete($id);
        header('Location: ' . BASE_URL . '/admin/projects?deleted=1');
        exit;
    }

    // KATEGORİLER
    public function categories() {
        $this->checkAdmin();
        $this->requireAdminRole();

        global $db;
        require_once __DIR__ . '/../Models/CategoryModel.php';
        $catModel = new CategoryModel($db);
        $categories = $catModel->getAll();

        $this->view('admin/layouts/main', [
            'title' => 'Kategori Yönetimi',
            'active' => 'categories',
            'viewContent' => '../app/Views/admin/categories.php',
            'categories' => $categories
        ]);
    }

    public function category_add() {
        $this->checkAdmin();
        $this->requireAdminRole();
        global $db;
        require_once __DIR__ . '/../Models/CategoryModel.php';
        $catModel = new CategoryModel($db);
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $catModel->add($_POST['name']);
        }
        header('Location: ' . BASE_URL . '/admin/categories');
        exit;
    }

    public function category_delete($id) {
        $this->checkAdmin();
        $this->requireAdminRole();
        global $db;
        require_once __DIR__ . '/../Models/CategoryModel.php';
        $catModel = new CategoryModel($db);
        $catModel->delete($id);
        header('Location: ' . BASE_URL . '/admin/categories');
        exit;
    }

    // KULLANICILAR
    public function users() {
        $this->checkAdmin();
        $this->requireAdminRole();

        $userModel = $this->model('User');
        $users = $userModel->getAllConsultants();

        $this->view('admin/layouts/main', [
            'title' => 'Danışman Yönetimi',
            'active' => 'users',
            'viewContent' => '../app/Views/admin/users.php',
            'users' => $users
        ]);
    }

    public function user_add() {
    $this->checkAdmin();
    $this->requireAdminRole();

    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $data = [
            'name' => trim($_POST['name']),
            'email' => trim($_POST['email']),
            // Ham şifreyi hashleyerek güvenli hale getiriyoruz
            'password' => password_hash($_POST['password'], PASSWORD_DEFAULT), 
            'phone' => trim($_POST['phone'])
        ];

        $userModel = $this->model('User');
        $userModel->addUser($data);
    }

    header('Location: ' . BASE_URL . '/admin/users');
    exit;
}

    public function user_delete($id) {
        $this->checkAdmin();
        $this->requireAdminRole();
        $userModel = $this->model('User');
        $userModel->deleteUser($id);
        header('Location: ' . BASE_URL . '/admin/users');
        exit;
    }

    // AYARLAR
    public function settings() {
        $this->checkAdmin();
        $this->requireAdminRole();
        $settingModel = $this->model('Setting');

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $data = [
                'site_title' => $_POST['site_title'] ?? '',
                'phone' => $_POST['phone'] ?? '',
                'email' => $_POST['email'] ?? '',
                'address' => $_POST['address'] ?? '',
                'about_text' => $_POST['about_text'] ?? '',
                'about_subtitle' => $_POST['about_subtitle'] ?? '',
                'about_heading' => $_POST['about_heading'] ?? '',
                'stat_years' => $_POST['stat_years'] ?? '',
                'stat_customers' => $_POST['stat_customers'] ?? '',
                'stat_sales' => $_POST['stat_sales'] ?? '',
                'stat_awards' => $_POST['stat_awards'] ?? '',
                'facebook' => $_POST['facebook'] ?? '',
                'instagram' => $_POST['instagram'] ?? '',
                'twitter' => $_POST['twitter'] ?? '',
                'adv1_title' => $_POST['adv1_title'] ?? '',
                'adv1_text' => $_POST['adv1_text'] ?? '',
                'adv2_title' => $_POST['adv2_title'] ?? '',
                'adv2_text' => $_POST['adv2_text'] ?? '',
                'adv3_title' => $_POST['adv3_title'] ?? '',
                'adv3_text' => $_POST['adv3_text'] ?? ''
            ];

            $settingModel->updateSettings($data);

            if (isset($_FILES['site_logo']) && $_FILES['site_logo']['error'] == 0) {
                $uploadDir = '../public/assets/uploads/';
                if (!file_exists($uploadDir)) { mkdir($uploadDir, 0777, true); }

                $fileName = time() . '_' . basename($_FILES['site_logo']['name']);
                $targetPath = $uploadDir . $fileName;
                move_uploaded_file($_FILES['site_logo']['tmp_name'], $targetPath);
                $settingModel->updateLogo('assets/uploads/' . $fileName);
            }

            header('Location: ' . BASE_URL . '/admin/settings?success=1');
            exit;
        }

        $settings = $settingModel->getSettings();
        $this->view('admin/layouts/main', [
            'title' => 'Site Ayarları',
            'active' => 'settings',
            'viewContent' => '../app/Views/admin/settings.php',
            'settings' => $settings
        ]);
    }

    public function profile() {
    $this->checkAdmin();
    
    // 1. Modelin doğru yüklendiğinden emin olalım
    $userModel = $this->model('User');
    if (!$userModel) {
        die("Hata: User modeli yüklenemedi.");
    }

    // 2. Kullanıcı verisinin geldiğinden emin olalım
    $user = $userModel->getUserById($_SESSION['admin_id']);
    if (!$user) {
        die("Hata: Oturumdaki ID (#".$_SESSION['admin_id'].") ile kullanıcı bulunamadı.");
    }

    // 3. Dosya yolunu mutlak yol (absolute path) olarak tanımlayalım (Beyaz ekranın asıl çözümü)
    $viewPath = dirname(__DIR__) . '/Views/admin/profile.php';

    // 4. Dosya gerçekten orada mı kontrol edelim
    if (!file_exists($viewPath)) {
        die("Hata: Görünüm dosyası bulunamadı! Aranan konum: " . $viewPath);
    }

    $this->view('admin/layouts/main', [
        'title' => 'Profil Ayarlarım',
        'active' => 'profile',
        'viewContent' => $viewPath,
        'user' => $user
    ]);
}
}



