<?php
function hu_register_body_bg_module( $args ) {
    $defaults = array(
        'setting_id' => '',

        'base_url_path' => '',//PC_AC_BASE_URL/inc/czr-modules/social-links/
        'version' => '',

        'option_value' => array(), //<= will be used for the dynamic registration

        'setting' => array(),
        'control' => array(),
        'section' => array(), //array( 'id' => '', 'label' => '' ),

        'sanitize_callback' => '',
        'validate_callback' => ''
    );
    $args = wp_parse_args( $args, $defaults );

    if ( ! isset( $GLOBALS['czr_base_fmk_namespace'] ) ) {
        error_log( __FUNCTION__ . ' => global czr_base_fmk not set' );
        return;
    }

    $czrnamespace = $GLOBALS['czr_base_fmk_namespace'];
    //czr_fn\czr_register_dynamic_module
    $CZR_Fmk_Base_fn = $czrnamespace . 'CZR_Fmk_Base';
    if ( ! function_exists( $CZR_Fmk_Base_fn) ) {
        error_log( __FUNCTION__ . ' => Namespace problem => ' . $CZR_Fmk_Base_fn );
        return;
    }


    $CZR_Fmk_Base_fn() -> czr_pre_register_dynamic_setting( array(
        'setting_id' => $args['setting_id'],
        'module_type' => 'czr_background',
        'option_value' => ! is_array( $args['option_value'] ) ? array() : $args['option_value'],

        'setting' => $args['setting'],

        'section' => $args['section'],

        'control' => $args['control']
    ));

    // czr_fn\czr_register_dynamic_module()
    $CZR_Fmk_Base_fn() -> czr_pre_register_dynamic_module( array(
        'dynamic_registration' => true,
        'module_type' => 'czr_background',

        // 'sanitize_callback' => 'hu_sanitize_callback__czr_social_module',
        // 'validate_callback' => 'hu_validate_callback__czr_social_module',

        'customizer_assets' => array(
            'control_js' => array(
                // handle + params for wp_enqueue_script()
                // @see https://developer.wordpress.org/reference/functions/wp_enqueue_script/
                'czr-body-bg-module' => array(
                    'src' => sprintf(
                        '%1$s/assets/js/%2$s',
                        $args['base_url_path'],
                        '_3_2_body_background_module.js'
                    ),
                    'deps' => array('customize-controls' , 'jquery', 'underscore'),
                    'ver' => ( defined('WP_DEBUG') && true === WP_DEBUG ) ? time() : $args['version'],
                    'in_footer' => true
                )
            ),
            'localized_control_js' => array(
                'deps' => 'czr-customizer-fmk',
                'global_var_name' => 'bodyBGModuleLocalized',
                'params' => array(
                    //background repeat select options
                    'bg_repeat_options' => array(
                        'no-repeat'      => __( 'No Repeat', 'hueman-pro' ),
                        'repeat'         => __( 'Repeat All', 'hueman-pro' ),
                        'repeat-x'       => __( 'Repeat Horizontally', 'hueman-pro' ),
                        'repeat-y'       => __( 'Repeat Vertically', 'hueman-pro' ),
                        'inherit'        => __( 'Inherit', 'hueman-pro' ),
                    ),

                    //background attachment select options
                    'bg_attachment_options' => array(
                        'fixed'           => __( 'Fixed', 'hueman-pro' ),
                        'scroll'          => __( 'Scroll', 'hueman-pro' ),
                        'inherit'         => __( 'Inherit', 'hueman-pro' ),
                    ),

                    //background position select options
                    'bg_position_options' => array(
                        'left top'        => __( 'Left Top', 'hueman-pro' ),
                        'left center'     => __( 'Left Center', 'hueman-pro' ),
                        'left bottom'     => __( 'Left Bottom', 'hueman-pro' ),
                        'center top'      => __( 'Center Top', 'hueman-pro' ),
                        'center center'   => __( 'Center Center', 'hueman-pro' ),
                        'center bottom'   => __( 'Center Bottom', 'hueman-pro' ),
                        'right top'       => __( 'Right Top', 'hueman-pro' ),
                        'right center'    => __( 'Right Center', 'hueman-pro' ),
                        'right bottom'    => __( 'Right Bottom', 'hueman-pro' ),
                    )
                )
            )
        ),

        'tmpl' => array(
            'item-inputs' => array(
                'background-color'           => array(
                    'input_type'  => 'wp_color_alpha',
                    'title'       => __('Color', 'hueman-pro'),
                    'default'     => '#eaeaea',
                    'width-100'   => true
                ),//"#000000",
                'background-image'  => array(
                    'input_type'  => 'upload',
                    'title'       => __('Background Image', 'hueman-pro'),
                ),
                'background-repeat'  => array(
                    'input_type'  => 'select',
                    'title'       => __('Repeat', 'hueman-pro'),
                ),
                'background-attachment'  => array(
                    'input_type'  => 'select',
                    'title'       => __('Background attachment', 'hueman-pro'),
                ),
                'background-position'  => array(
                    'input_type'  => 'select',
                    'title'       => __('Background position', 'hueman-pro'),
                ),
                'background-size'  => array(
                    'input_type'  => 'text',
                    'title'       => __('Background size', 'hueman-pro'),
                    'notice_after'   => sprintf( '%1$s %2$s',
                        __('The background-size CSS property specifies the size of the background images. The size of the image can be fully constrained or only partially in order to preserve its intrinsic ratio.', 'hueman-pro'),
                        sprintf(' %1$s %2$s.',
                            __('Learn more', 'hueman-pro'),
                            sprintf('<a href="%1$s" target="_blank">%2$s</a>', esc_url('developer.mozilla.org/en-US/docs/Web/CSS/background-size'), __('here', 'hueman-pro') )
                        )
                    )
                )
            )
        )//tmpl
    ));
}//hu_register_body_bg_module()
