<?php

defined('ABSPATH') or die('No script kiddies please!!');

if (!class_exists('CIWS_WooCommerce')) {
    class CIWS_WooCommerce extends CIWS_Library
    {
        function __construct()
        {

            add_action('woocommerce_single_product_summary', array($this, 'ciws_add_button_before_title'), 10);
            add_action('woocommerce_single_product_summary', array($this, 'ciws_add_button_after_title'), 12);
            add_action('woocommerce_single_product_summary', array($this, 'ciws_add_button_before_cart'), 30);
            add_action('woocommerce_single_product_summary', array($this, 'ciws_add_button_after_cart'), 32);
            add_action('woocommerce_after_single_product_summary', array($this, 'ciws_add_button_after_long_description'), 20);
        }




        function ciws_add_button_before_title()
        {
            $ciws_main_settings = get_option('ciws_main_settings');

            $button_status = (!empty($ciws_main_settings['woocommerce']['button_status'])) ? 1 : 0;
            if ($button_status == 1) {
                $button_position = (!empty($ciws_main_settings['woocommerce']['button_position'])) ? $ciws_main_settings['woocommerce']['button_position'] : '';
                if ($button_position == 'ciws-before-title') {
                    $woo_button_account = (!empty($ciws_main_settings['woocommerce']['woo_button_account'])) ? $ciws_main_settings['woocommerce']['woo_button_account'] : '';
                    $account_row = $this->get_account_row_by_id($woo_button_account);
                    require CIWS_PATH . '/includes/views/frontend/ciws-shortcode.php';
                }
            }
        }

        function ciws_add_button_after_title()
        {
            $ciws_main_settings = get_option('ciws_main_settings');
            $button_status = (!empty($ciws_main_settings['woocommerce']['button_status'])) ? 1 : 0;
            if ($button_status == 1) {
                $button_position = (!empty($ciws_main_settings['woocommerce']['button_position'])) ? $ciws_main_settings['woocommerce']['button_position'] : '';
                if ($button_position == 'ciws-after-title') {
                    $woo_button_account = (!empty($ciws_main_settings['woocommerce']['woo_button_account'])) ? $ciws_main_settings['woocommerce']['woo_button_account'] : '';
                    $account_row = $this->get_account_row_by_id($woo_button_account);
                    require CIWS_PATH . '/includes/views/frontend/ciws-shortcode.php';
                }
            }
        }

        function ciws_add_button_before_cart()
        {
            $ciws_main_settings = get_option('ciws_main_settings');
            $button_status = (!empty($ciws_main_settings['woocommerce']['button_status'])) ? 1 : 0;
            if ($button_status == 1) {
                $button_position = (!empty($ciws_main_settings['woocommerce']['button_position'])) ? $ciws_main_settings['woocommerce']['button_position'] : '';
                if ($button_position == 'ciws-before-cart') {
                    $woo_button_account = (!empty($ciws_main_settings['woocommerce']['woo_button_account'])) ? $ciws_main_settings['woocommerce']['woo_button_account'] : '';
                    $account_row = $this->get_account_row_by_id($woo_button_account);
                    require CIWS_PATH . '/includes/views/frontend/ciws-shortcode.php';
                }
            }
        }


        function ciws_add_button_after_cart()
        {
            $ciws_main_settings = get_option('ciws_main_settings');
            $button_status = (!empty($ciws_main_settings['woocommerce']['button_status'])) ? 1 : 0;
            if ($button_status == 1) {
                $button_position = (!empty($ciws_main_settings['woocommerce']['button_position'])) ? $ciws_main_settings['woocommerce']['button_position'] : '';
                if ($button_position == 'ciws-after-cart') {
                    $woo_button_account = (!empty($ciws_main_settings['woocommerce']['woo_button_account'])) ? $ciws_main_settings['woocommerce']['woo_button_account'] : '';
                    $account_row = $this->get_account_row_by_id($woo_button_account);
                    require CIWS_PATH . '/includes/views/frontend/ciws-shortcode.php';
                }
            }
        }


        function ciws_add_button_after_long_description()
        {
            $ciws_main_settings = get_option('ciws_main_settings');
            $button_status = (!empty($ciws_main_settings['woocommerce']['button_status'])) ? 1 : 0;
            if ($button_status == 1) {
                $button_position = (!empty($ciws_main_settings['woocommerce']['button_position'])) ? $ciws_main_settings['woocommerce']['button_position'] : '';
                if ($button_position == 'ciws-after-description') {
                    $woo_button_account = (!empty($ciws_main_settings['woocommerce']['woo_button_account'])) ? $ciws_main_settings['woocommerce']['woo_button_account'] : '';
                    $account_row = $this->get_account_row_by_id($woo_button_account);
                    require CIWS_PATH . '/includes/views/frontend/ciws-shortcode.php';
                }
            }
        }
    }

    new CIWS_WooCommerce();
}
