<?php

/**
 * Quote settings detail array.
 */

namespace EnEchoQuoteSettings;

if (!class_exists('EnEchoQuoteSettings')) {

    class EnEchoQuoteSettings
    {

        /**
         * Quote Settings Html
         * @return array
         */
        static public function Load()
        {

            $en_settings = json_decode(EN_ECHO_SET_QUOTE_SETTINGS, true);
            $number_of_options = [];
            if (isset($en_settings['enable_carriers']) && !empty($en_settings['enable_carriers'])) {
                for ($c = 1; $c <= count($en_settings['enable_carriers']); $c++) {
                    $number_of_options[$c] = __($c, $c);
                }
            }

            if (get_option('en_quote_settings_show_delivery_estimate_echo') == 'yes') {
                update_option('en_quote_settings_delivery_estimate_options_echo', 'delivery_days');
                delete_option('en_quote_settings_show_delivery_estimate_echo');
            }

            // Cuttoff Time
            $echo_disable_cutt_off_time_ship_date_offset = "";
            $echo_cutt_off_time_package_required = "";

            //  Check the cutt of time & offset days plans for disable input fields
            $echo_action_cutOffTime_shipDateOffset = apply_filters('echo_plans_suscription_and_features', 'order_cutt_off_time');
            if (is_array($echo_action_cutOffTime_shipDateOffset)) {
                $echo_disable_cutt_off_time_ship_date_offset = "disabled_me";
                $echo_cutt_off_time_package_required = apply_filters('echo_plans_notification_link', $echo_action_cutOffTime_shipDateOffset);
            }

            $disable_hold_at_terminal = $hold_at_terminal_package_required = "";

            $action_hold_at_terminal = apply_filters('echo_plans_suscription_and_features', 'hold_at_terminal');
            if (is_array($action_hold_at_terminal)) {
                $disable_hold_at_terminal = "disabled_me";
                $hold_at_terminal_package_required = apply_filters('echo_plans_notification_link', $action_hold_at_terminal);
            }

            $ltl_enable = get_option('en_plugins_return_LTL_quotes');
            $weight_threshold_class = $ltl_enable == 'yes' ? 'show_en_weight_threshold_lfq' : 'hide_en_weight_threshold_lfq';
            $weight_threshold = get_option('en_weight_threshold_lfq');
            $weight_threshold = isset($weight_threshold) && $weight_threshold > 0 ? $weight_threshold : 150;

            // Checkout Error Message
            $custom_error_selection = get_option('en_quote_settings_checkout_error_message_echo');
            if (empty($custom_error_selection)) {
                update_option('en_quote_settings_option_select_when_unable_retrieve_shipping_echo', 'prevent', true);
                update_option('en_quote_settings_checkout_error_message_echo', 'There are no shipping methods available for the address provided. Please check the address.', true);
            }
            
            $settings = array(
                'en_quote_settings_start_echo' => [
                    'name' => __('', 'woocommerce-settings-echo'),
                    'type' => 'title',
                    'id' => 'en_quote_settings_echo',
                ],
                /**
                 * ==================================================================
                 * Rating Method Start
                 * ==================================================================
                 */
                'en_quote_settings_rating_method_echo' => [
                    'name' => __('Rating Method ', 'woocommerce-settings-echo'),
                    'type' => 'select',
                    'desc' => __('Displays only the cheapest returned Rate.', 'woocommerce-settings-echo'),
                    'id' => 'en_quote_settings_rating_method_echo',
                    'options' => [
                        'Cheapest' => __('Cheapest', 'Cheapest'),
                        'cheapest_options' => __('Cheapest Options', 'cheapest_options'),
                        'average_rate' => __('Average Rate', 'average_rate')
                    ]
                ],
                'en_quote_settings_number_of_options_echo' => [
                    'name' => __('Number Of Options ', 'woocommerce-settings-echo'),
                    'type' => 'select',
                    'default' => '3',
                    'desc' => __('Number of options to display in the shopping cart.', 'woocommerce-settings-echo'),
                    'id' => 'en_quote_settings_number_of_options_echo',
                    'options' => $number_of_options
                ],
                'en_quote_settings_custom_label_echo' => [
                    'name' => __('Label As ', 'woocommerce-settings-echo'),
                    'type' => 'text',
                    'desc' => __('What the user sees during checkout, e.g "Freight" leave blank to display the carrier name.', 'woocommerce-settings-echo'),
                    'id' => 'en_quote_settings_custom_label_echo'
                ],
                'en_shipping_methods_do_not_sort_by_price_echo' => [
                    'name' => __("Don't sort shipping methods by price  ", 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'desc' => 'By default, the plugin will sort all shipping methods by price in ascending order.',
                    'id' => 'en_shipping_methods_do_not_sort_by_price_echo'
                ],
                /**
                 * ==================================================================
                 * Rating Method End
                 * ==================================================================
                 */

                //** Start Delivery Estimate Options - Cuttoff Time
                 'delivery_estimate_options_echo' => array(
                    'name' => __('Delivery Estimate Options ', 'woocommerce-settings-en_woo_addons_packages_quotes'),
                    'type' => 'text',
                    'class' => 'hidden',
                    'id' => 'delivery_estimate_options_echo'
                ),
                'en_quote_settings_delivery_estimate_options_echo' => array(
                    'name' => '',
                    'type' => 'radio',
                    'default' => 'dont_show_estimates',
                    'options' => array(
                        'dont_show_estimates' => __("Don't display delivery estimates.", 'woocommerce'),
                        'delivery_days' => __("Display estimated number of days until delivery.", 'woocommerce'),
                        'delivery_date' => __("Display estimated delivery date.", 'woocommerce'),
                    ),
                    'id' => 'en_quote_settings_delivery_estimate_options_echo',
                    'class' => 'freightview_lfq_dont_show_estimate_option',
                ),
                //** End Delivery Estimate Options

                //**Start: Cut Off Time & Ship Date Offset
                'en_quote_settings_cutt_off_time_ship_date_offset_echo' => array(
                    'name' => __('Cut Off Time & Ship Date Offset ', 'woocommerce-settings-en_woo_addons_packages_quotes'),
                    'type' => 'text',
                    'class' => 'hidden',
                    'desc' => $echo_cutt_off_time_package_required,
                    'id' => 'en_quote_settings_cutt_off_time_ship_date_offset_echo'
                ),
                'en_quote_settings_order_cut_off_time_echo' => array(
                    'name' => __('Order Cut Off Time ', 'woocommerce-settings-priority-one_lfq_freight_freight_orderCutoffTime'),
                    'type' => 'text',
                    'placeholder' => '-- : -- --',
                    'desc' => 'Enter the cut off time (e.g. 2:00) for orders. Orders placed after this time will be quoted as shipping the next business day.',
                    'id' => 'en_quote_settings_order_cut_off_time_echo',
                    'class' => $echo_disable_cutt_off_time_ship_date_offset,
                ),
                'en_quote_settings_shipment_offset_days_echo' => array(
                    'name' => __('Fulfillment Offset Days ', 'woocommerce-settings-priority-one_lfq_freight_shipment_offset_days'),
                    'type' => 'text',
                    'desc' => 'The number of days the ship date needs to be moved to allow for the processing of the order.',
                    'placeholder' => 'Fulfillment Offset Days, e.g. 2',
                    'id' => 'en_quote_settings_shipment_offset_days_echo',
                    'class' => $echo_disable_cutt_off_time_ship_date_offset,
                ),
                'en_quote_settings_all_shipment_days_echo' => array(
                    'name' => __("What days do you ship orders?", 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'desc' => 'Select All',
                    'class' => "all_shipment_days_echo_lfq $echo_disable_cutt_off_time_ship_date_offset",
                    'id' => 'en_quote_settings_all_shipment_days_echo'
                ),
                'en_quote_settings_monday_shipment_day_echo' => array(
                    'name' => __("", 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'desc' => 'Monday',
                    'class' => "echo_shipment_day $echo_disable_cutt_off_time_ship_date_offset",
                    'id' => 'en_quote_settings_monday_shipment_day_echo'
                ),
                'en_quote_settings_tuesday_shipment_day_echo' => array(
                    'name' => __("", 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'desc' => 'Tuesday',
                    'class' => "echo_shipment_day $echo_disable_cutt_off_time_ship_date_offset",
                    'id' => 'en_quote_settings_tuesday_shipment_day_echo'
                ),
                'en_quote_settings_wednesday_shipment_day_echo' => array(
                    'name' => __("", 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'desc' => 'Wednesday',
                    'class' => "echo_shipment_day $echo_disable_cutt_off_time_ship_date_offset",
                    'id' => 'en_quote_settings_wednesday_shipment_day_echo'
                ),
                'en_quote_settings_thursday_shipment_day_echo' => array(
                    'name' => __("", 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'desc' => 'Thursday',
                    'class' => "echo_shipment_day $echo_disable_cutt_off_time_ship_date_offset",
                    'id' => 'en_quote_settings_thursday_shipment_day_echo'
                ),
                'en_quote_settings_friday_shipment_day_echo' => array(
                    'name' => __("", 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'desc' => 'Friday',
                    'class' => "echo_shipment_day $echo_disable_cutt_off_time_ship_date_offset",
                    'id' => 'en_quote_settings_friday_shipment_day_echo'
                ),
                // Don't remove the section below as it is used in RAD addon
                'en_quote_settings_show_delivery_estimate_echo' => array(
                    'name' => __('', 'woocommerce-settings-echo'),
                    'type' => 'title',
                    'title' => __('', 'woocommerce'),
                    'id' => 'echo_lfq_show_delivery_estimates',
                ),
                //**End: Cut Off Time & Ship Date Offset

                'residential_delivery_options_label' => [
                    'name' => __('Residential Delivery', 'woocommerce-settings-echo'),
                    'type' => 'text',
                    'class' => 'hidden',
                    'id' => 'en_quote_settings_residential_label_echo'
                ],
                'en_quote_settings_residential_delivery_echo' => [
                    'name' => __('', 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'desc' => 'Always quote as residential delivery.',
                    'id' => 'en_quote_settings_residential_delivery_echo'
                ],
                /**
                 * ==================================================================
                 * Auto-detect residential addresses notification
                 * ==================================================================
                 */
                'avaibility_auto_residential' => [
                    'name' => __('', 'woocommerce-settings-echo'),
                    'type' => 'text',
                    'class' => 'hidden',
                    'desc' => "Click <a target='_blank' href='" . EN_ECHO_RAD_URL . "'>here</a> to add the Auto-detect residential addresses module. (<a target='_blank' href='https://eniture.com/woocommerce-residential-address-detection/#documentation'>Learn more</a>)",
                    'id' => 'en_quote_settings_availability_auto_residential_echo'
                ],
                'liftgate_delivery_options_label' => [
                    'name' => __('Lift Gate Delivery ', 'woocommerce-settings-echo'),
                    'type' => 'text',
                    'class' => 'hidden',
                    'id' => 'en_quote_settings_liftgate_label_echo'
                ],
                'en_quote_settings_liftgate_delivery_echo' => [
                    'name' => __('', 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'class' => 'liftgate_accessorial_action',
                    'desc' => 'Always quote lift gate delivery.',
                    'id' => 'en_quote_settings_liftgate_delivery_echo',
                ],
                'echo_liftgate_delivery_as_option' => [
                    'name' => __('', 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'class' => 'liftgate_accessorial_action',
                    'desc' => __('Offer lift gate delivery as an option.', 'woocommerce-settings-echo'),
                    'id' => 'echo_liftgate_delivery_as_option',
                ],
                'en_woo_addons_liftgate_with_auto_residential' => [
                    'name' => __('', 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'class' => 'liftgate_accessorial_action en_woo_addons_liftgate_with_auto_residential_echo',
                    'desc' => __('Always include lift gate delivery when a residential address is detected.', 'woocommerce-settings-echo'),
                    'id' => 'en_woo_addons_liftgate_with_auto_residential',
                ],
                /**
                 * ==================================================================
                 * Liftgate notification
                 * ==================================================================
                 */
                'avaibility_lift_gate' => [
                    'name' => __('', 'woocommerce-settings-echo'),
                    'type' => 'text',
                    'class' => 'hidden',
                    'desc' => "Click <a target='_blank' href='" . EN_ECHO_RAD_URL . "'>here</a> to add the Residential Address Detection module. (<a target='_blank' href='https://eniture.com/woocommerce-residential-address-detection/#documentation'>Learn more</a>)",
                    'id' => 'en_quote_settings_availability_liftgate_echo'
                ],

                // Hold At Terminal
                'en_quote_settings_hold_at_terminal_echo' => array(
                        'name' => __('Hold At Terminal', 'woocommerce-settings-fedex_small'),
                        'type' => 'checkbox',
                        'desc' => 'Offer Hold At Terminal as an option ' . $hold_at_terminal_package_required,
                        'class' => $disable_hold_at_terminal,
                        'id' => 'en_quote_settings_hold_at_terminal_echo',
                ),
                'en_quote_settings_hold_at_terminal_fee_echo' => array(
                    'name' => __('', 'ground-transit-settings-ground_transit'),
                    'type' => 'text',
                    'desc' => 'Adjust the price of the Hold At Terminal option.Enter an amount, e.g. 3.75, or a percentage, e.g. 5%.  Leave blank to use the price returned by the carrier.',
                    'class' => $disable_hold_at_terminal,
                    'id' => 'en_quote_settings_hold_at_terminal_fee_echo',
                ),

                'en_quote_settings_handling_unit_echo' => array(
                    'name' => __('Handling Unit ', 'woocommerce-settings-echo'),
                    'type' => 'text',
                    'class' => 'hidden',
                    'id' => 'en_quote_settings_handling_unit_echo'
                ),
                'en_quote_settings_handling_unit_weight_echo' => [
                    'name' => __('Weight of Handling Unit ', 'woocommerce-settings-echo'),
                    'type' => 'text',
                    'desc' => 'Enter in pounds the weight of your pallet, skid, crate or other type of handling unit.',
                    'id' => 'en_quote_settings_handling_unit_weight_echo',
                ],
                'en_quote_settings_max_weight_handling_unit_echo' => [
                    'name' => __('Maximum Weight per Handling Unit ', 'woocommerce-settings-echo'),
                    'type' => 'text',
                    'desc' => 'Enter in pounds the weight of your pallet, skid, crate or other type of handling unit.',
                    'id' => 'en_quote_settings_max_weight_handling_unit_echo',
                ],
                'en_quote_settings_handling_fee_echo' => [
                    'name' => __('Handling Fee / Markup ', 'woocommerce-settings-echo'),
                    'type' => 'text',
                    'desc' => 'Amount excluding tax. Enter an amount, e.g 3.75, or a percentage, e.g, 5%. Leave blank to disable.',
                    'id' => 'en_quote_settings_handling_fee_echo'
                ],
                'en_quote_settings_enable_logs_echo' => [
                    'name' => __("Enable Logs  ", 'woocommerce-settings-dayross'),
                    'type' => 'checkbox',
                    'desc' => 'When checked, the Logs page will contain up to 25 of the most recent transactions.',
                    'id' => 'en_quote_settings_enable_logs_echo'
                ],    
                'en_quote_settings_own_arrangment_echo' => [
                    'name' => __('Allow For Own Arrangement ', 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'desc' => __('<span class="description">Adds an option in the shipping cart for users to indicate that they will make and pay for their own LTL shipping arrangements.</span>', 'woocommerce-settings-wwe_quetes'),
                    'id' => 'en_quote_settings_own_arrangment_echo'
                ],
                'en_quote_settings_text_for_own_arrangment_echo' => [
                    'name' => __('Text For Own Arrangement ', 'woocommerce-settings-echo'),
                    'type' => 'text',
                    'desc' => '',
                    'default' => "I'll arrange my own freight",
                    'id' => 'en_quote_settings_text_for_own_arrangment_echo'
                ],
                'en_quote_settings_allow_other_plugins_echo' => [
                    'name' => __('Show WooCommerce Shipping Options ', 'woocommerce-settings-echo'),
                    'type' => 'select',
                    'default' => 'yes',
                    'desc' => __('Enabled options on WooCommerce Shipping page are included in quote results.', 'woocommerce-settings-echo'),
                    'id' => 'en_quote_settings_allow_other_plugins_echo',
                    'options' => [
                        'yes' => __('YES', 'YES'),
                        'no' => __('NO', 'NO'),
                    ]
                ],
                'en_plugins_return_LTL_quotes' => [
                    'name' => __('Return LTL quotes when an order parcel shipment weight exceeds the weight threshold', 'woocommerce-settings-echo'),
                    'type' => 'checkbox',
                    'desc' => '<span class="description" >When checked, the LTL Freight Quote will return quotes when an order’s total weight exceeds the weight threshold (the maximum permitted by WWE and UPS), even if none of the products have settings to indicate that it will ship LTL Freight. To increase the accuracy of the returned quote(s), all products should have accurate weights and dimensions. </span>',
                    'id' => 'en_plugins_return_LTL_quotes'
                ],
                // Weight threshold for LTL freight
                'en_weight_threshold_lfq' => [
                    'name' => __('Weight threshold for LTL Freight Quotes ', 'woocommerce-settings-echo'),
                    'type' => 'text',
                    'default' => $weight_threshold,
                    'class' => $weight_threshold_class,
                    'id' => 'en_weight_threshold_lfq'
                ],
                'en_suppress_parcel_rates' => array(
                    'name' => __("", 'woocommerce-settings-echo'),
                    'type' => 'radio',
                    'default' => 'display_parcel_rates',
                    'options' => array(
                        'display_parcel_rates' => __("Continue to display parcel rates when the weight threshold is met.", 'woocommerce'),
                        'suppress_parcel_rates' => __("Suppress parcel rates when the weight threshold is met.", 'woocommerce'),
                    ),
                    'class' => 'en_suppress_parcel_rates',
                    'id' => 'en_suppress_parcel_rates',
                ),
                /**
                 * ==================================================================
                 * When plugin fail return to rate
                 * ==================================================================
                 */
                'en_quote_settings_clear_both_echo' => [
                    'title' => __('', 'woocommerce'),
                    'name' => __('', 'woocommerce-settings-echo'),
                    'desc' => '',
                    'id' => 'en_quote_settings_clear_both_echo',
                    'css' => '',
                    'type' => 'title',
                ],
                // Backup rates
                'en_quote_settings_unable_retrieve_shipping_echo' => [
                    'name' => __('Checkout options if the plugin fails to return a rate ', 'woocommerce-settings-echo'),
                    'type' => 'text',
                    'class' => 'hidden',
                    'id' => 'en_quote_settings_unable_retrieve_shipping_echo',
                ],
                'enable_backup_rates_echo' => array(
                    'name' => __('', 'woocommerce-settings-echo-quotes'),
                    'type' => 'checkbox',
                    'desc' => __('Present the user with a backup shipping rate.', 'woocommerce-settings-echo-quotes'),
                    'id' => 'enable_backup_rates_echo',
                ),
                'echo_backup_rates_label' => array(
                    'name' => __('', 'woocommerce-settings-echo-quotes'),
                    'type' => 'text',
                    'desc' => 'Label for backup shipping rate (Maximum of 50 characters).',
                    'id' => 'echo_backup_rates_label'
                ),
                'echo_backup_rates_category' => array(
                    'name' => __('', 'woocommerce-settings-echo-quotes'),
                    'type' => 'radio',
                    'default' => 'fixed_rate',
                    'options' => array(
                        'fixed_rate' => __('', 'woocommerce'),
                        'percentage_of_cart_price' => __('', 'woocommerce'),
                        'function_of_weight' => __('', 'woocommerce'),
                    ),
                    'id' => 'echo_backup_rates_category',
                ),
                'echo_backup_rates_carrier_fails_to_return_response' => array(
                    'name' => __('', 'woocommerce-settings-echo-quotes'),
                    'type' => 'checkbox',
                    'desc' => __('Display the backup rate if the carrier fails to return a response.', 'woocommerce-settings-echo-quotes'),
                    'id' => 'echo_backup_rates_carrier_fails_to_return_response',
                ),
                'echo_backup_rates_carrier_returns_error' => array(
                    'name' => __('', 'woocommerce-settings-echo-quotes'),
                    'type' => 'checkbox',
                    'desc' => __('Display the backup rate if the carrier returns an error.', 'woocommerce-settings-echo-quotes'),
                    'id' => 'echo_backup_rates_carrier_returns_error',
                ),
                'echo_backup_rates_display' => array(
                    'name' => __('', 'woocommerce-settings-echo-quotes'),
                    'type' => 'radio',
                    'default' => 'no_other_rates',
                    'options' => array(
                        'no_plugin_rates' => __('Display the backup rate if the plugin fails to return a rate.', 'woocommerce'),
                        'no_other_rates' => __('Display the backup rate only if no rates, from any shipping method, are presented.', 'woocommerce'),
                    ),
                    'id' => 'echo_backup_rates_display',
                ),
                'en_quote_settings_end_echo' => [
                    'type' => 'sectionend',
                    'id' => 'en_quote_settings_end_echo'
                ],
            );

            return $settings;
        }

    }

}