<?php

// Enqueue styles and scripts
add_action('wp_enqueue_scripts', 'green_grocer_my_theme_enqueue_styles');
function green_grocer_my_theme_enqueue_styles() {
    $green_grocer_parent_style = 'supermarket-shopping-main'; // Style handle of parent theme
    wp_enqueue_style($green_grocer_parent_style, get_template_directory_uri() . '/assets/css/main.css');
    wp_enqueue_style('green_grocer-style', get_stylesheet_uri(), array($green_grocer_parent_style));
}

add_action('wp_enqueue_scripts', 'green_grocer_script');
function green_grocer_script() {
    $green_grocer_parent_script_handle = 'supermarket-shopping-theme-js'; // Script handle of parent theme
    wp_enqueue_script($green_grocer_parent_script_handle, get_theme_file_uri('/assets/js/theme.js'), array(), null, true);
}

// Theme setup
if (!function_exists('green_grocer_setup')) :
    function green_grocer_setup() {
        load_theme_textdomain( 'green-grocer', get_template_directory() . '/languages' );
        add_theme_support('automatic-feed-links');
        add_theme_support('title-tag');
        add_theme_support('custom-header');
        add_theme_support('responsive-embeds');
        add_theme_support('post-thumbnails');
        add_theme_support('align-wide');
        add_editor_style(array('assets/css/editor-style.css'));
        add_theme_support('custom-background', apply_filters('green_grocer_custom_background_args', array(
            'default-color' => 'ffffff',
            'default-image' => '',
        )));

        if ( ! defined( 'SUPERMARKET_SHOPPING_DEMO_IMPORT_URL' ) ) {
            define( 'SUPERMARKET_SHOPPING_DEMO_IMPORT_URL', esc_url( admin_url( 'themes.php?page=greengrocer-wizard' ) ) );
        }
    }
endif;
add_action('after_setup_theme', 'green_grocer_setup');

// Set content width
function green_grocer_content_width() {
    $GLOBALS['content_width'] = apply_filters('green_grocer_content_width', 1170);
}
add_action('after_setup_theme', 'green_grocer_content_width', 0);

// Register widget areas
function green_grocer_widgets_init() {
    register_sidebar(array(
        'name' => __('Sidebar Widget Area', 'green-grocer'),
        'id' => 'supermarket-shopping-sidebar-primary',
        'description' => __('The Primary Widget Area', 'green-grocer'),
        'before_widget' => '<aside id="%1$s" class="widget %2$s wow fadeInUp">',
        'after_widget' => '</aside>',
        'before_title' => '<h4 class="widget-title">',
        'after_title' => '</h4><div class="title"><span class="shap"></span></div>',
    ));
    register_sidebar( array(
        'name' => __( 'Footer Widget Area', 'green-grocer' ),
        'id' => 'supermarket-shopping-footer-widget-area',
        'description' => __( 'The Footer Widget Area', 'green-grocer' ),
        'before_widget' => '<div class="footer-widget col-lg-3 col-sm-6 wow fadeIn" data-wow-delay="0.5s"><aside id="%1$s" class="widget %2$s">',
        'after_widget' => '</aside></div>',
        'before_title' => '<h5 class="widget-title w-title">',
        'after_title' => '</h5><span class="shap"></span>',
    ) );
}
add_action('widgets_init', 'green_grocer_widgets_init');

// Remove customizer settings
function green_grocer_remove_custom($wp_customize) {

    $wp_customize->remove_setting('supermarket_shopping_upgrade_page_settingahdv');
    $wp_customize->remove_control('supermarket_shopping_upgrade_page_settingahdv');

    $wp_customize->remove_setting('supermarket_shopping_upgrade_page_settings_101');
    $wp_customize->remove_control('supermarket_shopping_upgrade_page_settings_101');

    $wp_customize->remove_section('supermarket_shopping_top_product_category_section');

}
add_action('customize_register', 'green_grocer_remove_custom', 1000);

function green_grocer_child_customize_register( $wp_customize ) {

    /*=========================================
    Product deatil
    =========================================*/
    $wp_customize->add_section(
        'green_grocer_product_service', array(
            'title' => esc_html__( 'About Products Delivery & Services Section', 'green-grocer' ),
            'priority' => 14,
            'panel' => 'supermarket_shopping_frontpage_sections',
        )
    );

    // Slider Hide/ Show Setting // 
    $wp_customize->add_setting( 
        'green_grocer_show_hide_product_services_section' , 
            array(
            'default' => false,
            'sanitize_callback' => 'supermarket_shopping_sanitize_checkbox',
            'capability' => 'edit_theme_options',
            'priority' => 2,
        ) 
    );
    $wp_customize->add_control(
    'green_grocer_show_hide_product_services_section', 
        array(
            'label'       => esc_html__( 'Hide / Show Section', 'green-grocer' ),
            'section'     => 'green_grocer_product_service',
            'settings'    => 'green_grocer_show_hide_product_services_section',
            'type'        => 'checkbox'
        )
    );

    $wp_customize->add_setting('green_grocer_add_payment_secure_heading',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('green_grocer_add_payment_secure_heading',array(
        'label' => __('Add Payment Related Heading','green-grocer'),
        'section'   => 'green_grocer_product_service',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('green_grocer_add_payment_secure_details',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('green_grocer_add_payment_secure_details',array(
        'label' => __('Add Payment Related Details','green-grocer'),
        'section'   => 'green_grocer_product_service',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('green_grocer_add_money_guarantee_heading',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('green_grocer_add_money_guarantee_heading',array(
        'label' => __('Add Money Guarantee Heading','green-grocer'),
        'section'   => 'green_grocer_product_service',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('green_grocer_add_money_guarantee_details',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('green_grocer_add_money_guarantee_details',array(
        'label' => __('Add Money Guarantee Details','green-grocer'),
        'section'   => 'green_grocer_product_service',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('green_grocer_add_shipping_heading',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('green_grocer_add_shipping_heading',array(
        'label' => __('Add Shipping Heading','green-grocer'),
        'section'   => 'green_grocer_product_service',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('green_grocer_add_shipping_details',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('green_grocer_add_shipping_details',array(
        'label' => __('Add Shipping Details','green-grocer'),
        'section'   => 'green_grocer_product_service',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('green_grocer_add_customer_support_heading',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('green_grocer_add_customer_support_heading',array(
        'label' => __('Add Customer Support Heading','green-grocer'),
        'section'   => 'green_grocer_product_service',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('green_grocer_add_customer_support_details',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('green_grocer_add_customer_support_details',array(
        'label' => __('Add Customer Support Details','green-grocer'),
        'section'   => 'green_grocer_product_service',
        'type'      => 'text'
    ));

}
add_action( 'customize_register', 'green_grocer_child_customize_register', 20 );

// global color
function green_grocer_customize_css() {
    $supermarket_shopping_dynamic_color = get_theme_mod( 'supermarket_shopping_dynamic_color_one', '#78B85D' );
    $green_grocer_custom_css = ":root { --color-primary1: {$supermarket_shopping_dynamic_color}; }";

    // Inline CSS in <head>
    echo '<style type="text/css">' . $green_grocer_custom_css . '</style>';
}
add_action( 'wp_head', 'green_grocer_customize_css' );