<?php

namespace Core\App\Controllers;

use Core\App\Models\GtmSettingModel;

class GtmController
{
    public function settings()
    {
        $model = new GtmSettingModel();

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

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

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

        (new GtmSettingModel())->save([
            'container_id' => $containerId
        ], $isActive);

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