<?php
/**
 * Created by Sublime text 2.
 * User: thanhhiep992
 * Date: 12/08/15
 * Time: 10:00 AM
 */
if(class_exists("woocommerce")){
    if(!function_exists('sv_vc_mini_cart'))
    {
        function sv_vc_mini_cart($attr,$content = false)
        {
            $html = $header_cart_html = $info_content = '';
            extract(shortcode_atts(array(
                'style'         => '',
                'list'          => '',
                'info_pos'      => 'left',
            ),$attr));
            if(!is_admin()){
                switch ($style) {
                    case 'mini-cart12':
                        $header_cart_html = '<a href="'.esc_url(wc_get_cart_url()).'">
                                                <div class="iner-block-cart">
                                                    <span class="cart-item-count set-cart-number">0</span>
                                                </div>
                                            </a>';
                        $html .=    '<div class="block-wrap-cart mini-cart-box mini-cart mini-cart-12">                                            
                                        '.$header_cart_html.'
                                        <div class="block-mini-cart">
                                            <div class="mini-cart-content content-mini-cart">                                    
                                                <div class="mini-cart-main-content">'.sv_mini_cart().'</div>                    
                                                <div class="total-default hidden">'.wc_price(0).'</div>
                                            </div>                                                
                                        </div>
                                    </div>';
                        break;

                    case 'mini-cart11':
                        $header_cart_html = '<div class="iner-block-cart">
                                                <a href="cart.html">
                                                    <span class="icon cart"></span>
                                                    <span class="line1"><b class="text-uppercase">'.esc_html__("Cart","megastore").'</b><br><span><span class="total cart-item-count set-cart-number">0</span> '.esc_html__("sản phẩm:","megastore").' </span><strong><span class="total total-mini-cart-price set-cart-price">'.WC()->cart->get_cart_subtotal().'</span></strong></span>
                                                </a>
                                            </div>';
                        $html .=    '<div class="mini-cart11">
                                        <div class="block-wrap-cart">                                            
                                            '.$header_cart_html.'
                                            <div class="block-mini-cart">
                                                <div class="mini-cart-content content-mini-cart">                                    
                                                    <div class="mini-cart-main-content">'.sv_mini_cart().'</div>                    
                                                    <div class="total-default hidden">'.wc_price(0).'</div>
                                                </div>                                                
                                            </div>
                                        </div>
                                    </div>';
                        break;

                    case 'mini-cart6':
                        $header_cart_html = '<div class="iner-block-cart">
                                                <a href="'.esc_url(wc_get_cart_url()).'">
                                                    <span class="total">'.esc_html__("Cart","megastore").' <span><span class="cart-item-count set-cart-number">0</span> '.esc_html__("sản phẩm","megastore").'</span></span>
                                                </a>
                                            </div>';
                        $html .=    '<div class="block-wrap-cart block-wrap-cart6">                                            
                                        '.$header_cart_html.'
                                        <div class="block-mini-cart">
                                            <div class="mini-cart-content content-mini-cart">                                    
                                                <div class="mini-cart-main-content">'.sv_mini_cart().'</div>                    
                                                <div class="total-default hidden">'.wc_price(0).'</div>
                                            </div>                                                
                                        </div>
                                    </div>';
                        break;

                    case 'mini-cart5':
                        $header_cart_html = '<div class="iner-block-cart">
                                                <a href="'.esc_url(wc_get_cart_url()).'">
                                                    '.esc_html__("Cart","megastore").'<span class="total cart-item-count set-cart-number">0</span>
                                                </a>
                                            </div>';
                        $html .=    '<div class="mini-cart5">
                                        <div class="block-wrap-cart">                                            
                                            '.$header_cart_html.'
                                            <div class="block-mini-cart">
                                                <div class="mini-cart-content content-mini-cart">                                    
                                                    <div class="mini-cart-main-content">'.sv_mini_cart().'</div>                    
                                                    <div class="total-default hidden">'.wc_price(0).'</div>
                                                </div>                                                
                                            </div>
                                        </div>
                                    </div>';
                        break;

                    case 'option3':
                        $header_cart_html = '<div class="iner-block-cart">
                                                <a href="'.esc_url(wc_get_cart_url()).'">
                                                    <span class="total total-mini-cart-price set-cart-price">'.WC()->cart->get_cart_subtotal().'</span>
                                                </a>
                                            </div>';
                        $html .=    '<div class="option3">
                                        <ul class="nav navbar-nav navbar-right">
                                            <li>
                                                <div class="block-wrap-cart">
                                                    '.$header_cart_html.'
                                                    <div class="block-mini-cart">
                                                        <div class="mini-cart-content content-mini-cart">                                    
                                                            <div class="mini-cart-main-content">'.sv_mini_cart().'</div>                    
                                                            <div class="total-default hidden">'.wc_price(0).'</div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </li>
                                        </ul>
                                    </div>';
                        break;

                    case 'mini-cart2':
                    parse_str( urldecode( $list ), $data);
                    if(is_array($data)){
                        foreach ($data as $key => $value) {
                            $url = '#';
                            if(isset($value['url'])) $url = $value['url'];
                            $info_content .=   '<li class="item">
                                                    <a href="'.esc_url($url).'">
                                                        <i class="fa '.$value['icon'].'"></i>
                                                        <span class="line1">'.$value['title'].'<br><strong>'.$value['title2'].'</strong></span>
                                                    </a>
                                                </li>';
                        }
                    }
                        $header_cart_html = '<a href="'.esc_url(wc_get_cart_url()).'">
                                                <span class="icon cart"></span>
                                                <span class="line1">'.esc_html__("Cart","megastore").'<br><strong class="total-mini-cart-price set-cart-price">'.WC()->cart->get_cart_subtotal().'</strong></span>
                                            </a>';
                        $html .=    '<div class="block block-header-right">
                                        <ul class="list-link">';
                        if($info_pos == 'left') $html .= $info_content;
                        $html .=            '<li class="item item-cart block-wrap-cart">
                                                '.$header_cart_html.'
                                                <div class="block-mini-cart">
                                                    <div class="mini-cart-content content-mini-cart">                                    
                                                        <div class="mini-cart-main-content">'.sv_mini_cart().'</div>                    
                                                        <div class="total-default hidden">'.wc_price(0).'</div>
                                                    </div>
                                                </div>
                                            </li>';
                        if($info_pos == 'right') $html .= $info_content;
                        $html .=        '</ul>
                        </div>';
                        break;

                    case 'mini-cart14':
                        $header_cart_html = '<a href="'.esc_url(wc_get_cart_url()).'">
                                                <div class="iner-block-cart box-radius">
                                                    <span>'.esc_html__("Cart","megastore").'</span>
                                                    <span class="total total-mini-cart-price set-cart-price">'.WC()->cart->get_cart_subtotal().'</span>
                                                </div>
                                            </a>';
                        $html .=    '<div class="block-wrap-cart mini-cart-box mini-cart '.$style.'">
                                        '.$header_cart_html.'
                                        <div class="block-mini-cart">
                                            <div class="mini-cart-content content-mini-cart">                                    
                                                <div class="mini-cart-main-content">'.sv_mini_cart().'</div>                    
                                                <div class="total-default hidden">'.wc_price(0).'</div>
                                            </div>
                                        </div>
                                    </div>';
                        break;
                    
                    default:
                        $header_cart_html = '<a href="'.esc_url(wc_get_cart_url()).'">
                                                <div class="iner-block-cart box-radius">
                                                    <span class="cart-item-count set-cart-number">0</span> <span>'.esc_html__("Products:","megastore").'</span>
                                                    <span class="total total-mini-cart-price set-cart-price">'.WC()->cart->get_cart_subtotal().'</span>
                                                </div>
                                            </a>';
                        $html .=    '<div class="block-wrap-cart mini-cart-box mini-cart '.$style.'">
                                        '.$header_cart_html.'
                                        <div class="block-mini-cart">
                                            <div class="mini-cart-content content-mini-cart">                                    
                                                <div class="mini-cart-main-content">'.sv_mini_cart().'</div>                    
                                                <div class="total-default hidden">'.wc_price(0).'</div>
                                            </div>
                                        </div>
                                    </div>';
                        break;
                }
            }
            return apply_filters('s7upf_tempalte_mini_cart',$html);
        }
    }

    stp_reg_shortcode('sv_mini_cart','sv_vc_mini_cart');

    vc_map( array(
        "name"      => esc_html__("SV Mini Cart", 'megastore'),
        "base"      => "sv_mini_cart",
        "icon"      => "icon-st",
        "category"  => '7Up-theme',
        "params"    => array(
            array(
                "type" => "dropdown",
                "heading" => esc_html__("Style",'megastore'),
                "param_name" => "style",
                "value"     => array(
                    esc_html__("Default",'megastore')   => '',
                    esc_html__("Mini Cart 2",'megastore')   => 'mini-cart2',
                    esc_html__("Home 3",'megastore')   => 'option3',
                    esc_html__("Home 5",'megastore')   => 'mini-cart5',
                    esc_html__("Home 6",'megastore')   => 'mini-cart6',
                    esc_html__("Home 11",'megastore')   => 'mini-cart11',
                    esc_html__("Home 12",'megastore')   => 'mini-cart12',
                    esc_html__("Home 14",'megastore')   => 'mini-cart14',
                    )
            ),
            array(
                "type" => "dropdown",
                "heading" => esc_html__("Info link position",'megastore'),
                "param_name" => "info_pos",
                "value"     => array(
                    esc_html__("Left",'megastore')   => 'left',
                    esc_html__("Right",'megastore')   => 'right',
                    ),
                "dependency"    => array(
                    "element"   => "style",
                    "value"     => "mini-cart2",
                    )
            ),
            array(
                "type" => "add_icon_link",
                "heading" => esc_html__("Add List",'megastore'),
                "param_name" => "list",
                "dependency"    => array(
                    "element"   => "style",
                    "value"     => "mini-cart2",
                    )
            )
        )
    ));
}