<?php

namespace Core\App\Controllers;

use Core\App\Models\FacebookPixelSettingModel;

class FacebookPixelController
{
    public function settings()
    {
        $model = new FacebookPixelSettingModel();

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

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

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

        (new FacebookPixelSettingModel())->save([
            'pixel_id' => $pixelId
        ], $isActive);

        header('Location: /admin/settings/facebook-pixel');
        exit;
    }
}
