<?php

namespace Core\App\Controllers;

use Core\App\Models\Ga4SettingModel;

class Ga4Controller
{
    public function settings()
    {
        $model = new Ga4SettingModel();

        $ga4 = $model->get() ?: [
            'measurement_id' => '',
            'is_active'      => 0,
        ];

       require ROOT_PATH . '/admin/templates/settings/ga4.php';
    }

    public function save()
    {
        $measurementId = trim($_POST['measurement_id'] ?? '');
        $isActive      = isset($_POST['is_active']) ? 1 : 0;

        (new Ga4SettingModel())->save([
            'measurement_id' => $measurementId
        ], $isActive);

        header('Location: /admin/settings/ga4');
        exit;
    }
}
