<?php
	if ( ! function_exists( 'law_advocate_setup' ) ) :

	function law_advocate_setup() {
		$GLOBALS['content_width'] = apply_filters( 'law_advocate_content_width', 640 );
		
		add_theme_support( 'automatic-feed-links' );
		add_theme_support( 'woocommerce' );
		add_theme_support( 'wc-product-gallery-zoom' );
		add_theme_support( 'wc-product-gallery-slider' );
		add_theme_support( 'post-thumbnails' );
		add_theme_support( 'title-tag' );
		add_theme_support( 'align-wide' );
		add_theme_support( 'wp-block-styles' );
		add_theme_support( 'responsive-embeds' );
		add_theme_support( 'html5', array( 'comment-list', 'search-form', 'comment-form', ) );
		add_theme_support( 'custom-logo', array(
			'height'      => 240,
			'width'       => 240,
			'flex-height' => true,
		) );

		add_theme_support( 'custom-background', array(
			'default-color' => 'f1f1f1'
		) );

		/*
		 * This theme styles the visual editor to resemble the theme style,
		 * specifically font, colors, icons, and column width.
		 */
		add_editor_style( array( 'css/editor-style.css', vw_lawyer_attorney_font_url() ) );

		// Theme Activation Notice
		global $pagenow;

		if (
			is_admin()
			&&
			('themes.php' == $pagenow)
			// &&
			// isset( $_GET['activated'] )
		) {
			add_action('admin_notices', 'law_advocate_activation_notice');
		}
	}
	endif;

	add_action( 'after_setup_theme', 'law_advocate_setup' );

	// Notice after Theme Activation
	function law_advocate_activation_notice() {
    // Hide permanently if dismissed
    if ( get_option('law_advocate_admin_notice') == 1 ) {
        return;
    }
    // Hide ONLY on Get Started page
    if ( isset($_GET['page']) && $_GET['page'] === 'law_advocate_guide' ) {
        return;
    }
		echo '<div id="law-advocate-welcome-notice" class="notice notice-success is-dismissible welcome-notice">';
			echo '<div class="notice-row">';
				echo '<div class="notice-text">';
					echo '<p class="welcome-text1">'. esc_html__( '🎉 Welcome to VW Themes,', 'law-advocate' ) .'</p>';
					echo '<p class="welcome-text2">'. esc_html__( 'You are now using the Law Advocate, a beautifully designed theme to kickstart your website.', 'law-advocate' ) .'</p>';
					echo '<p class="welcome-text3">'. esc_html__( 'To help you get started quickly, use the options below:', 'law-advocate' ) .'</p>';
					echo '<span class="import-btn"><a href="'. esc_url( admin_url( 'themes.php?page=law_advocate_guide' ) ) .'" class="button button-primary">'. esc_html__( 'IMPORT DEMO', 'law-advocate' ) .'</a></span>';
					echo '<span class="demo-btn"><a href="'. esc_url( 'https://www.vwthemes.net/law-advocate/' ) .'" class="button button-primary" target=_blank>'. esc_html__( 'VIEW DEMO', 'law-advocate' ) .'</a></span>';
					echo '<span class="upgrade-btn"><a href="'. esc_url( 'https://www.vwthemes.com/products/advocate-wordpress-theme' ) .'" class="button button-primary" target=_blank>'. esc_html__( 'UPGRADE TO PRO', 'law-advocate' ) .'</a></span>';
					echo '<span class="bundle-btn"><a href="'. esc_url( 'https://www.vwthemes.com/products/wp-theme-bundle' ) .'" class="button button-primary" target=_blank>'. esc_html__( 'BUNDLE OF 500+ THEMES', 'law-advocate' ) .'</a></span>';
				echo '</div>';
				echo '<div class="notice-img1">';
					echo '<img src="' . esc_url( get_theme_file_uri() . '/inc/getstart/images/arrow-notice.png' ) . '" width="180" alt="' . esc_attr__( 'Ecommerce Landing Page', 'law-advocate' ) . '" />';
				echo '</div>';
				echo '<div class="notice-img2">';
					echo '<img src="' . esc_url( get_theme_file_uri() . '/inc/getstart/images/bundle-notice.png' ) . '" width="180" alt="' . esc_attr__( 'Ecommerce Landing Page', 'law-advocate' ) . '" />';
				echo '</div>';	
			echo '</div>';	
		echo '</div>';
	}
    //Hook (VERY IMPORTANT)
	add_action('admin_notices', 'law_advocate_activation_notice');

	add_action( 'wp_enqueue_scripts', 'law_advocate_enqueue_styles' );
	function law_advocate_enqueue_styles() {
    	$parent_style = 'vw-lawyer-attorney-basic-style'; // Style handle of parent theme.
    	
		wp_enqueue_style( 'bootstrap-style', get_template_directory_uri().'/css/bootstrap.css' );
		wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
		wp_enqueue_style( 'law-advocate-style', get_stylesheet_uri(), array( $parent_style ) );
		require get_theme_file_path( '/inline-style.php' );
		wp_add_inline_style( 'law-advocate-style',$vw_lawyer_attorney_custom_css );
		require get_parent_theme_file_path( '/inline-style.php' );
		wp_add_inline_style( 'vw-lawyer-attorney-basic-style',$vw_lawyer_attorney_custom_css );
		wp_enqueue_style( 'law-advocate-block-style', get_theme_file_uri('/assets/css/blocks.css') );
		wp_enqueue_style( 'law-advocate-block-patterns-style-frontend', get_theme_file_uri('/inc/block-patterns/css/block-frontend.css') );

		if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
			wp_enqueue_script( 'comment-reply' );
		}
	}
		
	add_action( 'init', 'law_advocate_remove_parent_function');
	function law_advocate_remove_parent_function() {
		remove_action( 'admin_notices', 'vw_lawyer_attorney_activation_notice' );
		remove_action( 'admin_menu', 'vw_lawyer_attorney_gettingstarted' );
	}

	add_action( 'customize_register', 'law_advocate_customize_register', 11 );
	function law_advocate_customize_register($wp_customize) {
		global $wp_customize;
		$wp_customize->remove_section( 'vw_lawyer_attorney_upgrade_pro_link' );
		$wp_customize->remove_section( 'vw_lawyer_attorney_get_started_link' );
		$wp_customize->remove_section( 'vw_lawyer_attorney_social_icon_settings' );
		$wp_customize->remove_section( 'vw_lawyer_attorney_amenities_section' );
		$wp_customize->remove_section( 'vw_lawyer_attorney_faqs' );
		$wp_customize->remove_control( 'vw_lawyer_attorney_topbar_padding_top_bottom' );
		$wp_customize->remove_control( 'vw_lawyer_attorney_search_border_radius' );
		$wp_customize->remove_control( 'vw_lawyer_attorney_sticky_header' );
		$wp_customize->remove_control( 'vw_lawyer_attorney_sticky_header_padding' );
		$wp_customize->remove_control( 'vw_lawyer_attorney_location1' );
		$wp_customize->remove_control( 'vw_lawyer_attorney_time1' );
		$wp_customize->remove_control( 'vw_lawyer_attorney_time' );
		$wp_customize->remove_control( 'vw_lawyer_attorney_stickyheader_hide_show' );
		$wp_customize->remove_control( 'vw_lawyer_attorney_search_padding_top_bottom' );
		$wp_customize->remove_control( 'vw_lawyer_attorney_search_padding_left_right' );

		//Header
		$wp_customize->add_setting('law_advocate_header_contact_btn_text',array(
			'default'=> '',
			'sanitize_callback'	=> 'sanitize_text_field'
		));
		$wp_customize->add_control('law_advocate_header_contact_btn_text',array(
			'label'	=> esc_html__('Add Button Text','law-advocate'),
			'input_attrs' => array(
	            'placeholder' => esc_html__( 'Contact Us', 'law-advocate' ),
	        ),
			'section'=> 'vw_lawyer_attorney_contact',
			'type'=> 'text'
		));

		$wp_customize->add_setting('law_advocate_header_contact_btn_link',array(
			'default'=> '',
			'sanitize_callback'	=> 'esc_url_raw'
		));
		$wp_customize->add_control('law_advocate_header_contact_btn_link',array(
			'label'	=> esc_html__('Add Button Link','law-advocate'),
			'input_attrs' => array(
	            'placeholder' => esc_html__( 'www.example.com', 'law-advocate' ),
	        ),
			'section'=> 'vw_lawyer_attorney_contact',
			'type'=> 'url'
		));	
		
		//About Section
		$wp_customize->add_setting('law_advocate_section_small_title',array(
			'default'=> '',
			'sanitize_callback'	=> 'sanitize_text_field'
		));	
		$wp_customize->add_control('law_advocate_section_small_title',array(
			'label'	=> esc_html__('Section Small Title','law-advocate'),
			'input_attrs' => array(
	            'placeholder' => esc_html__( 'ABOUT LAW', 'law-advocate' ),
	        ),
			'section'=> 'vw_lawyer_attorney_about1',
			'type'=> 'text'
		));

		$wp_customize->add_setting('law_advocate_about_image2',array(
			'default'	=> '',
			'sanitize_callback'	=> 'esc_url_raw',
		));
		$wp_customize->add_control( new WP_Customize_Image_Control($wp_customize,'law_advocate_about_image2',array(
	        'label' => __('Client Image','law-advocate'),
	        'section' => 'vw_lawyer_attorney_about1'
		)));

		$wp_customize->add_setting('law_advocate_about_client_name',array(
			'default'=> '',
			'sanitize_callback'	=> 'sanitize_text_field'
		));	
		$wp_customize->add_control('law_advocate_about_client_name',array(
			'label'	=> esc_html__('Client Name','law-advocate'),
			'section'=> 'vw_lawyer_attorney_about1',
			'type'=> 'text'
		));

		$wp_customize->add_setting('law_advocate_about_client_designation',array(
			'default'=> '',
			'sanitize_callback'	=> 'sanitize_text_field'
		));	
		$wp_customize->add_control('law_advocate_about_client_designation',array(
			'label'	=> esc_html__('Client Designation','law-advocate'),
			'section'=> 'vw_lawyer_attorney_about1',
			'type'=> 'text'
		));

		for ( $i=1; $i <= 4 ; $i++ ) {
		    
		     $wp_customize->add_setting('law_advocate_about_list_icon' .$i,array(
				'default'	=> 'fas fa-check',
				'sanitize_callback'	=> 'sanitize_text_field'
			));	
			$wp_customize->add_control(new VW_Lawyer_Attorney_Fontawesome_Icon_Chooser(
		        $wp_customize,'law_advocate_about_list_icon' .$i, array(
				'label'	=> __('Add About List Icon','law-advocate'),
				'transport' => 'refresh',
				'section'	=> 'vw_lawyer_attorney_about1',
				'type'		=> 'icon'
			)));

		    $wp_customize->add_setting( 'law_advocate_about_page_list' . $i, array(
		      'default'           => '',
		      'sanitize_callback' => 'sanitize_text_field'
		    ));
		    $wp_customize->add_control( 'law_advocate_about_page_list' . $i, array(
		      'label'    => __( 'Add About List Text', 'law-advocate' ),
		      'section'  => 'vw_lawyer_attorney_about1',
		      'type'     => 'text'
		    ));
    	}
	}

	
	/**
	 * Enqueue block editor style
	 */
	function law_advocate_block_editor_styles() {
		wp_enqueue_style( 'law-advocate-font', vw_lawyer_attorney_font_url(), array() );
	    wp_enqueue_style( 'law-advocate-block-patterns-style-editor', get_theme_file_uri( '/inc/block-patterns/css/block-editor.css' ), false, '1.0', 'all' );
		wp_enqueue_style( 'font-awesome-css', get_template_directory_uri().'/css/fontawesome-all.css' );
	}
	add_action( 'enqueue_block_editor_assets', 'law_advocate_block_editor_styles' );

	function law_advocate_sanitize_choices( $input, $setting ) {
	    global $wp_customize; 
	    $control = $wp_customize->get_control( $setting->id ); 
	    if ( array_key_exists( $input, $control->choices ) ) {
	        return $input;
	    } else {
	        return $setting->default;
	    }
	}

	function law_advocate_sanitize_dropdown_pages( $page_id, $setting ) {
	  	$page_id = absint( $page_id );
	  	return ( 'publish' == get_post_status( $page_id ) ? $page_id : $setting->default );
	}

	/* Theme Widgets Setup */

	function law_advocate_widgets_init() {
		register_sidebar( array(
			'name'          => __( 'Footer Navigation 1', 'law-advocate' ),
			'description'   => __( 'Appears on footer 1', 'law-advocate' ),
			'id'            => 'footer-1',
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		) );

		register_sidebar( array(
			'name'          => __( 'Footer Navigation 2', 'law-advocate' ),
			'description'   => __( 'Appears on footer 2', 'law-advocate' ),
			'id'            => 'footer-2',
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		) );

		register_sidebar( array(
			'name'          => __( 'Footer Navigation 3', 'law-advocate' ),
			'description'   => __( 'Appears on footer 3', 'law-advocate' ),
			'id'            => 'footer-3',
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		) );

		register_sidebar( array(
			'name'          => __( 'Footer Navigation 4', 'law-advocate' ),
			'description'   => __( 'Appears on footer 4', 'law-advocate' ),
			'id'            => 'footer-4',
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		) );

		register_sidebar( array(
			'name'          => __( 'Social Media', 'law-advocate' ),
			'description'   => __( 'Appears on Topbar section', 'law-advocate' ),
			'id'            => 'social-links',
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		) );
	}
	add_action( 'widgets_init', 'law_advocate_widgets_init' );

