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

namespace AutoMarketerAI;

defined('ABSPATH') || exit;

final class PinterestChannel implements ChannelInterface
{
    // --------------------------------------------------
    // ChannelInterface: unique channel slug
    // --------------------------------------------------
    public function get_slug(): string
    {
        return 'pinterest';
    }

    // --------------------------------------------------
    // ChannelInterface: human-readable label for nav
    // --------------------------------------------------
    public function get_label(): string
    {
        return 'Pinterest';
    }

    // --------------------------------------------------
    // ChannelInterface: brand hex color for nav indicator
    // --------------------------------------------------
    public function get_color(): string
    {
        return '#E60023';
    }

    // --------------------------------------------------
    // ChannelInterface: availability
    // Pinterest publishing requires Pinterest API app approval.
    // Returning false renders the coming-soon template until approved.
    // --------------------------------------------------
    public function is_available(): bool
    {
        return false;
    }

    // --------------------------------------------------
    // ChannelInterface: current connection state
    // --------------------------------------------------
    public function get_connection_status(): string
    {
        if (PinterestAuth::isConnected()) {
            return 'connected';
        }

        return 'disconnected';
    }

    // --------------------------------------------------
    // ChannelInterface: handle GET/POST actions (admin_init)
    // --------------------------------------------------
    public function handle_actions(): void
    {
        if (
            isset($_POST['amai_pinterest_disconnect'])
            && isset($_POST['_wpnonce'])
            && wp_verify_nonce(sanitize_text_field((string) $_POST['_wpnonce']), 'amai_pinterest_disconnect')
        ) {
            PinterestAuth::disconnect();
            wp_safe_redirect(
                admin_url('admin.php?page=automarketer-ai-social&channel=pinterest&disconnected=1')
            );
            exit;
        }
    }

    // --------------------------------------------------
    // ChannelInterface: render the channel content area
    // --------------------------------------------------
    public function render(): void
    {
        if (PinterestAuth::isConnected()) {
            $templatePath = AMAI_PLUGIN_DIR . 'templates/social/pinterest-dashboard.php';
        } else {
            $templatePath = AMAI_PLUGIN_DIR . 'templates/social/pinterest-connect.php';
        }

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