<?xml version="1.0"?>
<!--
/**
 * Copyright © 2017 PayOne SmartRoute All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config/etc/system_file.xsd">
    <system>
        <section id="payment">
            <group id="smartroute" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>PayOne Smart Route</label>
                <comment>
                    <![CDATA[Please fill parameters below you get from your gateway provider.]]>
                </comment>
                <field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Enabled</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <comment><![CDATA[
                        <script type="text/javascript">
                            hideStsAll = function(){
                                //groups[smartroute][fields][private_key][value]
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-pg-url-value"]').closest('tr').hide();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-secret-key-value"]').closest('tr').hide();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-merchant_id"]').closest('tr').hide();                                
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-item-id-value"]').closest('tr').hide();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-recurring-payment-url-value"]').closest('tr').hide();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-api-url-value"]').closest('tr').hide();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-inquiry-url-value"]').closest('tr').hide();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-refund-url-value"]').closest('tr').hide();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-redirect-payment-url-value"]').closest('tr').hide();                                
                                jQuery('select[data-ui-id="select-groups-smartroute-fields-communication-model-value"]').closest('tr').hide();
                                jQuery('select[data-ui-id="select-groups-smartroute-fields-invoice-value"]').closest('tr').hide();
                            };

                            showStsAll = function(){
                                //groups[smartroute][fields][private_key][value]
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-pg-url-value"]').closest('tr').show();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-secret-key-value"]').closest('tr').show();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-merchant-id-value"]').closest('tr').show();                                
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-item-id-value"]').closest('tr').show();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-recurring-payment-url-value"]').closest('tr').show();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-api-url-value"]').closest('tr').show();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-inquiry-url-value"]').closest('tr').show();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-refund-url-value"]').closest('tr').show();
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-redirect-payment-url-value"]').closest('tr').show();                                
                                jQuery('select[data-ui-id="select-groups-smartroute-fields-communication-model-value"]').closest('tr').show();
                                jQuery('select[data-ui-id="select-groups-smartroute-fields-invoice-value"]').closest('tr').show();
                            };                        
                        
                            jQuery( document ).ready(function() {
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-title-value"]').val('SmartRoute');
                                jQuery('input[data-ui-id="text-groups-smartroute-fields-title-value"]').attr('readonly','readonly');
				jQuery('select[data-ui-id="select-groups-smartroute-fields-active-value"]').change(function(){
				    console.log(jQuery(this).val());
				    if(jQuery(this).val() == 1){
					showStsAll();
				    }else{
					hideStsAll();
				    }
				});
                                jQuery('select[data-ui-id="select-groups-smartroute-fields-communication-model-value"]').change(function(){
                                    console.log('communication model '+jQuery(this).val());
                                    if(jQuery(this).val() == 1){
                                        jQuery('select[data-ui-id="select-groups-smartroute-fields-method-type-value"]').closest('tr').show();
                                    }else{
                                        jQuery('select[data-ui-id="select-groups-smartroute-fields-method-type-value"]').closest('tr').hide();
                                    }
                                });
				jQuery('select[data-ui-id="select-groups-smartroute-fields-active-value"]').trigger('change');
                            });
                        </script>
                    ]]></comment>
                </field>
                <field id="sandbox" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Sandbox</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>                                
                <field id="title" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Title</label>
                </field>                                
                <field id="merchant_id" translate="label" type="text" sortOrder="31" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Merchant ID</label>
                </field>                                        
                <field id="item_id" translate="label" type="text" sortOrder="32" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Item ID</label>
                </field>                
                <field id="secret_key" translate="label" type="text" sortOrder="33" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Authentication Token (Secret Key)</label>
                </field>

                <field id="redirect_payment_url" translate="label" type="text" sortOrder="34" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Redirect Payment URL</label>
                </field>
                <field id="refund_url" translate="label" type="text" sortOrder="35" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Refund URL</label>
                </field>
                <field id="inquiry_url" translate="label" type="text" sortOrder="36" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Inquiry URL</label>
                </field>
                <field id="inquiry_in_minutes" translate="label" type="text" sortOrder="37" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Inquiry period in minutes</label>
                </field>                
                <!-- <field id="api_url" translate="label" type="text" sortOrder="37" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>API Payment URL</label>
                </field>-->
                <!--<field id="recurring_payment_url" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Recurring Payment URL</label>
                </field>-->
                <field id="communication_model" translate="label" type="select" sortOrder="38" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Communication Model</label>
                    <source_model>Sts\SmartRoute\Model\Config\CommunicationModel</source_model>
                </field>                
                <field id="method_type" translate="label" type="select" sortOrder="38" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Method Type</label>
                    <source_model>Sts\SmartRoute\Model\Config\SadadCreditModel</source_model>
                    <comment>Applicable in Direct Post only</comment>
                </field>                
                <field id="new_order_status" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>New Order Status</label>
                    <source_model>Magento\Sales\Model\Config\Source\Order\Status\Newprocessing</source_model>
                    <!--<config_path>payment/smartroute/new_order_status</config_path>-->
                </field>
                <field id="complete_order_status" translate="label" type="select" sortOrder="140" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Approved Order Status</label>
                    <source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
                    <!--<config_path>payment/smartroute/complete_order_status</config_path>-->
                </field>
                <!--<field id="cancel_order_status" translate="label" type="select" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Rejected Order Status</label>
                    <source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>                    
                </field>-->
                <field id="invoice" translate="label" type="select" sortOrder="160" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Invoice When Complete</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="allowspecific" translate="label" type="allowspecific" sortOrder="170" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Payment from Applicable Countries</label>
                    <source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
                </field>
                <field id="specificcountry" translate="label" type="multiselect" sortOrder="180" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Payment from Specific Countries</label>
                    <source_model>Magento\Directory\Model\Config\Source\Country</source_model>
                </field>
                <field id="sort_order" translate="label" type="text" sortOrder="190" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Sort Order</label>
                </field>
            </group>
        </section>
    </system>
</config>
