<?php

namespace Core\App\Controllers;

use Core\App\Models\TikTokPixelSettingModel;

class TikTokPixelController
{
    public function settings()
    {
        $model = new TikTokPixelSettingModel();

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

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

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

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

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