<?php

namespace CF7PA_Pay_Addons\Shared;

use CF7PA_Pay_Addons\Stripe\Stripe_Settings;
use CF7PA_Pay_Addons\Stripe\Stripe_Helper;
use CF7PA_Pay_Addons\Shared\Utils;

class Controls {

  public static function get_session_checkout_setting_fields($settings) {
    $default_currency = Stripe_Settings::get_setting('default_currency');
		$countries = Countries::get_countries();
		$pages_options = ['' => __('Current form page', 'accept-stripe-for-contact-form-7')];
		$pages_options += Utils::get_pages_options();

    return [
      'save_metadata' => [
        'type' => 'checkbox',
        'label' => 'Save as metadata',
        'value' => $settings['save_metadata'],
        'desc_tip' => true,
        'description' => 'Store form data directly within Stripe metadata, with a limit of up to 50 fields.'
      ],
      'payment_method_types' => [
        'type' => 'multiselect',
        'label' => 'Payment Methods',
        'value' => $settings['payment_method_types'],
        'options' => Utils::get_supported_payment_methods($default_currency),
        'desc_tip' => true,
        'description' => 'Select supported payment methods'
      ],
      'success_url' => [
        'type' => 'dropdown',
        'label' => __('Success URL', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['success_url'],
        'options' => $pages_options,
        'desc_tip' => true,
        'description' => __('Select the page to redirect to after successful payment', 'accept-stripe-for-contact-form-7'),
      ],
      'cancel_url' => [
        'type' => 'dropdown',
        'label' => __('Failed URL', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['cancel_url'],
        'options' => $pages_options,
        'desc_tip' => true,
        'description' => __('Select the page to redirect to after failed payment', 'accept-stripe-for-contact-form-7'),
      ],
      'submit_type' => [
        'type' => 'dropdown',
        'label' => 'Submit button type',
        'value' => $settings['submit_type'],
        'options' => [
          'auto' => esc_html__('auto', 'accept-stripe-for-contact-form-7'),
          'pay' => esc_html__('pay', 'accept-stripe-for-contact-form-7'),
          'book' => esc_html__('book', 'accept-stripe-for-contact-form-7'),
          'donate' => esc_html__('donate', 'accept-stripe-for-contact-form-7'),
        ],
      ],
      'billing_address_collection' => [
        'type' => 'checkbox',
        'label' => esc_html__('Billing address required', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['billing_address_collection'],
      ],
      'allow_promotion_codes' => [
        'type' => 'checkbox',
        'label' => esc_html__('Enable promotion', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['allow_promotion_codes'],
      ],
      'automatic_tax' => [
        'type' => 'checkbox',
        'label' => esc_html__('Enable automatic taxes', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['automatic_tax'],
      ],
      'tax_behavior' => [
        'type' => 'dropdown',
        'label' =>  esc_html__('Tax Behaviors', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['tax_behavior'],
        'options' => [
          'inclusive' => esc_html__('Inclusive', 'accept-stripe-for-contact-form-7'),
          'exclusive' => esc_html__('Exclusive', 'accept-stripe-for-contact-form-7'),
        ],
      ],
      'phone_number_collection' => [
        'type' => 'checkbox',
        'label' => esc_html__('Phone number required', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['phone_number_collection'],
      ],
      'terms_of_service' => [
        'type' => 'checkbox',
        'label' => esc_html__('Enable terms of service', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['terms_of_service'],
      ],
      'shipping_address_collection' => [
        'type' => 'multiselect',
        'label' =>  esc_html__('Shipping address countries', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['shipping_address_collection'],
        'options' => $countries,
      ],
    ];
  }

  public static function get_payment_type_condition_fields($settings) {
    return [
      'payment_type_condition_field' => [
        'type' => 'text',
        'label' => esc_html__('Condition Field', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['payment_type_condition_field'],
        'placeholder' => "[some-field-name]",
        'description' => esc_html__('This field is decide to use subscrition or not. such as [is-subscription]', 'accept-stripe-for-contact-form-7'),
      ],
      'payment_type_condition_operation' => [
        'type' => 'dropdown',
        'label' =>  esc_html__('Condition Operation', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['payment_type_condition_operation'],
        'options' => [
          'checked' => esc_html__('Checked', 'accept-stripe-for-contact-form-7'),
          'equalto' => esc_html__('Equal to', 'accept-stripe-for-contact-form-7'),
          'empty' => esc_html__('Empty', 'accept-stripe-for-contact-form-7'),
          'notchecked' => esc_html__('Not checked', 'accept-stripe-for-contact-form-7'),
          'notempty' => esc_html__('Not empty', 'accept-stripe-for-contact-form-7'),
          'notequalto' => esc_html__('Not equal to', 'accept-stripe-for-contact-form-7'),
        ],
      ],
      'payment_type_condition_value' => [
        'type' => 'text',
        'label' => esc_html__('Condition Value', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['payment_type_condition_value'],
      ],
    ];
  }

  public static function get_one_time_pricing_fields($settings) {
		$currencies = Utils::get_currencies_options();
    return [
      'onetime_currency' => [
        'type' => 'dropdown',
        'label' => esc_html__('Currency', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['onetime_currency'],
        'options' => $currencies,
      ],
      'onetime_amount_field' => [
        'type' => 'text',
        'label' => esc_html__('Amount Field', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['onetime_amount_field'],
        'placeholder' => esc_html__('19.9 or [your-amount]', 'accept-stripe-for-contact-form-7'), 
        'description' => __('a fixed amount or a form field such as [amount]', 'accept-stripe-for-contact-form-7'),
      ],
      'onetime_quantity_field' => [
        'type' => 'text',
        'label' => esc_html__('Quantity Field', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['onetime_quantity_field'],
        'description' => __('a fixed quantity or a form field such as [quantity]', 'accept-stripe-for-contact-form-7'),
      ],
      'onetime_product_name_field' => [
        'type' => 'text',
        'label' => esc_html__('Product Name Field', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['onetime_product_name_field'],
        'description' => __('a fixed value or including a form field such as [product-name]', 'accept-stripe-for-contact-form-7'),
      ],
      'onetime_product_desc_field' => [
        'type' => 'text',
        'label' => esc_html__('Product Description Field', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['onetime_product_desc_field'],
        'description' => __('a fixed value or including a form field such as [product-desc]', 'accept-stripe-for-contact-form-7'),
      ],
    ];
  }

  public static function get_sub_pricing_fields($settings) {
		$currencies = Utils::get_currencies_options();
    return [
      'sub_currency' => [
        'type' => 'dropdown',
        'label' => esc_html__('Currency', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['sub_currency'],
        'options' => $currencies,
      ],
      'sub_amount_field' => [
        'type' => 'text',
        'label' => esc_html__('Amount Field', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['sub_amount_field'],
        'placeholder' => "19.9 or [amount]",
        'description' => esc_html__('a fixed value or a form field such as [amount]', 'accept-stripe-for-contact-form-7'),
      ],
      'sub_quantity_field' => [
        'type' => 'text',
        'label' => esc_html__('Quantity Field', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['sub_quantity_field'],
        'placeholder' => "1 or [quantity]",
        'description' => esc_html__('a fixed value or a form field such as [quantity]', 'accept-stripe-for-contact-form-7'),
      ],
      'sub_interval_count_field' => [
        'type' => 'text',
        'label' => esc_html__('Number of intervals Field', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['sub_interval_count_field'],
        'placeholder' => "3 or [interval-count]",
        'description' => esc_html__('a fixed value or a form field such as [interval-count]', 'accept-stripe-for-contact-form-7'),
      ],
      'sub_interval_field' => [
        'type' => 'text',
        'label' => esc_html__('Recurring frequency Field', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['sub_interval_field'],
        'placeholder' => "month or [mouth]",
        'description' => esc_html__('Either day, week, month or year or any specified field such as [interval]', 'accept-stripe-for-contact-form-7'),
      ],
      'sub_product_name_field' => [
        'type' => 'text',
        'label' => esc_html__('Product Name Field', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['sub_product_name_field'],
        'description' => __('a fixed value or a form field such as [product-name]', 'accept-stripe-for-contact-form-7'),
      ],
      'sub_product_desc_field' => [
        'type' => 'text',
        'label' => esc_html__('Product Description Field', 'accept-stripe-for-contact-form-7'),
        'value' => $settings['sub_product_desc_field'],
        'description' => __('a fixed value or a form field such as [product-desc]', 'accept-stripe-for-contact-form-7'),
      ],
    ];
  }
}