<?php

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

class AIEO_DMM_Free_Shipping_Display extends AIEO_DMM_Module_Base {

    public function get_id()       { return 'free_shipping_display'; }
    public function get_label()    { return __('Free Shipping 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_add_inline_script('wp-color-picker',
            'jQuery(function($){$(".aieo-dmm-fs-color").wpColorPicker();});'
        );
    }

    public function render_subtab() {
        echo '<div class="aieo-dmm-section">';
        echo '<h2>' . esc_html__('Free Shipping — display settings', 'ai-eshop-optimizer') . '</h2>';
        echo '<p class="description">'
           . esc_html__('Messages, where the progress bar appears, the early-signal notice, and the visual styling. These settings are unified — they drive every Free Shipping rule\'s render across cart / checkout / mini-cart / product page / floating bar. Eligibility logic (rules CRUD, threshold, weight cap) lives under Special Pricing → Offers → Free Shipping.', 'ai-eshop-optimizer')
           . '</p>';

        $parent = $this->resolve_parent();
        if ($parent && method_exists($parent, 'render_display_settings_card')) {
            $parent->render_display_settings_card();
        } else {
            echo '<p style="color:#b91c1c;">'
               . esc_html__('Free Shipping module is not loaded — check that AIEO_DMM_Free_Shipping 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('free_shipping');
    }
}
