<?php

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

class AIEO_DMM_Product_Needs_Display extends AIEO_DMM_Module_Base {

    public function get_id()       { return 'product_needs_display'; }
    public function get_label()    { return __('Product Needs Display', 'ai-eshop-optimizer'); }
    public function get_priority() { return 30; }
    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_enqueue_media();
        wp_add_inline_script('wp-color-picker',
            'jQuery(function($){$(".aieo-dmm-pn-color").wpColorPicker();});'
        );
    }

    public function render_subtab() {
        $display = $this->get_display_settings();
        $this->render_template('product-needs-display.php', array(
            'display' => $display,
        ));
    }

    
    private function get_display_settings(): array {
        if (class_exists('AIEO_DMM_Product_Needs')) {
            
            $parent = $this->resolve_parent();
            if ($parent && method_exists($parent, 'get_display_settings')) {
                return (array) $parent->get_display_settings();
            }
        }
        
        $stored = get_option('aieo_dmm_product_needs_display', array());
        return is_array($stored) ? $stored : array();
    }

    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('product_needs');
    }
}
