<?php

class Intense_Pricing_Section extends Intense_Shortcode {

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

        global $intense_visions_options;

        $this->title = __( 'Pricing Section', 'intense' );
        $this->category = __( 'Layout', 'intense' );
        $this->show_preview = true;
        $this->hidden = true;
        $this->is_container = true;
        $this->parent = 'intense_pricing_table';        
    }

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

        $output = '';
        $style = '';
        $font_color_css = '';
        $border_style = null;
        $border_top_style = null;
        $border_right_style = null;
        $border_bottom_style = null;
        $border_left_style = null;

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

        $background_color = intense_get_plugin_color( $background_color );
        $font_color = intense_get_plugin_color( $font_color );

        if ( !empty( $background_color ) ) {
            $background_color_css = ' background: ' . $background_color . ' !important;';
        } else {
            if ( $intense_pricing_table_index % 2 == 0 ) {
                $background_color = $intense_pricing_table_even_background_color;
            } else {
                $background_color = $intense_pricing_table_odd_background_color;
            }

            if ( $template == 'footer' ) {
                $background_color = '#fff';
            }

            $background_color_css = ' background: ' . $background_color . ' !important;';
        }

        if ( !empty( $font_color ) ) {
            $font_color_css = ' color: ' . $font_color . ' !important;';
        }

        if ( isset( $border ) ) $border_style = "border: " . $border . ' !important;';
        if ( isset( $border_top ) ) $border_top_style = "border-top: " . $border_top . ' !important;';
        if ( isset( $border_right ) ) $border_right_style = "border-right: " . $border_right . ' !important;';
        if ( isset( $border_bottom ) ) $border_bottom_style = "border-bottom: " . $border_bottom . ' !important;';
        if ( isset( $border_left ) ) $border_left_style = "border-left: " . $border_left . ' !important;';      
        if ( isset( $border_radius ) ) $border_radius = 'border-radius:' . $border_radius . ';';

        if ( !isset( $atts['frequency'] ) ) $atts['frequency'] = null;
        if ( !isset( $atts['amount'] ) ) $atts['amount'] = null;
        if ( !isset( $atts['sale_amount'] ) ) $atts['sale_amount'] = null;
        if ( !isset( $atts['title'] ) ) $atts['title'] = null;

        $intense_pricing_section = array_merge( $atts, array(
                'background_color_css' => $background_color_css,
                'font_color_css' => $font_color_css,
                'is_featured' => $intense_pricing_table_featured,
                'content' => $content,
                'index' => $intense_pricing_table_index,
                'font_color' => $font_color,
                'background_color' => $background_color,
                'even_background_color' => $intense_pricing_table_even_background_color,
                'odd_background_color' => $intense_pricing_table_odd_background_color,
                'border_css' => $border_style . $border_top_style . $border_right_style . $border_bottom_style . $border_left_style . $border_radius
            ) );

        $output .= intense_get_template( '/pricing-table/' . $template . '.php' );

        $intense_pricing_table_index++;

        $style .= ' .intense.pricing-table-section {
            transition: all .2s linear;
        }';

        if ( !empty( $style ) ) {
            $output .= '<style>' . $style . '</style>';
        }

        return $output;
    }
}
