<?php
declare(strict_types=1);
// ==================================================
// Nuclear Fancy Pants Edition™ -- NUCLEAR+++
// File: /home/ploi/automarketer-ai.com/public/wp-content/plugins/automarketer-ai/includes/class-yelp-channel.php
// Description: Yelp local channel implementing ChannelInterface - NUCLEAR+++
// Last Edited: 2026-05-27
// ==================================================

namespace AutoMarketerAI;

defined('ABSPATH') || exit;

final class YelpChannel implements ChannelInterface
{
    public function get_slug(): string
    {
        return 'yelp';
    }

    public function get_label(): string
    {
        return 'Yelp';
    }

    public function get_color(): string
    {
        return '#FF1A1A';
    }

    public function is_available(): bool
    {
        return false;
    }

    public function get_connection_status(): string
    {
        if (YelpAuth::isConnected()) {
            return 'connected';
        }

        return 'disconnected';
    }

    public function handle_actions(): void
    {
        if (
            isset($_POST['amai_yelp_disconnect'])
            && isset($_POST['_wpnonce'])
            && wp_verify_nonce(sanitize_text_field((string) $_POST['_wpnonce']), 'amai_yelp_disconnect')
        ) {
            YelpAuth::disconnect();
            wp_safe_redirect(
                admin_url('admin.php?page=automarketer-ai-social&channel=yelp&disconnected=1')
            );
            exit;
        }
    }

    public function render(): void
    {
        if (YelpAuth::isConnected()) {
            $template = AMAI_PLUGIN_DIR . 'templates/social/yelp-dashboard.php';
        } elseif (YelpAuth::isPendingBusinessSelection()) {
            $template = AMAI_PLUGIN_DIR . 'templates/social/yelp-picker.php';
        } else {
            $template = AMAI_PLUGIN_DIR . 'templates/social/yelp-connect.php';
        }

        if (is_file($template)) {
            include $template;
        }
    }
}