<?php

/**
 * angel functions and definitions.
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package angel
 */
if (!function_exists('angel_setup')) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 */
function angel_setup()
{
    /*
   * Make theme available for translation.
   * Translations can be filed in the /languages/ directory.
   * If you're building a theme based on angel, use a find and replace
   * to change 'angel' to the name of your theme in all the template files.
   */
  load_theme_textdomain('angel', get_template_directory() . '/languages');

    // Add default posts and comments RSS feed links to head.
  add_theme_support('automatic-feed-links');
    /*
   * Let WordPress manage the document title.
   * By adding theme support, we declare that this theme does not use a
   * hard-coded <title> tag in the document head, and expect WordPress to
   * provide it for us.
   */
  add_theme_support('title-tag');

    /*
   * Enable support for Post Thumbnails on posts and pages.
   *
   * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
   */
  add_theme_support('post-thumbnails');

    // This theme uses wp_nav_menu() in one location.
  register_nav_menus(array(
    'primary' => esc_html__('Primary', 'angel'),
    'secondary' => esc_html__('Secondary', 'angel'),
  ));
    /*
   * Switch default core markup for search form, comment form, and comments
   * to output valid HTML5.
   */
  add_theme_support('html5', array(
    'search-form',
    'comment-form',
    'comment-list',
    'gallery',
    'caption',
  ));
    /*
   * Enable support for Post Formats.
   * See https://developer.wordpress.org/themes/functionality/post-formats/
   */
  add_theme_support('post-formats', array(
    'aside',
    'image',
    'video',
    'quote',
    'link',
  ));
    // Set up the WordPress core custom background feature.
  add_theme_support('custom-background', apply_filters('angel_custom_background_args', array(
    'default-color' => 'ffffff',
    'default-image' => '',
  )));
}
endif;
add_action('after_setup_theme', 'angel_setup');
/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function angel_content_width()
{
  $GLOBALS['content_width'] = apply_filters('angel_content_width', 640);
}
add_action('after_setup_theme', 'angel_content_width', 0);
/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */

function angel_widgets_init()
{

  register_sidebar(array(
    'name' => 'Blog Sidebar',
    'id' => 'blog_sidebar',
    'before_widget' => '<div class="widget">',
    'after_widget' => '</div>',
    'before_title' => '<h4 class="widget-title">',
    'after_title' => '</h4>',
  ));


  register_sidebar(array(
    'name' => 'Footer Widgets',
    'id' => 'footer_widgets',
    'before_widget' => '<div class="col-sm-3 col-xs-12 widget">',
    'after_widget' => '</div>',
    'before_title' => '<h4 class="footerInfoTitle">',
    'after_title' => '</h4>',
  ));



}
add_action('widgets_init', 'angel_widgets_init');

/**
 * Show cart contents / total Ajax
 */
add_filter('woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');

function woocommerce_header_add_to_cart_fragment($fragments)
{
  global $woocommerce;

  ob_start();

  ?>

    <a class="cart-contents" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'angel'); ?>">
      <i class="fa fa-shopping-basket"></i> <span class="cart-contents-count"><?php echo sprintf(_n('%d', '%d', WC()->cart->get_cart_contents_count(), 'angel'), WC()->cart->get_cart_contents_count()); ?></span>
    </a>

	<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}

/**
 * Enqueue scripts and styles.
 */
function angel_scripts()
{
  wp_enqueue_style('angel-bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css');
  wp_enqueue_style('angel-fonts', get_template_directory_uri() . '/assets/css/font-awesome.min.css');
//    wp_enqueue_style( 'angel-main.css', get_template_directory_uri().'/assets/css/style.css' );
  wp_enqueue_style('owl.carousel.css', get_template_directory_uri() . '/assets/css/owl.carousel.min.css');
  wp_enqueue_style('angel-style', get_stylesheet_uri());
  wp_enqueue_script('angel-bootstrap.min.js', get_template_directory_uri() . '/assets/js/bootstrap.min.js', array('jquery'), '20120206', true);

  wp_enqueue_script('owl.carousel.min.js', get_template_directory_uri() . '/assets/js/owl.carousel.min.js', array('jquery'), '20120206', true);
  wp_enqueue_script('script-js', get_template_directory_uri() . '/assets/js/custom.js', array('jquery'), '20120206', true);
  wp_enqueue_script('tilt.min.js', get_template_directory_uri() . '/assets/js/tilt.jquery.min.js', array('jquery'), '20120206', true);

  if (is_singular() && comments_open() && get_option('thread_comments')) {
    wp_enqueue_script('comment-reply');
  }
}
add_action('wp_enqueue_scripts', 'angel_scripts');


