<?php
/**
 * Created by PhpStorm.
 * User: Villatheme-Thanh
 * Date: 08-06-19
 * Time: 2:35 PM
 */

namespace WACVP\Inc\Settings;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class SMS_Settings extends Admin_Settings {

	protected static $instance = null;

	public static function get_instance() {

		if ( null == self::$instance ) {
			self::$instance = new self;
		}

		return self::$instance;
	}

	public function setting_page() {
		$provider = self::$data['sms_provider'];
		?>
        <div class="vi-ui bottom attached tab segment tab-admin" data-tab="sms">
            <h4><?php esc_html_e( 'SMS account config', 'woo-abandoned-cart-recovery' ) ?></h4>
            <table class="wacv-table">
				<?php $this->select_option( 'sms_provider',
					$option = array(
						'twilio'  => 'Twilio',
						'nexmo'   => 'Nexmo',
						'plivo'   => 'Plivo',
						'infobip' => 'Infobip',
//						'messagebird' => 'Messagebird',
//						'smshosting' => 'Smshosting',
					),
					esc_html__( 'SMS provider', 'woo-abandoned-cart-recovery' ) ) ?>
            </table>
            <div class="wacv-providers">
                <div class="wacv-twilio-config" <?php $this->show( $provider, 'twilio' ) ?>>
                    <table class="wacv-table">
						<?php
						$this->text_option( 'sms_app_id', esc_html__( 'App ID', 'woo-abandoned-cart-recovery' ) );
						$this->text_option( 'sms_app_secret', esc_html__( 'App token', 'woo-abandoned-cart-recovery' ) );
						$this->text_option( 'from_phone', esc_html__( 'From number', 'woo-abandoned-cart-recovery' ), 'E.g: +1234567890' );
						?>
                    </table>
                </div>
                <div class="wacv-nexmo-config" <?php $this->show( $provider, 'nexmo' ) ?>>
                    <table class="wacv-table">
						<?php
						$this->text_option( 'sms_app_id_nexmo', esc_html__( 'App ID', 'woo-abandoned-cart-recovery' ) );
						$this->text_option( 'sms_app_secret_nexmo', esc_html__( 'App token', 'woo-abandoned-cart-recovery' ) );
						$this->text_option( 'from_phone_nexmo', esc_html__( 'From number', 'woo-abandoned-cart-recovery' ) );
						?>
                    </table>
                </div>
                <div class="wacv-plivo-config" <?php $this->show( $provider, 'plivo' ) ?>>
                    <table class="wacv-table">
						<?php
						$this->text_option( 'sms_app_id_plivo', esc_html__( 'Auth ID', 'woo-abandoned-cart-recovery' ) );
						$this->text_option( 'sms_app_secret_plivo', esc_html__( 'Auth secret', 'woo-abandoned-cart-recovery' ) );
						//						$this->text_option( 'from_phone_plivo', esc_html__( 'From number', 'woo-abandoned-cart-recovery' ) );
						$this->text_option( 'powerpack_uuid', esc_html__( 'Powerpack UUID', 'woo-abandoned-cart-recovery' ) );
						?>
                    </table>
                </div>
                <div class="wacv-infobip-config" <?php $this->show( $provider, 'infobip' ) ?>>
                    <table class="wacv-table">
						<?php
						$this->text_option( 'sms_app_api_key_infobip', esc_html__( 'API Key', 'woo-abandoned-cart-recovery' ) );
						$this->text_option( 'sms_app_base_url_infobip', esc_html__( 'API Base URL', 'woo-abandoned-cart-recovery' ) );
						$this->text_option( 'from_phone_infobip', esc_html__( 'From number', 'woo-abandoned-cart-recovery' ), 'E.g: +1234567890' );
						?>
                    </table>
                </div>
                <div class="wacv-messagebird-config" <?php $this->show( $provider, 'messagebird' ) ?>>
                    <table class="wacv-table">
						<?php
						$this->text_option( 'sms_app_api_key_messagebird', esc_html__( 'API Key', 'woo-abandoned-cart-recovery' ) );
						$this->text_option( 'from_phone_messagebird', esc_html__( 'From number', 'woo-abandoned-cart-recovery' ), 'E.g: +1234567890' );
						?>
                    </table>
                </div>
<!--                <div class="wacv-smshosting-config" --><?php //$this->show( $provider, 'smshosting' ) ?><!---->
<!--                    <table class="wacv-table">-->
<!--						--><?php
//						$this->text_option( 'sms_app_api_key_smshosting', esc_html__( 'API Key', 'woo-abandoned-cart-recovery' ) );
//						$this->text_option( 'sms_app_api_secret_smshosting', esc_html__( 'API Secret Key', 'woo-abandoned-cart-recovery' ) );
//						$this->text_option( 'from_phone_smshosting', esc_html__( 'From number', 'woo-abandoned-cart-recovery' ), 'E.g: +1234567890' );
//						?>
<!--                    </table>-->
<!--                </div>-->
            </div>
            <h4><?php esc_html_e( 'Bitly config', 'woo-abandoned-cart-recovery' ) ?></h4>
            <table class="wacv-table">
				<?php
				$this->checkbox_option( 'shortlink_enable', esc_html__( 'Use shortlink', 'woo-abandoned-cart-recovery' ) );
				$this->text_option( 'shortlink_access_token', esc_html__( 'Access token', 'woo-abandoned-cart-recovery' ) );
				?>
            </table>

            <h4><?php esc_html_e( 'Send test SMS', 'woo-abandoned-cart-recovery' ) ?></h4>
            <table class="wacv-table">
                <tr>
                    <td class="col-1" valign="top">
						<?php esc_html_e( 'To number', 'woo-abandoned-cart-recovery' ); ?>
                    </td>
                    <td class="col-2">
                        <input type="text" class="wacv-to-phone-number" placeholder="E.g: +1234567890">
                    </td>
                </tr>
                <tr>
                    <td class="col-1" valign="top"></td>
                    <td class="col-2">
                        <button type="button" class="wacv-send-test-sms vi-ui small icon green button">
							<?php esc_html_e( 'Send', 'woo-abandoned-cart-recovery' ); ?>
                        </button>
                        <span class="wacv-send-test-sms-notice"></span>
                    </td>
                    <td class="col-3"></td>
                </tr>
                <tr>
                    <td class="col-1" valign="top">
                    </td>
                    <td class="col-2">
                        <div class="vi-ui styled accordion wacv-accor">
                            <div class="title">
                                <i class="dropdown icon"></i>
								<?php esc_html_e( 'Config guide', 'woo-abandoned-cart-recovery' ) ?>
                            </div>
                            <div class="content">
                                <ul>
                                    <li><?php esc_html_e( '1. Create an account at ', 'woo-abandoned-cart-recovery' ) ?></li>
                                    <li>
                                        <a href="https://www.twilio.com" target="_blank" rel="nofollow">https://www.twilio.com,</a>
                                        <a href="https://www.nexmo.com" target="_blank" rel="nofollow">https://www.nexmo.com,</a>
                                        <a href="https://www.infobip.com" target="_blank" rel="nofollow">https://www.infobip.com</a>
										<?php esc_html_e( 'or', 'woo-abandoned-cart-recovery' ) ?>
                                        <a href="https://www.plivo.com" target="_blank" rel="nofollow">https://www.plivo.com</a>
                                    </li>
                                    <li><?php esc_html_e( '2. Login your SMS account ', 'woo-abandoned-cart-recovery' ) ?></li>
                                    <li><?php esc_html_e( '3. Copy app id, app token & phone number to input fields above. ', 'woo-abandoned-cart-recovery' ) ?></li>
                                    <li><?php esc_html_e( '4. Create an bitly\'s account at ', 'woo-abandoned-cart-recovery' ) ?>
                                        <a href="https://bitly.com/" target="_blank"
                                           rel="nofollow">https://bitly.com/</a>
                                    </li>
                                    <li><?php esc_html_e( '5. Login bitly\'s account ', 'woo-abandoned-cart-recovery' ) ?></li>
                                    <li><?php esc_html_e( '6. Go to Settings > Edit profile > Generic Access Token, enter your password & click \'Generate Token\' ', 'woo-abandoned-cart-recovery' ) ?></li>
                                    <li><?php esc_html_e( '7. Copy your access token to access token field & save settings', 'woo-abandoned-cart-recovery' ) ?></li>
                                    <li>
                                        <iframe width="560" height="315"
                                                src="https://www.youtube.com/embed/d2dAjh3BTC8?feature=oembed"
                                                frameborder="0" allow="autoplay; encrypted-media"
                                                allowfullscreen></iframe>
                                    </li>
                                    <li>
                                        <iframe width="560" height="315"
                                                src="https://www.youtube.com/embed/hkSSTrJJCwA?feature=oembed"
                                                frameborder="0" allow="autoplay; encrypted-media"
                                                allowfullscreen></iframe>
                                    </li>
                                    <li>
                                        <iframe width="560" height="315"
                                                src="https://www.youtube.com/embed/r9ubdfQvd90?feature=oembed"
                                                frameborder="0" allow="autoplay; encrypted-media"
                                                allowfullscreen></iframe>
                                    </li>
                                    <li>
                                        <iframe width="560" height="315" src="https://www.youtube.com/embed/hYfZNMiGl0w"
                                                title="YouTube video player" frameborder="0"
                                                allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
                                                allowfullscreen></iframe>
                                    </li>
                                    <li><a href="http://docs.villatheme.com/?item=woocommerce-abandoned-cart-recovery"
                                           target="_blank" rel="nofollow">
											<?php esc_html_e( 'See detail', 'woo-abandoned-cart-recovery' ); ?></a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
            <hr>

            <h4><?php esc_html_e( 'SMS for Abandoned Cart', 'woo-abandoned-cart-recovery' ) ?></h4>
            <table class="wacv-table">
				<?php
				$this->checkbox_option( 'sms_abd_cart_enable', esc_html__( 'Enable', 'woo-abandoned-cart-recovery' ) );
				$this->send_message_rules_settings( 'sms_abd_cart', true );
				?>
                <tr>
                    <td></td>
                    <td><?php esc_html_e( 'Note: SMS character limit is 160 with GSM-7 encoding & 63 with other encoding (Ex:', 'woo-abandoned-cart-recovery' );
						echo ' 👋)'; ?></td>
                </tr>
            </table>
            <hr>

            <h4><?php esc_html_e( 'SMS for Abandoned Order', 'woo-abandoned-cart-recovery' ) ?></h4>
            <table class="wacv-table">
				<?php
				$this->checkbox_option( 'sms_abd_order_enable', esc_html__( 'Enable', 'woo-abandoned-cart-recovery' ) );
				$order_stt = array(
					'wc-failed'    => 'Failed',
					'wc-cancelled' => 'Cancelled',
					'wc-pending'   => 'Pending payment',
					'wc-on-hold'   => "On hold",
				);
				$this->select_option( 'sms_order_stt', $order_stt, esc_html__( "Order status", 'woo-abandoned-cart-recovery' ), '', '', true );
				$this->send_message_rules_settings( 'sms_abd_order', true );
				?>
            </table>
        </div>
		<?php
	}

	public function show( $provider, $current ) {
		if ( $provider == $current ) {
			echo "style='display:block;'";
		} else {
			echo "style='display:none;'";
		}
	}
}
