<?php
/**
 * FluentC Manager Class.
 *
 * @package FluentCPlugin
 */


namespace FluentC;

use FluentC\Utils\Language;
use FluentC\Services\Connect;

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

	public function __call($name, $arguments) {
        error_log("Sitepress method called: " . $name);
        
        switch($name) {
            case 'get_active_languages':  // Not pll_get_post_translations
                $fluentc_connect = new Connect();
    
    // Always set 'fields' to 'slug' to ensure we get an array of slugs
    $args['fields'] = 'slug';
    
    $result = $fluentc_connect->get_pll_fluentc_languages_list( $args );
    
    // Ensure we always return an array of strings (slugs)
    if ( !is_array($result) || empty($result) ) {
        return array();
    }
    
    // If any elements are still objects, extract the slug
    return array_map(function($item) {
        return is_object($item) ? $item->slug : $item;
    }, $result);
                
            case 'languages_list':         // Not pll_languages_list
                return ['en', 'fr'];
                
            case 'default_language':       // Not pll_default_language
                return 'en';
                
            // etc...
            
            default:
                error_log("Unhandled Polylang method: " . $name);
                return null;
        }
    }
	public function __construct() {
      	add_action( 'init', array( $this, 'init_hooks' ), 1 );
	}

	/**
	 * Register hooks to replace Polylang functionality
	 */
	public function init_hooks() {
		add_filter( 'locale', array( $this, 'set_locale' ) );
	}

	/**
	 * Set locale function to replace Polylang functionality
	 */
	public function set_locale( $locale ) {
		// Always return the original locale unchanged
		// FluentC should never modify WordPress locale
		return $locale;
	}

	/**
	 * Check if FluentC is active
	 */
	public function is_fluentc_active() {
		return true; // Replace with your logic to check if FluentC is active.
	}

	/**
	 * Get the locale for FluentC
	 */
	public function get_fluentc_locale() {
		return 'en'; // Replace with your logic to get the current locale.
	}
}