<?php
/**
 * Pro Widget Placeholders — Free Edition
 *
 * Registers "locked" Pro widgets that appear in the Elementor panel under the
 * "User Directory" category. When a Free user drags one onto the canvas they
 * see a premium upgrade card instead of an empty/broken widget.
 *
 * Each placeholder widget:
 *  - Has a 🔒 badge in the panel icon area (via CSS).
 *  - Renders an upgrade card on the canvas with [See Demo] and [Upgrade] CTAs.
 *  - Never outputs any real frontend HTML (returns early on non-editor requests).
 *
 * @package UM_Elementor_Free
 * @since   2.7
 */

namespace UM_Elementor;

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

// ---------------------------------------------------------------------------
// Abstract base — shared by all Pro placeholder widgets
// ---------------------------------------------------------------------------

abstract class UM_Pro_Placeholder_Base extends \Elementor\Widget_Base {

    /** Elementor category slug. */
    public function get_categories(): array {
        return [ 'um-addons-elementor' ];
    }

    /** No real scripts/styles needed on frontend. */
    public function get_style_depends(): array  { return []; }
    public function get_script_depends(): array { return []; }

    // -- Subclasses supply these -------------------------------------------

    /** Human-readable Pro feature name shown in the upgrade card. */
    abstract protected function get_pro_feature_name(): string;

    /** One-sentence pitch shown under the feature name. */
    abstract protected function get_pro_feature_description(): string;

    /** URL to a live demo for this feature. */
    protected function get_demo_url(): string {
        return 'https://userelements.com/ultimate-member-elementor/#demo';
    }

    /** Upgrade CTA URL. */
    protected function get_upgrade_url(): string {
        return UM_Elementor_Pro_Links::upgrade_url( 'editor-card' );
    }

    // -----------------------------------------------------------------------

    protected function register_controls(): void {
        // No controls — this widget is purely a placeholder.
    }

    protected function render(): void {
        // Only render the upgrade card inside the Elementor editor.
        if ( ! \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
            return;
        }
        $this->render_upgrade_card();
    }

    private function render_upgrade_card(): void {
        $feature     = esc_html( $this->get_pro_feature_name() );
        $description = esc_html( $this->get_pro_feature_description() );
        $demo_url    = esc_url( $this->get_demo_url() );
        $upgrade_url = esc_url( $this->get_upgrade_url() );
        ?>
        <div class="umwfe-pro-placeholder" role="region" aria-label="<?php echo esc_attr( $feature ); ?> — Pro Feature">
            <div class="umwfe-pro-placeholder-inner">
                <span class="umwfe-pro-lock-icon" aria-hidden="true">🔒</span>

                <h3 class="umwfe-pro-placeholder-title">
                    <?php echo $feature; ?> <span class="umwfe-pro-badge">Pro</span>
                </h3>

                <p class="umwfe-pro-placeholder-desc">
                    <?php echo $description; ?>
                </p>

                <div class="umwfe-pro-placeholder-actions">
                    <a href="<?php echo $demo_url; ?>"
                       target="_blank"
                       rel="noopener noreferrer"
                       class="umwfe-pro-btn umwfe-pro-btn--ghost">
                        <?php esc_html_e( 'See Demo', 'ultimate-member-widgets-for-elementor' ); ?>
                    </a>
                    <a href="<?php echo $upgrade_url; ?>"
                       target="_blank"
                       rel="noopener noreferrer"
                       class="umwfe-pro-btn umwfe-pro-btn--primary">
                        <?php echo esc_html( UM_Elementor_Pro_Links::price_label() ); ?>
                    </a>
                </div>
            </div>
        </div>
        <?php
    }
}

// ---------------------------------------------------------------------------
// 1. User Table Pro placeholder
// ---------------------------------------------------------------------------

class UM_Pro_User_Table_Placeholder extends UM_Pro_Placeholder_Base {

    public function get_name(): string  { return 'umwfe-pro-user-table'; }
    public function get_title(): string { return __( '🔒 User Table — Pro', 'ultimate-member-widgets-for-elementor' ); }
    public function get_icon(): string  { return 'eicon-table'; }

    protected function get_pro_feature_name(): string {
        return __( 'User Table', 'ultimate-member-widgets-for-elementor' );
    }

    protected function get_pro_feature_description(): string {
        return __(
            'This widget is available in Pro. It lets you display your members in a sortable, searchable table with AJAX pagination.',
            'ultimate-member-widgets-for-elementor'
        );
    }
}

// ---------------------------------------------------------------------------
// 2. User Carousel Pro placeholder
// ---------------------------------------------------------------------------

class UM_Pro_User_Carousel_Placeholder extends UM_Pro_Placeholder_Base {

    public function get_name(): string  { return 'umwfe-pro-user-carousel'; }
    public function get_title(): string { return __( '🔒 User Carousel — Pro', 'ultimate-member-widgets-for-elementor' ); }
    public function get_icon(): string  { return 'eicon-carousel'; }

