<?php
declare(strict_types=1);

namespace WP_AUX\Entities\AuxCF\OptionsFields\Global;

use AuxCF\Entities\Field\TextFieldEntity;
use AuxCF\Entities\Settings\Enum\OperatorEnum;
use WP_AUX\Entities\AuxCF\OptionsFields\Global\TrackingMethodFieldEntity;

/**
 * Google Tag Manager ID field in the AUX Site Settings page.
 * Code that loads the Google Tag Manager 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 GtmFieldEntity extends TextFieldEntity
{
  public static string $name = 'aux_gtm_id';
  protected string $label = 'Google Tag Manager (GTM) ID';
  protected string $instructions = 'Google Tag Manager is a more advanced option that allows you to load Google Analytics
                                    and other analytics tools, track events and conversions and more. Tag Manager requires
                                    more time and technical knowledge to set up. Misconfiguration can result in tracking
                                    errors, security issues and performance problems.<br/>
                                    <a href="https://support.google.com/tagmanager/answer/15107467">How to find your GTM ID</a>';
  protected string $placeholder = 'GTM-XXXXXXX';
  protected array $validation = [
    'regex' => '/^GTM-[A-Za-z0-9]{6,10}$/',
    'custom_messages' => [
      'regex' => 'This value does not appear to be a valid Google Tag Manager ID.
                  The ID should be in the format GTM-XXXXXXX.'
    ]
  ];

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