function angel_theme_customizer_init()
{
  wp_enqueue_script(
    'angel-themecustomizer',            //Give the script an ID
    get_template_directory_uri() . '/js/customizer.js',//Point to file
    array('jquery', 'customize-preview'),    //Define dependencies
    '1.0',                       //Define a version (optional) 
    true                      //Put script in footer?
  );
}
add_action('customize_preview_init', 'angel_theme_customizer_init');
/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/inc/custom-header.php';
/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';
/**l
 * Custom functions that act independently of the theme templates.
 */
require get_template_directory() . '/inc/extras.php';
/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';
/**
 * Load Jetpack compatibility file.
 */
require get_template_directory() . '/inc/jetpack.php';


/**
 * Registers an editor stylesheet for the theme.
 */
function wpdocs_theme_add_editor_styles() {
  add_editor_style( 'custom-editor-style.css' );
}
add_action( 'admin_init', 'wpdocs_theme_add_editor_styles' );









//TMG Plugin for plugin activation
if (file_exists(__DIR__ . '/inc/tmg/class-tgm-plugin-activation.php')) {
  require_once __DIR__ . '/inc/tmg/class-tgm-plugin-activation.php';
}


if (file_exists(__DIR__ . '/inc/shortcodes.php')) {
  require_once __DIR__ . '/inc/shortcodes.php';
};

if (file_exists(__DIR__ . '/inc/elementor-functions.php')) {
  require_once __DIR__ . '/inc/elementor-functions.php';
}

if (file_exists(__DIR__ . '/inc/elements.php')) {
  require_once __DIR__ . '/inc/elements.php';
}

// Woocommerce Settings
add_action('after_setup_theme', 'woocommerce_support');
function woocommerce_support()
{
  add_theme_support('woocommerce');
}


remove_action('woocommerce_before_shop_loop', 'woocommerce_result_count', 20);
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5);



remove_action('woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10);
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_after_shop_loop_item', 5);


add_action('woocommerce_before_shop_loop_item', function () {
  ?>
  <div <?php wc_product_class('col-md-4'); ?> >
	  <div class="block produtSingle">
 
      <div class="produtImage">
<?php

});

add_action('woocommerce_before_shop_loop_item_title', function () {
  ?>
  </div>
<?php

}, 11);


add_action('woocommerce_before_shop_loop_item_title', function () {
  ?>
    <div class="productMask">
      <?php woocommerce_template_loop_add_to_cart(); ?>
    </div>
  <?php

}, 10);

add_action('woocommerce_before_shop_loop_item_title', function () {
  ?>
    <div class="productCaption">
    
  <?php

}, 11);

add_action('woocommerce_shop_loop_item_title', function () {
  ?>
    </div>
  <?php

}, 12);

add_action('woocommerce_after_shop_loop_item', function(){
  ?>
     </div>
</div>
  <?php 
}, 10);

add_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_price', 11);

add_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9);
add_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 10);

remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price');

add_action('woocommerce_before_main_content', 'remove_sidebar');
function remove_sidebar()
{
  if (is_shop()) {
    remove_action('woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
  }
}

add_action('woocommerce_before_main_content', function() {
  ?>

<section class="page-wrapper container">
	<div class="row" id="woo-margin-zero">
		<div class="col-md-12">

  <?php
},8);

add_action('woocommerce_no_products_found', function() {
  ?>
		</div>	
	</div>
</section>

<?php 
},12);

// woocommerce product catagory page
add_action('woocommerce_before_main_content', 'remove_sidebar_archive');
function remove_sidebar_archive() {
  if (is_archive()) {
    remove_action('woocommerce_sidebar', 'woocommerce_get_sidebar',10);
  }
}

add_filter( 'woocommerce_output_related_products_args', 'bbloomer_change_number_related_products', 9999 );
 
function bbloomer_change_number_related_products( $args ) {
 $args['posts_per_page'] = 3; // # of related products
 $args['columns'] = 3; // # of columns per row
 return $args;
}

//TMG Plugin Settings
add_action('tgmpa_register', 'angel_register_required_plugins');
function angel_register_required_plugins()
{

  $plugins = array(
    array(
      'name' => 'Elementor Page Builder',
      'slug' => 'elementor',
      'required' => true,
    ),
    array(
      'name' => 'Contact Form',
      'slug' => 'contact-form-7',
      'required' => false,
    ),
    array(
      'name' => 'Woocommerce',
      'slug' => 'woocommerce',
      'required' => false,
    ),
     array(
      'name' => 'Booked',
      'slug' => 'booked',
	  'source'    => 'http://angel.iamabdus.com/plugins/booked.zip',
    ),
    array(
      'name' => 'Demo Import',
      'slug' => 'one-click-demo-import',
      'required' => true,
    )
  );

  $config = array(
    'id' => 'angel',
    'default_path' => '',
    'menu' => 'tgmpa-install-plugins',
    'has_notices' => true,
    'dismissable' => true,
    'dismiss_msg' => '',
    'is_automatic' => true,
    'message' => '',
  );

  tgmpa($plugins, $config);
}

function hex2rgba($color, $opacity = false)
{

  $default = 'rgb(0,0,0)';

  //Return default if no color provided
  if (empty($color))
    return $default; 

  //Sanitize $color if "#" is provided 
  if ($color[0] == '#') {
    $color = substr($color, 1);
  }

        //Check if color has 6 or 3 characters and get values
  if (strlen($color) == 6) {
    $hex = array($color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]);
  } elseif (strlen($color) == 3) {
    $hex = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]);
  } else {
    return $default;
  }

        //Convert hexadec to rgb
  $rgb = array_map('hexdec', $hex);

        //Check if opacity is set(rgba or rgb)
  if ($opacity) {
    if (abs($opacity) > 1)
      $opacity = 1.0;
    $output = 'rgba(' . implode(",", $rgb) . ',' . $opacity . ')';
  } else {
    $output = 'rgb(' . implode(",", $rgb) . ')';
  }

    //Return rgb(a) color string
  return $output;
}


