<?php
declare(strict_types=1);

namespace WP_AUX\Entities\AuxCF\OptionsFields\Global;

use AuxCF\Entities\Field\TextFieldEntity;
use AuxCF\Entities\Settings\Enum\OperatorEnum;

/**
 * Google Analytics ID field in the AUX Site Settings page.
 * Code that loads the Google Analytics script is in inc/functions-html-head.php.
 * Validation options are documented in /inc/WP_AUX/Services/AuxCF/README_VALIDATION.md
 *
 * @since 1.0.0
 */
class GoogleAnalyticsFieldEntity extends TextFieldEntity
{
  public static string $name = 'aux_google_analytics_id';
  protected string $label = 'Google Analytics ID';
  protected string $instructions = '<a href="https://support.google.com/analytics/answer/9539598">How to find your Google Analytics ID</a>';
  protected string $placeholder = 'G-XXXXXXXXXX';
  protected array $validation = [
    'regex' => '/^G-[A-Za-z0-9]{10}$/',
    'custom_messages' => [
      'regex' => 'This value does not appear to be a valid Google Analytics ID.
                  The ID should be in the format G-XXXXXXXXXX (GA4).'
    ]
  ];

  protected array $initConditionalLogic = [
    [
      [ TrackingMethodFieldEntity::class, OperatorEnum::EQUALS, 'google_analytics' ]
    ],
  ];
}
