<?php
/**
 * GhostAction — an action that never runs but appears in the action picker
 * with a "Pro" badge and an upgrade prompt.
 *
 * Mirrors the GhostTrigger pattern: the class is registered in the free
 * build purely as an upgrade teaser. It exposes no editable fields, can
 * never be selected in the editor (the inserter intercepts the click and
 * shows the upgrade gate), and is rejected server-side by PlaySaveGuard if
 * a crafted request ever tries to persist it.
 *
 * Concrete ghost actions MUST use the same get_slug() value as their real
 * Pro counterpart, so that a store which later upgrades keeps any teased
 * action it eventually configures.
 *
 * @package CartCue\Actions
 */

namespace CartCue\Actions;

use CartCue\Context;
use CartCue\Plugin;

defined( 'ABSPATH' ) || exit;

abstract class GhostAction extends AbstractAction {

	/** Ghost actions are always Pro. */
	public function is_pro(): bool {
		return true;
	}

	/**
	 * Never selectable on free, so this should never execute. Implemented as a
	 * no-op safety net so a stray saved row can't fatal the WorkflowRunner.
	 */
	public function run( array $settings, Context $context ): void {
		// Intentionally empty — ghost actions exist only as upgrade teasers.
	}

	/** Ghost actions expose no editable fields. */
	public function get_settings_fields(): array {
		return [];
	}

	/** Tabler icon name shown in the action picker (e.g. "ti-message-2"). */
	abstract public function get_icon(): string;

	/** Short pitch shown inside the upgrade gate. */
	abstract protected function get_pro_description(): string;

	/**
	 * Upgrade CTA HTML rendered when this action is highlighted in the picker.
	 * Reuses the same .ap-pro-gate markup as GhostTrigger::get_upgrade_html().
	 */
	public function get_upgrade_html(): string {
		return sprintf(
			'<div class="ap-pro-gate">'
			. '<div class="ap-pro-gate__icon"><i class="ti ti-lock" aria-hidden="true"></i></div>'
			. '<div class="ap-pro-gate__title">%s</div>'
			. '<p class="ap-pro-gate__desc">%s</p>'
			. '<a href="' . esc_url( Plugin::upgrade_url( 'ghost_action_' . $this->get_slug() ) ) . '" target="_blank" rel="noopener noreferrer" class="ap-btn ap-btn-primary">%s &rarr;</a>'
			. '</div>',
			esc_html(
				sprintf(
					/* translators: %s: action label */
					__( 'Pro Action: %s', 'cartcue-sales-automation' ),
					$this->get_label()
				)
			),
			esc_html( $this->get_pro_description() ),
			esc_html__( 'Upgrade to CartCue Pro', 'cartcue-sales-automation' )
		);
	}
}