// Woocommerce Add Filer To remove CSS 
add_filter('woocommerce_enqueue_styles', '__return_empty_array');


function angle_customizer_css()
{
  $primary_color = get_theme_mod('angel_color_scheme_settings') == '' ? "#e1488c" : get_theme_mod('angel_color_scheme_settings');
  ?>

    <style type="text/css">

    .navbar-default .navbar-nav > li.current-menu-item > a {
      color: <?php echo $primary_color ?>
    }

    .btn-primary:link, .btn-primary:visited, .btn-primary:active:focus{
      background-color: <?php echo $primary_color ?>;
    }


    ::selection {
      background-color: <?php echo $primary_color ?>;
    }


    .tabs-left .nav li a:hover, .tabs-left .nav li.active a, .tabs-left .nav li.active a:hover, .tabs-left .nav li.active a:focus, .tabs-left .nav li.active a a:active, .homeGallery ul.filter > li.active > a, .homeGallery ul.filter > li > a:hover {
      border-bottom-color: <?php echo $primary_color ?>;
    }

    .tabs-left .nav li.active a {
      border-bottom: 1px dashed <?php echo $primary_color ?>;
    }
    .tabTop .nav li.active a, .tabTop .nav li.active a:hover, .tabTop .nav li a:hover {
        color: <?php echo $primary_color ?>;
    }

    .tabs-left .nav li a:hover, .tabs-left .nav li.active a, .tabs-left .nav li.active a:hover, .tabs-left .nav li.active a:focus, .tabs-left .nav li.active a a:active, .homeGallery ul.filter > li.active > a, .homeGallery ul.filter > li > a:hover {
        border-bottom-color: <?php echo $primary_color ?>;
    }

    .varietyContent h4{
      color: <?php echo $primary_color ?>;
    }

          
    .blogCommnets .media-body .btn-link, .post-comments .comment-form .submit , .backToTop , .pageTitleArea ,.cart_btn a .cart-contents-count , .top-info-bar , .priceTag , .navbar-default .navbar-toggle , .woocommerce .woocommerce-MyAccount-navigation li.is-active a , p.no-comments , .single_add_to_cart_button, .woocommerce-Button , .btn-primary:hover, .wpcf7 input[type='submit']:hover, .single_add_to_cart_button:hover, .woocommerce-Button:hover ,.mc4wp-form-fields input[type="submit"] , .shop_table td.actions input[type="submit"] , .woocommerce .cart-collaterals .cart_totals .wc-proceed-to-checkout a , .woocommerce .form-row input[type='submit'], .blogSidebar .widget .widget-title, .btn-primary, .wpcf7 input[type='submit'] , .product .woocommerce-tabs .tabs li.active a ,.navbar-default .navbar-toggle:hover ,   ::selection , .onsale , .woocommerce-tabs .tabs li.active a   {
      background: <?php echo $primary_color ?>
    }

    .post-comments .comment-form .submit{
      border-color: <?php echo $primary_color ?>;
    }


    .footerInfo , .main-menu .sub-menu , .navbar-default .navbar-toggle , .woocommerce .woocommerce-MyAccount-navigation li.is-active a , .mc4wp-form-fields input[type="submit"] , .woocommerce .form-row input[type='submit'] , .blogSidebar .widget .widget-title , .product .woocommerce-tabs .tabs li.active a , .navbar-default .navbar-toggle:hover, .wpcf7 .wpcf7-form-control:not(span):not([type="submit"]):focus, .woocommerce .woocommerce-MyAccount-navigation li.is-active a:hover , .main-slider , .woocommerce-tabs .tabs li.active a{
      border-color: <?php echo $primary_color ?>
    }


    .blogPost h2, .blogPost h2 a , a , .angel-tab .nav-tabs li.active , .reviewInfo .fa-quote-left , .reviewInfo h4 , .expertBox:hover .expertCaption h2, .offerContent .offerPrice h5 , .navbar-default .navbar-nav > li > a:hover , .main-menu .sub-menu li a:hover , .footer-widget .cat-item a:hover , .copyRight .list-inline li a:hover , .copyRightText p a:hover , .required , .post-comments .reply a, .post-comments .edit-link a , .main-slider .owl-carousel .owl-controls .owl-nav .owl-prev, .main-slider .owl-carousel .owl-controls .owl-nav .owl-next, .main-slider .owl-carousel .owl-controls .owl-dot , .secotionTitle h2 span, .productCaption h3 , .product .summary .price , .price ins, .price .woocommerce-Price-amount { 
      color: <?php echo $primary_color ?>;
    }

    .priceTableWrapper:hover .maskImage , .expertMask , .productMask , .offerTitle , .woocommerce-message , .woocommerce-error, .woocommerce-info,.woocommerce-noreviews  {
      background: <?php echo hex2rgba($primary_color, 0.7); ?>;
    }


    .team-slider .owl-controls .owl-dots .owl-dot {
        border-color: <?php echo $primary_color ?>;;
        border: 1px solid <?php echo $primary_color ?>;
    }

    .team-slider .owl-controls .owl-dots .owl-dot.active {
        background-color: <?php echo $primary_color ?>;
        width: 13px;
        height: 13px;
    }

    .coupon [name="apply_coupon"], .woocommerce-cart-form [name="update_cart"], button[name='woocommerce_checkout_place_order']{
      background-color: <?php echo $primary_color ?>;
      border: 1px solid <?php echo $primary_color ?>;
    }

    #coupon_code{
      height: 40px;
      box-shadow: none;
      border-radius: 0;
      padding-left: 18px;
      border: 1px solid <?php echo $primary_color ?>;
      color: #333;
    }

    .angel-cta.elementor-element {
      background-color: <?php echo $primary_color ?> !important;
    }

    .angel-contact-details {
      background-color: <?php echo $primary_color ?>!important;
    }
    
    /*.angel-contact-details .elementor-icon-list-icon i {
      color: <?php echo $primary_color ?> !important;
    }*/

    .profilePersonal .list-unstyled li i.fa{
      color: <?php echo $primary_color ?>;
    }

    .wpcf7 input[type="submit"]:active:focus,.wpcf7 input[type="submit"]:focus, .wpcf7 input[type="submit"]:active, .footer-widget .wpcf7 input[type="submit"]{
      background-color: <?php echo $primary_color ?>;
      border: 1px solid <?php echo $primary_color ?>;
    }

    .footer-widget .wpcf7 input[type="email"]{
      border: 1px solid <?php echo $primary_color ?>;
    }

    body table.booked-calendar tr.days, body table.booked-calendar tr.days th, body .booked-calendarSwitcher.calendar, body #booked-profile-page .booked-tabs, #ui-datepicker-div.booked_custom_date_picker table.ui-datepicker-calendar thead, #ui-datepicker-div.booked_custom_date_picker table.ui-datepicker-calendar thead th{
      background-color: <?php echo $primary_color ?> !important;
    }
    body table.booked-calendar tr.days th, body #booked-profile-page .booked-tabs{
      border-color: <?php echo $primary_color ?> !important;
    }
    #ui-datepicker-div.booked_custom_date_picker table.ui-datepicker-calendar tbody td a.ui-state-active, #ui-datepicker-div.booked_custom_date_picker table.ui-datepicker-calendar tbody td a.ui-state-active:hover, body #booked-profile-page input[type=submit].button-primary:hover, body .booked-list-view button.button:hover, body .booked-list-view input[type=submit].button-primary:hover, body table.booked-calendar input[type=submit].button-primary:hover, body .booked-modal input[type=submit].button-primary:hover, body table.booked-calendar th, body table.booked-calendar thead, body table.booked-calendar thead th, body table.booked-calendar .booked-appt-list .timeslot .timeslot-people button:hover, body #booked-profile-page .booked-profile-header, body #booked-profile-page .booked-tabs li.active a, body #booked-profile-page .booked-tabs li.active a:hover, body #booked-profile-page .appt-block .google-cal-button > a:hover, #ui-datepicker-div.booked_custom_date_picker .ui-datepicker-header{
       background-color: <?php echo $primary_color ?> !important;
    }
    body #booked-profile-page input[type=submit].button-primary:hover, body table.booked-calendar input[type=submit].button-primary:hover, body .booked-list-view button.button:hover, body .booked-list-view input[type=submit].button-primary:hover, body .booked-modal input[type=submit].button-primary:hover, body table.booked-calendar th, body table.booked-calendar .booked-appt-list .timeslot .timeslot-people button:hover, body #booked-profile-page .booked-profile-header, body #booked-profile-page .appt-block .google-cal-button > a:hover {
      border-color: <?php echo $primary_color ?> !important;
    }

    body table.booked-calendar td.today .date span{
      border-color: <?php echo $primary_color ?> !important;
    }
    body table.booked-calendar td.today:hover .date span{
      background: <?php echo $primary_color ?> !important;
    }

    .blogSidebar .widget .search-form input[type="search"]:focus {
      border: 1px solid <?php echo $primary_color ?>
    }

    .post-comments .comment-form textarea:focus, .post-comments .comment-form .comment-form-author input:focus, .post-comments .comment-form .comment-form-email input:focus, .post-comments .comment-form .comment-form-url input:focus {
      border: 1px solid <?php echo $primary_color ?>
    }

    .home2-pricing-tabel figure.elementor-image-box-img::before {
    background-image: -webkit-linear-gradient(90deg,rgb(211,16,39) 0%, <?php echo hex2rgba($primary_color, 0.7) ?> 0%,rgba(255,255,255,0) 50%);
    }

    li.home2-price-list span {
    color: <?php echo $primary_color ?>
    }

    .homev2-divider .elementor-divider-separator {
      border-top-color: <?php echo $primary_color ?>
    }

    .home2-icon-list .elementor-icon-list-item i, .home2-icon-list .elementor-icon-list-item .elementor-icon-list-text, .home2-time-shedule .elementor-image-box-content .elementor-image-box-title, .home2-counterup .elementor-counter-number, .home2-shedule-app .elementor-widget-container .elementor-heading-title, .home2-video-title .elementor-widget-container .elementor-heading-title, .home2-shedule-app .elementor-icon-list-item .elementor-icon-list-text {
      color: <?php echo $primary_color ?>
    }

    .homev2-app-clm .elementor-element-populated, .homev2-app-clm .elementor-element-populated::after, .homev2-app-clm .elementor-element-populated::before {
      border-color: <?php echo $primary_color ?>
    }
    
    .star-rating span:before, ul.wc-block-grid__products li.wc-block-grid__product .star-rating span::before, p.stars a:before ,p.stars a:hover ~ a:before ,p.stars:hover a:before, p.stars.selected, a.active:before, p.stars.selected a.active ~ a:before, p.stars.selected a:not(.active):before  {
      color: <?php echo $primary_color ?> !important;
    }

    .angel-ct12, .contact-sidebar {
      background-color: <?php echo $primary_color ?> !important;
    }

    .per-head-color * {
      color: <?php echo $primary_color ?> !important;
    }


  </style>
  <?php

}
add_action('wp_head', 'angle_customizer_css');



add_action('elementor/editor/before_enqueue_scripts', 'elementor_scripts');

function elementor_scripts()
{
  wp_enqueue_script(
    'plugin-name-frontend',
    get_template_directory_uri() . '/assets/js/owl.carousel.min.js',
    [
      'elementor-frontend', // dependency
    ],
    '1.0',
    true // in_footer
  );
}



function ocdi_import_files()
{
  return array(
    array(
      'import_file_name' => 'Demo Import',
      'local_import_file' => trailingslashit(get_template_directory()) . 'demo-files/angel-wp.xml',
      'local_import_widget_file' => trailingslashit(get_template_directory()) . 'demo-files/angel-wp-widgets.wie',
      'local_import_customizer_file' => trailingslashit(get_template_directory()) . 'demo-files/angel-customizer-export.dat',
      'import_preview_image_url' => trailingslashit(get_template_directory_uri()) . 'demo-files/demo.jpg',
      'preview_url' => 'http://angel.iamabdus.com',
    )
  );
}
add_filter('pt-ocdi/import_files', 'ocdi_import_files');

