<?php

class Intense_Pricing_Table extends Intense_Shortcode {

    function __construct() {
        parent::__construct();

        global $intense_visions_options;

        $this->title = __( 'Pricing Table', 'intense' );
        $this->description = __( 'Add a pricing table to WordPress with the pricing table shortcode. Use multiple to compare different pricing packages side-by-side. Template each section as needed to make sure they layout perfectly with your design. Several templates are included by default to help you get started.', 'intense' );
        $this->category = __( 'Layout', 'intense' );
        $this->show_preview = true;
        $this->is_container = true;        
    }

    function shortcode( $atts, $content = null ) {
        global $intense_visions_options;
        extract( shortcode_atts( $this->get_shortcode_defaults( null, $atts ), $atts ) );

        global $intense_pricing_table_index;
        global $intense_pricing_table_odd_background_color;
        global $intense_pricing_table_even_background_color;
        global $intense_pricing_table_featured;

        $intense_pricing_table_index = 0;
        $intense_pricing_table_featured = $featured;

        $output = '';
        $style = '';
        $id = ( !empty ( $id ) ) ? ' id="' . $id . '"' : ' id="pricing_table_' . rand() . '"';

        intense_add_script( 'intense.pricingtable' );

        $even_background_color = intense_get_plugin_color( $even_background_color );
        $odd_background_color = intense_get_plugin_color( $odd_background_color );
        $intense_pricing_table_odd_background_color = $odd_background_color;
        $intense_pricing_table_even_background_color = $even_background_color;

        if ( $shadow ) {
            $output .= "<div><div style='margin-bottom: 0;'>";
        }

        $style .= ' margin: 10px 0; position: relative; width: 100%; transition: all .2s linear;';

        if ( $intense_pricing_table_featured ) {
            $style .= ' margin-top: -5px; box-shadow: 0 0 15px rgba(0,0,0,.4); z-index: 2;';
        } else {
            $style .= ' z-index: 1;';
        }

        if ( !empty( $grouping ) ) {
            $grouping = ' data-grouping="' . $grouping . '"';
        } 

        if ( !empty( $hover_expand ) && $hover_expand ) {
            $hover_expand = ' data-hover-expand="true"';
        }

        $output .= '<div style="position: relative;"><div' . $id . ' ' . $grouping . $hover_expand . ' class="intense pricing-table' . ( $featured ? ' featured' : '' ) . ( !empty( $class ) ? ' ' . $class : '' ) . '" style="' . $style . '">' . do_shortcode( $content ) . '</div><div class="clearfix"></div></div>';

        if ( $shadow ) {
            $output .= "</div><img src='" . INTENSE_PLUGIN_URL . "/assets/img/shadow{$shadow}.png' class='intense shadow' style='vertical-align: top; ' alt='' /></div>";
        }

        return $output;
    }
}
