<?php

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

class AIEO_DMM_Ratings_Display extends AIEO_DMM_Module_Base {

    public function get_id()       { return 'ratings_display'; }
    public function get_label()    { return __('Star Ratings Display', 'ai-eshop-optimizer'); }
    public function get_priority() { return 40; }
    public function get_group()    { return 'visuals'; }

    public function register_hooks() {
        
        
    }

    
    public function enqueue_admin_assets() {
        wp_enqueue_style('wp-color-picker');
        wp_enqueue_script('wp-color-picker');
        wp_add_inline_script('wp-color-picker',
            'jQuery(function($){$(".aieo-dmm-ratings-color").wpColorPicker();});'
        );
    }

    public function render_subtab() {
        echo '<div class="aieo-dmm-section">';
        echo '<h2>' . esc_html__('Star Ratings — display settings', 'ai-eshop-optimizer') . '</h2>';
        echo '<p class="description">'
           . esc_html__('Behavior, where the widget appears, captions + thresholds, and visual styling. The analytics surface (top rated, distribution histogram, source breakdown) lives under Customer Profiling → Star Ratings.', 'ai-eshop-optimizer')
           . '</p>';

        $parent = $this->resolve_parent();
        if ($parent && method_exists($parent, 'render_settings_card')) {
            $parent->render_settings_card();
        } else {
            echo '<p style="color:#b91c1c;">'
               . esc_html__('Star Ratings module is not loaded — check that AIEO_DMM_Ratings is active.', 'ai-eshop-optimizer')
               . '</p>';
        }
        echo '</div>';
    }

    private function resolve_parent() {
        if (!class_exists('AIEO_DMM')) { return null; }
        $dmm = AIEO_DMM::instance();
        if (!$dmm || !method_exists($dmm, 'get_module')) { return null; }
        return $dmm->get_module('ratings');
    }
}
