<?php

namespace DaftPlug\Generatify\Features\ContentModeration;

use DaftPlug\Generatify\Helpers\Utils;

if (!defined('ABSPATH')) {
  exit();
}

class CommentToxicity
{
  public function __construct()
  {
    add_action('wp_enqueue_scripts', [$this, 'loadCommentToxicityAssets']);
  }

  public function loadCommentToxicityAssets()
  {
    if (Utils::getSetting('aiToxicityChecker') !== 'on' || !is_single() || !comments_open()) {
      return;
    }

    Utils::enqueueTensorflow();
    $dependencies[] = 'generatify-tensorflow';

    // Load the Toxicity model
    wp_enqueue_script('generatify-toxicity', plugins_url('assets/js/vendor/toxicity.js', GENERATIFY_FILE), $dependencies, GENERATIFY_VERSION, true);
    $dependencies[] = 'generatify-toxicity';

    // Load Toxicity Checker script
    wp_enqueue_script('generatify-toxicity-checker', plugins_url('assets/js/toxicityChecker.js', GENERATIFY_FILE), $dependencies, GENERATIFY_VERSION, true);
  }
}