    protected function get_pro_feature_name(): string {
        return __( 'User Carousel', 'ultimate-member-widgets-for-elementor' );
    }

    protected function get_pro_feature_description(): string {
        return __(
            'This widget is available in Pro. It lets you display your members in a beautiful touch-friendly slider.',
            'ultimate-member-widgets-for-elementor'
        );
    }
}

// ---------------------------------------------------------------------------
// 3. Advanced Filters Pro placeholder
// ---------------------------------------------------------------------------

class UM_Pro_Advanced_Filters_Placeholder extends UM_Pro_Placeholder_Base {

    public function get_name(): string  { return 'umwfe-pro-advanced-filters'; }
    public function get_title(): string { return __( '🔒 Advanced Filters — Pro', 'ultimate-member-widgets-for-elementor' ); }
    public function get_icon(): string  { return 'eicon-filter'; }

    protected function get_pro_feature_name(): string {
        return __( 'Advanced Filters', 'ultimate-member-widgets-for-elementor' );
    }

    protected function get_pro_feature_description(): string {
        return __(
            'This widget is available in Pro. Add live AJAX-powered dropdowns, range sliders, and tag filters to any member directory.',
            'ultimate-member-widgets-for-elementor'
        );
    }
}

// ---------------------------------------------------------------------------
// 4. Profile Builder Pro placeholder
// ---------------------------------------------------------------------------

class UM_Pro_Profile_Builder_Placeholder extends UM_Pro_Placeholder_Base {

    public function get_name(): string  { return 'umwfe-pro-profile-builder'; }
    public function get_title(): string { return __( '🔒 Profile Builder — Pro', 'ultimate-member-widgets-for-elementor' ); }
    public function get_icon(): string  { return 'eicon-person'; }

    public function get_categories(): array {
        return [ 'um-profile-forms-elementor' ];
    }

    protected function get_pro_feature_name(): string {
        return __( 'Profile Builder', 'ultimate-member-widgets-for-elementor' );
    }

    protected function get_pro_feature_description(): string {
        return __(
            'This widget is available in Pro. Build fully custom user profile pages with 9 dedicated profile widgets.',
            'ultimate-member-widgets-for-elementor'
        );
    }
}

// ---------------------------------------------------------------------------
// 5. Account Page Styler Pro placeholder
// ---------------------------------------------------------------------------

class UM_Pro_Account_Styler_Placeholder extends UM_Pro_Placeholder_Base {

    public function get_name(): string  { return 'umwfe-pro-account-styler'; }
    public function get_title(): string { return __( '🔒 Account Page Styler — Pro', 'ultimate-member-widgets-for-elementor' ); }
    public function get_icon(): string  { return 'eicon-settings'; }

    public function get_categories(): array {
        return [ 'um-profile-forms-elementor' ];
    }

    protected function get_pro_feature_name(): string {
        return __( 'Account Page Styler', 'ultimate-member-widgets-for-elementor' );
    }

    protected function get_pro_feature_description(): string {
        return __(
            'Style the Ultimate Member account page (General, Password, Privacy, Notifications tabs) directly inside Elementor.',
            'ultimate-member-widgets-for-elementor'
        );
    }
}

// ---------------------------------------------------------------------------
// 6. Multi-Column Layout Pro placeholder
// ---------------------------------------------------------------------------

class UM_Pro_Multi_Column_Placeholder extends UM_Pro_Placeholder_Base {

    public function get_name(): string  { return 'umwfe-pro-multi-column'; }
    public function get_title(): string { return __( '🔒 Multi-Column Layout — Pro', 'ultimate-member-widgets-for-elementor' ); }
    public function get_icon(): string  { return 'eicon-columns'; }

    protected function get_pro_feature_name(): string {
        return __( 'Multi-Column & Zigzag Layouts', 'ultimate-member-widgets-for-elementor' );
    }

    protected function get_pro_feature_description(): string {
        return __(
            'Display your members in 2-column, 3-column, or zigzag layouts for full design flexibility.',
            'ultimate-member-widgets-for-elementor'
        );
    }
}

// ---------------------------------------------------------------------------
// 7. Live Search Pro placeholder
// ---------------------------------------------------------------------------

class UM_Pro_Live_Search_Placeholder extends UM_Pro_Placeholder_Base {

    public function get_name(): string  { return 'umwfe-pro-live-search'; }
    public function get_title(): string { return __( '🔒 Live Search — Pro', 'ultimate-member-widgets-for-elementor' ); }
    public function get_icon(): string  { return 'eicon-search'; }

    protected function get_pro_feature_name(): string {
        return __( 'Live Search Widget', 'ultimate-member-widgets-for-elementor' );
    }

    protected function get_pro_feature_description(): string {
        return __(
            'A dedicated AJAX-powered user search widget. Drop it anywhere on the page — separate from the directory grid.',
            'ultimate-member-widgets-for-elementor'
        );
    }
}
