<?php
/**
 * No-op field implementation (loaded only when Elementor Pro Field_Base exists).
 *
 * @package WP_PowerSuite\Captcha\Shared
 */

namespace WP_PowerSuite\Captcha\Shared;

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

/**
 * Placeholder for legacy `wpps_simple_captcha` form rows.
 */
class ElementorWppsScStubFieldType extends \ElementorPro\Modules\Forms\Fields\Field_Base {

	/**
	 * @return string
	 */
	public function get_type(): string {
		return 'wpps_simple_captcha';
	}

	/**
	 * @return string
	 */
	public function get_name(): string {
		return esc_html__( 'Simple CAPTCHA (inactive)', 'wp-powersuite' );
	}

	/**
	 * @return string[]
	 */
	public function get_script_depends(): array {
		return [];
	}

	/**
	 * @return string[]
	 */
	public function get_style_depends(): array {
		return [];
	}

	/**
	 * @param \Elementor\Widget_Base $widget Widget.
	 * @return void
	 */
	public function update_controls( $widget ): void {
		unset( $widget );
	}

	/**
	 * @param array<string, mixed>   $item
	 * @param int|string            $item_index
	 * @param \ElementorPro\Modules\Forms\Classes\Form $form
	 * @return void
	 */
	public function render( $item, $item_index, $form ): void {
		unset( $item, $item_index, $form );
		if ( $this->is_builder_panel() ) {
			echo '<div class="wpps-simple-captcha-stub" style="padding:10px 12px;border:1px dashed #c3c4c7;border-radius:4px;font-size:13px;">';
			echo esc_html__( 'This field is inactive (remove it or re-enable Simple CAPTCHA for Elementor).', 'wp-powersuite' );
			echo '</div>';
		}
	}

	/**
	 * @param mixed $field
	 * @param mixed $record
	 * @param mixed $ajax_handler
	 * @return void
	 */
	public function validation( $field, $record, $ajax_handler ): void {
		unset( $field, $record, $ajax_handler );
	}

	/**
	 * @return bool
	 */
	private function is_builder_panel(): bool {
		if ( ! class_exists( '\Elementor\Plugin' ) || ! isset( \Elementor\Plugin::$instance->editor ) ) {
			return false;
		}
		return (bool) \Elementor\Plugin::$instance->editor->is_edit_mode();
	}
}
