<?php
/*
 * Class MP_Profit_Plugin_Features
 * Calculator section
 */

class MP_Profit_Plugin_Calculator {

    public function __construct() {
        add_action('mp_profit_section_calculator', array($this, 'get_html'));
    }

    /*
     * Get calculator form 
     */

    public function get_calculator_form() {
        ?>
        <form method="POST" action="<?php echo get_template_directory_uri(); ?>">
            <input name="calc_name" type="hidden" value="CompoundSavings">
            <div class="form-group">
                <div class="row">                        
                    <div class=" col-xs-12 col-sm-6 col-md-6 col-lg-6">
                        <label for="starting_amount"><?php _e('Starting Amount', 'mp-profit'); ?></label>
                        <input type="text" id="starting_amount" name="starting_amount" value="2000" title="<?php _e('Only numbers (0-9) are allowed', 'mp-profit'); ?>">


                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="row">                        
                    <div class=" col-xs-12 col-sm-6 col-md-6 col-lg-6">
                        <label for="years"><?php _e('Years to Invest', 'mp-profit'); ?></label>
                        <input type="text" title="<?php _e('Only numbers (0-9) are allowed', 'mp-profit'); ?>" id="years" name="years" value="10" >


                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="span8">
                    <label for="hypo_rate_of_return"><?php _e('Hypothetical Annual Rate of Return', 'mp-profit'); ?></label>
                    <div class="row">                        
                        <div class=" col-xs-12 col-sm-6 col-md-6 col-lg-4">
                            <input type="text" title="<?php _e('Only numbers (0-9) and decimal (.) are allowed', 'mp-profit'); ?>" id="hypo_rate_of_return" name="rate_of_return" value="8.00" size="5" maxlength="7">
                        </div>                       
                        <div class=" col-xs-12 col-sm-6 col-md-6 col-lg-8">
                            <select name="compound_interest" id="compound_interest">
                                <option value="1" selected="selected">compounded annually</option>
                                <option value="4">compounded quarterly</option>
                                <option value="12">compounded monthly</option>
                                <option value="365">compounded daily</option>
                            </select> 
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <button class="button btn-size-middle calc-investing" type="submit"><?php _e('Submit', 'mp-profit'); ?></button>
            </div>
        </form>
        <div class="result">

        </div>
        <?php
    }

    /*
     * Get calculator 
     */

    public function get_calculator() {
        /*
         * mp_profit_before_sidebar_calculator hook
         *
         * @hooked mp_profit_before_sidebar_calculator - 10 
         */
        do_action('mp_profit_before_sidebar_calculator');
        /*
         * calculator form
         */
        $this->get_calculator_form();
        /*
         * mp_profit_after_sidebar_calculator hook
         *
         * @hooked mp_profit_after_sidebar_calculator - 10 
         */
        do_action('mp_profit_after_sidebar_calculator');
    }

    /*
     * Get title 
     */

    public function get_title() {
        $mp_profit_calculator_title = esc_html(get_theme_mod('mp_profit_calculator_title'));
        if (get_theme_mod('mp_profit_calculator_title', false) === false) :
            ?> 
            <h2 class="section-title"><?php _e('Lease calculator', 'mp-profit'); ?></h2>
            <?php
        else:
            if (!empty($mp_profit_calculator_title)):
                ?>
                <h2 class="section-title"><?php echo $mp_profit_calculator_title; ?></h2>
                <?php
            endif;
        endif;
    }

    /*
     * Get subtitle 
     */

    public function get_subtitle() {
        $mp_profit_calculator_subtitle = esc_html(get_theme_mod('mp_profit_calculator_subtitle'));
        if (get_theme_mod('mp_profit_calculator_subtitle', false) === false) :
            ?> 
            <div class="section-subtitle"><?php _e('Use this calculator to estimate the lease payments for particular periods by submitting real prices.', 'mp-profit'); ?></div>
            <?php
        else:
            if (!empty($mp_profit_calculator_subtitle)):
                ?>
                <div class="section-subtitle"><?php echo $mp_profit_calculator_subtitle; ?></div>
                <?php
            endif;
        endif;
    }

    /*
     * Calculator section
     */

    public function get_html() {
        $mp_profit_calculator_image = esc_url(get_theme_mod('mp_profit_calculator_bg'));
        if (get_theme_mod('mp_profit_calculator_bg', false) === false) :
            $mp_profit_calculator_image = MP_PROFIT_PLUGIN_PATH . '/images/calculator-image.jpg';
        endif;
        ?>
        <section id="calculator" class="calculator-section default-section" >       
            <div class="container">
                <div class="row">                        
                    <div class="col-xs-12 col-sm-12 <?php echo empty($mp_profit_calculator_image) ? 'col-md-8 col-lg-8' : 'col-md-6 col-lg-6' ?>">
                        <div class="section-content">
                            <?php
                            $this->get_title();
                            $this->get_subtitle();
                            $this->get_calculator();
                            ?>                   
                        </div>
                    </div>
                    <div class="section-right calculator-right" <?php
                         if (!empty($mp_profit_calculator_image)): echo "style='background: url(\"" . $mp_profit_calculator_image . "\") no-repeat scroll bottom left'";
                         endif;
                         ?>>
                    </div>
                </div>
            </div>
        </section>
        <?php
    }

}