// Customizer Pro
load_template( ABSPATH . WPINC . '/class-wp-customize-section.php' );

class Law_Advocate_Customize_Section_Pro extends WP_Customize_Section {
	public $type = 'law-advocate';
	public $pro_text = '';
	public $pro_url = '';
	public function json() {
		$json = parent::json();
		$json['pro_text'] = $this->pro_text;
		$json['pro_url']  = esc_url( $this->pro_url );
		return $json;
	}
	protected function render_template() { ?>
		<li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }} cannot-expand">
			<h3 class="accordion-section-title">
				{{ data.title }}
				<# if ( data.pro_text && data.pro_url ) { #>
					<a href="{{ data.pro_url }}" class="button button-secondary alignright" target="_blank">{{ data.pro_text }}</a>
				<# } #>
			</h3>
		</li>
	<?php }
}

final class Law_Advocate_Customize {
	public static function get_instance() {
		static $instance = null;
		if ( is_null( $instance ) ) {
			$instance = new self;
			$instance->setup_actions();
		}
		return $instance;
	}
	private function __construct() {}
	private function setup_actions() {
		// Register panels, sections, settings, controls, and partials.
		add_action( 'customize_register', array( $this, 'sections' ) );
		// Register scripts and styles for the controls.
		add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ), 0 );
	}
	public function sections( $manager ) {
		// Register custom section types.
		$manager->register_section_type( 'Law_Advocate_Customize_Section_Pro' );
		// Register sections.
		$manager->add_section( new Law_Advocate_Customize_Section_Pro( $manager, 'law_advocate_upgrade_pro_link',
		array(
			'priority'   => 1,
			'title'    => esc_html__( 'Law Advocate PRO', 'law-advocate' ),
			'pro_text' => esc_html__( 'UPGRADE PRO', 'law-advocate' ),
			'pro_url'  => esc_url('https://www.vwthemes.com/products/advocate-wordpress-theme'),
		) ) );

		// Register sections.
		$manager->add_section(new Law_Advocate_Customize_Section_Pro($manager,'law_advocate_get_started_link',array(
			'priority'   => 1,
			'title'    => esc_html__( 'DOCUMENTATION', 'law-advocate' ),
			'pro_text' => esc_html__( 'DOCS', 'law-advocate' ),
			'pro_url'  => esc_url('https://preview.vwthemesdemo.com/docs/free-vw-law-advocate/'),
		)));
	}
	public function enqueue_control_scripts() {
		wp_enqueue_script( 'law-advocate-customize-controls', get_stylesheet_directory_uri() . '/assets/js/customize-controls-child.js', array( 'customize-controls' ) );
		wp_enqueue_style( 'law-advocate-customize-controls', get_stylesheet_directory_uri() . '/assets/css/customize-controls-child.css' );
	}
}
Law_Advocate_Customize::get_instance();

