<?php

namespace PloverCRM\Modules\FluentCRM\Tabs;

/**
 * FluentCRM Settings Tab
 * 
 * Handles FluentCRM-specific settings and logs
 */
class FluentCRMSettingsTab
{
    /**
     * Register settings
     */
    public function register(): void
    {
        add_action('admin_init', [$this, 'registerSettings']);
    }

    /**
     * Register settings fields
     */
    public function registerSettings(): void
    {
        // Register settings section
        add_settings_section(
            'plover_crm_fluent_crm_section',
            'FluentCRM Integration',
            [$this, 'renderSectionDescription'],
            'plover_crm_fluent_crm_settings'
        );

        // Logs
        add_settings_field(
            'plover_crm_fluent_crm_logs',
            'Recent Logs',
            [$this, 'renderLogs'],
            'plover_crm_fluent_crm_settings',
            'plover_crm_fluent_crm_section'
        );
    }

    /**
     * Render section description
     */
    public function renderSectionDescription(): void
    {
        echo '<p>FluentCRM is currently active as your CRM provider. View logs and monitor operations below.</p>';
        
        // Show FluentCRM version if available
        if (defined('FLUENTCRM_PLUGIN_VERSION')) {
            echo '<p><strong>FluentCRM Version:</strong> ' . esc_html(FLUENTCRM_PLUGIN_VERSION) . '</p>';
        }
    }

    /**
     * Render logs section
     */
    public function renderLogs(): void
    {
        \PloverCRM\Modules\FluentCRM\Helpers\LogViewer::render();
    }
}
