<?php
/*
 * Price widget
 */
// register widget
add_action('widgets_init', 'portfoliolite_price_widget');
function portfoliolite_price_widget() {
    register_widget( 'portfoliolite_price' );
}
// add admin scripts
add_action('admin_enqueue_scripts', 'portfoliolite_price_enqueue');
function portfoliolite_price_enqueue() {
    wp_enqueue_media();
    wp_enqueue_script('portfoliolite_price_script', get_template_directory_uri() . '/js/widget.js', false, '1.0', true);
}
// portfoliolite_price widget class
class portfoliolite_price extends WP_Widget {
    function portfoliolite_price() {
        $widget_ops = array('classname' => 'th-price',
            'description' => 'Show your pricing table');
        parent::__construct('price-widget', __('portfoliolite : Price Widget','portfoliolite'), $widget_ops);
    }

    function widget($args, $instance) {
        extract($args);
        // widget content
        echo $before_widget;
        $item = "";
        $title = isset($instance['title'])?$instance['title']:'New Title';
        $price = isset($instance['price'])?$instance['price']:'';
        $currency = isset($instance['currency'])?$instance['currency']:'';
        $pricemeta = isset($instance['pricemeta'])?$instance['pricemeta']:'';
        $buttonlevel = isset($instance['buttonlevel'])?$instance['buttonlevel']:'Level';
        $buttonlink = isset($instance['buttonlink'])?$instance['buttonlink']:'http://';
         $portfolioitem = isset($instance['portfolioitem'])?$instance['portfolioitem']:'';
        
        $item     .= (isset($instance['item1']) && $instance['item1']!='')?"<li><i class='fa fa-check' aria-hidden='true' 
        ></i>".$instance['item1']."</li>":'';
        $item     .= (isset($instance['item2']) && $instance['item2']!='')?"<li ><i class='fa fa-check' aria-hidden='true'></i>".$instance['item2']."</li>":'';
        $item     .= (isset($instance['item3']) && $instance['item3']!='')?"<li ><i class='fa fa-check' aria-hidden='true'></i>".$instance['item3']."</li>":'';
        $item     .= (isset($instance['item4']) && $instance['item4']!='')?"<li><i class='fa fa-check' aria-hidden='true'></i>".$instance['item4']."</li>":'';
        $item     .= (isset($instance['item5']) && $instance['item4']!='')?"<li><i class='fa fa-check' aria-hidden='true'></i>".$instance['item5']."</li>":'';
        $item     .= (isset($instance['item6']) && $instance['item6']!='')?"<li><i class='fa fa-check' aria-hidden='true'></i>".$instance['item6']."</li>":'';
        $item     .= (isset($instance['item7']) && $instance['item7']!='')?"<li><i class='fa fa-check' aria-hidden='true'></i>".$instance['item7']."</li>":'';
        $item     .= (isset($instance['item8']) && $instance['item8']!='')?"<li><i class='fa fa-check' aria-hidden='true'></i>".$instance['item8']."</li>":'';
        $item     .= (isset($instance['item9']) && $instance['item9']!='')?"<li><i class='fa fa-check' aria-hidden='true'></i>".$instance['item9']."</li>":'';
        $item     .= (isset($instance['item10']) && $instance['item10']!='')?"<li><i class='fa fa-check' aria-hidden='true'></i>".$instance['item10']."</li>":'';
?>
<style>
#price-package .package li::before {
    color: <?php echo $color; ?>;
}
</style>
<li class="multi-price first">
<?php if($portfolioitem !=='recommend') {?>          
<div class='package'>
  <a href="<?php echo $buttonlink; ?>"> </a>
    <div class='name'><?php echo apply_filters('widget_title', $title ); ?></div>
    <div class='price'><?php echo $currency; ?><?php echo $price; ?><span class="price-meta"> <?php echo $pricemeta;?></span></div>
    <div class='trial'><?php echo $buttonlevel; ?></div>
    <hr>
    <ul>
    <?php echo $item;?>
    </ul>
  </div>
 <?php } else { ?>
     <style>
    </style>
    <div class='package brilliant'>
    <div class="triangle-price"></div>
    <a href="<?php echo $buttonlink; ?>"></a>
    <div class='name'><?php echo apply_filters('widget_title', $title ); ?></div>
    <div class='price'><?php echo $currency; ?><?php echo $price; ?><span class="price-meta"> <?php echo $pricemeta;?></span></div>
    <div class='trial'><?php echo $buttonlevel; ?></div>
    <hr>
    <ul>
    <?php echo $item; ?>
    </ul>
  </div>
<?php } ?>
</li> 
<?php
        echo $after_widget;

    }
    function update($new_instance, $old_instance) {
        $instance = $old_instance;
        $instance['title'] = $new_instance['title'];
        $instance['price'] = $new_instance['price'];
        $instance['currency'] = $new_instance['currency'];
        $instance['pricemeta'] = $new_instance['pricemeta'];
        $instance['buttonlevel'] = $new_instance['buttonlevel'];
        $instance['buttonlink'] = $new_instance['buttonlink'];
        $instance['item1'] = $new_instance['item1'];
        $instance['item2'] = $new_instance['item2'];
        $instance['item3'] = $new_instance['item3'];
        $instance['item4'] = $new_instance['item4'];
        $instance['item5'] = $new_instance['item5'];
        $instance['item6'] = $new_instance['item6'];
        $instance['item7'] = $new_instance['item7'];
        $instance['item8'] = $new_instance['item8'];
        $instance['item9'] = $new_instance['item9'];
        $instance['item10'] = $new_instance['item10'];
        $instance['portfolioitem'] = $new_instance['portfolioitem'];
        
        return $instance;
    }
    function form($instance) {
         if( $instance) {
        $title = esc_attr($instance['title']);
        $price = $instance['price'];
        $currency = $instance['currency'];
        $pricemeta = $instance['pricemeta'];
        $buttonlevel = $instance['buttonlevel'];
        $buttonlink = $instance['buttonlink'];
        $item1 = $instance['item1'];
        $item2 = $instance['item2'];
        $item3 = $instance['item3'];
        $item4 = $instance['item4'];
        $item5 = $instance['item5'];
        $item6 = $instance['item6'];
        $item7 = $instance['item7'];
        $item8 = $instance['item8'];
        $item9 = $instance['item9'];
        $item10 = $instance['item10'];
        $portfolioitem = $instance['portfolioitem'];
        

    } else {
        $title = 'New Item';
        $price = '000';
        $currency = '$';
        $pricemeta = '/ Per Month';
        $buttonlevel = 'Level';
        $buttonlink = 'http://';
        $item1 = '';
        $item2 = '';
        $item3 = '';
        $item4 = '';
        $item5 = '';
        $item6 = '';
        $item7 = '';
        $item8 = '';
        $item9 = '';
        $item10 = '';
        $portfolioitem = '';
        
    }
    ?>
        <div class="clearfix"></div>

        <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title','portfoliolite'); ?></label>
        <input type="text" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title'); ?>" value="<?php  echo $title; ?>" style="margin-top:5px;">
        </p>
        <p>
        <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Price','portfoliolite'); ?></label>
        <input type="text" class="widefat" name="<?php echo $this->get_field_name('price'); ?>" id="<?php echo $this->get_field_id('price'); ?>" value="<?php  echo $price; ?>" style="margin-top:5px;">
        </p>
        <p>
        <label for="<?php echo $this->get_field_id('currency'); ?>"><?php _e('Currency','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('currency'); ?>" id="<?php echo $this->get_field_id('currency'); ?>" value="<?php  echo $currency; ?>" style="margin-top:5px;">
        </p>

        <p>
        <label for="<?php echo $this->get_field_id('pricemeta'); ?>"><?php _e('Price-Meta','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('pricemeta'); ?>" id="<?php echo $this->get_field_id('pricemeta'); ?>" value="<?php  echo $pricemeta; ?>" style="margin-top:5px;">
        </p>
        <p>
        <label for="<?php echo $this->get_field_id('buttonlevel'); ?>"><?php _e('Level','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('buttonlevel'); ?>" id="<?php echo $this->get_field_id('buttonlevel'); ?>" value="<?php  echo $buttonlevel; ?>" style="margin-top:5px;">
       </p>
       <p>
       <label for="<?php echo $this->get_field_id('buttonlink'); ?>"><?php _e('Link','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('buttonlink'); ?>" id="<?php echo $this->get_field_id('buttonlink'); ?>" value="<?php  echo $buttonlink; ?>" style="margin-top:5px;">
      </p>
      <p>
      <label for="<?php echo $this->get_field_id('item1'); ?>"><?php _e('Item1','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('item1'); ?>" id="<?php echo $this->get_field_id('item1'); ?>" value="<?php  echo $item1; ?>" style="margin-top:5px;">
      </p>
      <p>
<label for="<?php echo $this->get_field_id('item2'); ?>"><?php _e('Item2','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('item2'); ?>" id="<?php echo $this->get_field_id('item2'); ?>" value="<?php  echo $item2; ?>" style="margin-top:5px;">
</p>
<p>

<label for="<?php echo $this->get_field_id('item3'); ?>"><?php _e('Item3','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('item3'); ?>" id="<?php echo $this->get_field_id('item3'); ?>" value="<?php  echo $item3; ?>" style="margin-top:5px;">
</p>
<p>
<label for="<?php echo $this->get_field_id('item4'); ?>"><?php _e('Item4','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('item4'); ?>" id="<?php echo $this->get_field_id('item4'); ?>" value="<?php  echo $item4; ?>" style="margin-top:5px;">
       </p>
       <p>
<label for="<?php echo $this->get_field_id('item5'); ?>"><?php _e('Item5','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('item5'); ?>" id="<?php echo $this->get_field_id('item5'); ?>" value="<?php  echo $item5; ?>" style="margin-top:5px;">
</p>
<p>
<label for="<?php echo $this->get_field_id('item6'); ?>"><?php _e('Item6','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('item6'); ?>" id="<?php echo $this->get_field_id('item6'); ?>" value="<?php  echo $item6; ?>" style="margin-top:5px;">
</p>
<p>
<label for="<?php echo $this->get_field_id('item7'); ?>"><?php _e('Item7','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('item7'); ?>" id="<?php echo $this->get_field_id('item7'); ?>" value="<?php  echo $item7; ?>" style="margin-top:5px;">
       </p>
<p>
<label for="<?php echo $this->get_field_id('item8'); ?>"><?php _e('Item8','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('item8'); ?>" id="<?php echo $this->get_field_id('item8'); ?>" value="<?php  echo $item8; ?>" style="margin-top:5px;">
       </p>
       <p>
<label for="<?php echo $this->get_field_id('item9'); ?>"><?php _e('Item9','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('item9'); ?>" id="<?php echo $this->get_field_id('item9'); ?>" value="<?php  echo $item9; ?>" style="margin-top:5px;">
       </p>
       <p>
<label for="<?php echo $this->get_field_id('item10'); ?>"><?php _e('Item10','portfoliolite'); ?></label>
       <input type="text" class="widefat" name="<?php echo $this->get_field_name('item10'); ?>" id="<?php echo $this->get_field_id('item10'); ?>" value="<?php  echo $item10; ?>" style="margin-top:5px;">
</p>

<p>
<label for="<?php echo $this->get_field_id('portfolioitem'); ?>"><?php _e('Recommend','portfoliolite'); ?></label>
<input type="checkbox" class="widefat" name="<?php echo $this->get_field_name('portfolioitem'); ?>" id="<?php echo $this->get_field_id('portfolioitem'); ?>" value="recommend" >
</p>

        <?php
    }
}
?>