function law_advocate_init_setup() {
	/* getstart */
	require get_theme_file_path('/inc/getstart/getstart.php');

	/* Plugin Activation */
	require get_theme_file_path() . '/inc/getstart/plugin-activation.php';

	/* Block Pattern */
	require get_theme_file_path('/inc/block-patterns/block-patterns.php');

	define('LAW_ADVOCATE_FREE_THEME_DOC',__('https://preview.vwthemesdemo.com/docs/free-vw-law-advocate/','law-advocate'));
	define('LAW_ADVOCATE_SUPPORT',__('https://wordpress.org/support/theme/law-advocate/','law-advocate'));
	define('LAW_ADVOCATE_REVIEW',__('https://wordpress.org/support/theme/law-advocate/reviews','law-advocate'));
	define('LAW_ADVOCATE_BUY_NOW',__('https://www.vwthemes.com/products/advocate-wordpress-theme','law-advocate'));
	define('LAW_ADVOCATE_LIVE_DEMO',__('https://www.vwthemes.net/law-advocate/','law-advocate'));
	define('LAW_ADVOCATE_PRO_DOC',__('https://preview.vwthemesdemo.com/docs/law-advocate-pro/','law-advocate'));
	define('LAW_ADVOCATE_FAQ',__('https://www.vwthemes.com/faqs/','law-advocate'));
	define('LAW_ADVOCATE_CONTACT',__('https://www.vwthemes.com/contact/','law-advocate'));
	define('LAW_ADVOCATE_CHILD_THEME',__('https://developer.wordpress.org/themes/advanced-topics/child-themes/','law-advocate'));
	define('LAW_ADVOCATE_CREDIT',__('https://www.vwthemes.com/products/free-law-wordpress-theme','law-advocate'));
	define('LAW_ADVOCATE_THEME_BUNDLE_BUY_NOW',__('https://www.vwthemes.com/products/wp-theme-bundle','law-advocate'));
	define('LAW_ADVOCATE_THEME_BUNDLE_DOC',__('https://preview.vwthemesdemo.com/docs/theme-bundle/','law-advocate'));

	if ( ! function_exists( 'law_advocate_credit' ) ) {
		function law_advocate_credit(){
			echo "<a href=".esc_url(LAW_ADVOCATE_CREDIT)." target='_blank'>". esc_html__('Lawyer WordPress Theme','law-advocate') ."</a>";
		}
	}

	if ( ! defined( 'VW_LAWYER_ATTORNEY_GETSTARTED_URL' ) ) {
		define( 'VW_LAWYER_ATTORNEY_GETSTARTED_URL', 'themes.php?page=law_advocate_guide');
	}

	if ( ! defined( 'VW_LAWYER_ATTORNEY_GO_PRO' ) ) {
		define( 'VW_LAWYER_ATTORNEY_GO_PRO', 'https://www.vwthemes.com/products/advocate-wordpress-theme');
	}
}
add_action( 'after_setup_theme', 'law_advocate_init_setup' );

// Admin notice code START
add_action('wp_ajax_law_advocate_dismiss_notice', 'law_advocate_dismiss_notice');
function law_advocate_dismiss_notice() {
    update_option('law_advocate_admin_notice', 1);
    wp_die();
}

//After Switch theme function
add_action('after_switch_theme', 'law_advocate_getstart_setup_options');
function law_advocate_getstart_setup_options () {
    delete_option('law_advocate_admin_notice');
}
// Admin notice code END