<?php
/**
 * pageSettingsFields.php
 *
 * @since      1.0.0
 * @author     alfiopiccione <alfio.piccione@gmail.com>
 * @license    http://opensource.org/licenses/gpl-2.0.php GPL v2
 *
 * Copyright (C) 2025 POP
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

if (! defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

use WcElectronInvoice\Admin\Settings\OptionPage;
use WcElectronInvoice\InvoiceApi;
use WcElectronInvoice\Providers\TaxesQuery;
use WcElectronInvoice\WooCommerce\Fields\GeneralFields;
use function WcElectronInvoice\Functions\checkOptions;

$page = \WcElectronInvoice\Admin\Settings\OptionPage::init();
$tabs = $this->tabs;

$active  = $this->checkPageTab($tabs);
$section = isset($tabs[$active]['section_id']) ? $tabs[$active]['section_id'] : '';
// Invoice
$invoiceNumber         = $page->getOptions('number_next_invoice');
$invoiceNumberDisabled = isset($invoiceNumber) && '' !== $invoiceNumber ? 'disabled' : '';
// Receipt
$receiptNumber         = $page->getOptions('number_next_receipt');
$receiptNumberDisabled = isset($receiptNumber) && '' !== $receiptNumber ? 'disabled' : '';
// Credit note
$creditNoteNumber                = $page->getOptions('number_next_credit_note');
$creditNoteNumberDisabled        = isset($creditNoteNumber) && '' !== $creditNoteNumber ? 'disabled' : '';
$creditNoteReceiptNumber         = $page->getOptions('number_next_credit_note_receipt');
$creditNoteReceiptNumberDisabled = isset($creditNoteReceiptNumber) && '' !== $creditNoteReceiptNumber ? 'disabled' : '';
$level                           = \WcElectronInvoice\Wizard::popGetUserLevel();
$premiumSettingsDisabled         = ! \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic');
$premiumFieldAttrs               = $premiumSettingsDisabled ? array(
    'disabled' => 'disabled',
    'readonly' => 'readonly',
) : array();
$paidOnlyBadge                   = sprintf(
    ' <span class="pop-premium-badge">%s</span>',
    esc_html__('Paid only', WC_EL_INV_TEXTDOMAIN)
);

switch ($section) {
    // General Tab
    case 'setting_section_general' :
        $this->sectionArgs['wc_el_inv_settings'] = array(
            'section_id'       => 'setting_section_general',
            'section_title'    => '', //esc_html__('General options', WC_EL_INV_TEXTDOMAIN),
            'section_callback' => function () {
                $taxRegime  = get_option("wc_el_inv-general_store_tax_regime", false);
                $uidOption  = (int)get_option('pop_account_user_id', false);
                $licenseKey = OptionPage::init()->getOptions('license_key') ?? null;

                if ($licenseKey && $uidOption && $uidOption > 0) :

                    if (in_array($taxRegime, ['RF19', 'RF02'])) {
                        $taxProviderWC     = TaxesQuery::instance()->getTaxProvider('woocommerce');
                        $taxProviderPMPro  = TaxesQuery::instance()->getTaxProvider('pmpro');
                        $taxProviderCozmos = TaxesQuery::instance()->getTaxProvider('cozmoslabspms');

                        $taxEnable = false;
                        if (! empty($taxProviderWC) && 'yes' === $taxProviderWC->is_tax_enabled()) {
                            $taxEnable = true;
                        } elseif (! empty($taxProviderPMPro) && 'yes' === $taxProviderPMPro->is_tax_enabled()) {
                            $taxEnable = true;
                        } elseif (! empty($taxProviderCozmos) && 'yes' === $taxProviderCozmos->is_tax_enabled()) {
                            $taxEnable = true;
                        }
                        if ($taxEnable) {
                            echo sprintf('<div style="margin:0 8px 10px;" class="pop-notice notice-error"><p><span class="dashicons dashicons-info"></span> %s</p></div>',
                                esc_html__('For the selected tax regimes (RF19 – Forfettario, RF02 – Minimi), taxes must be disabled in your store settings. If taxes remain enabled, the system will generate orders that are inconsistent with the selected tax regime, which may lead to invalid invoices.',
                                    WC_EL_INV_TEXTDOMAIN)
                            );
                        }
                    }

                    echo sprintf('<div style="margin:0 8px;" class="pop-notice notice-info"><p><span class="dashicons dashicons-info"></span> %s - <a target="_blank" href="https://popapi.io/ticket-support/">%s popapi.io</a></p></div>',
                        esc_html__('If you need to modify this data, please go to the customer area and open a ticket.',
                            WC_EL_INV_TEXTDOMAIN),
                        esc_html_x('Support', 'help_link', WC_EL_INV_TEXTDOMAIN)
                    );
                endif;
            },
            'section_page'     => 'wc_el_inv-options-page',
        );
        $this->fieldsArgs[]                      = array(
            'field_id'       => 'license_key_options_fields',
            'field_title'    => esc_html__('Api Key', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'id'          => 'wc_el_inv-settings-license_key',
                    'name'        => 'wc_el_inv-settings-license_key',
                    'description' => '(*) ' . esc_html__('Before changing the API key, create another key from the API panel of your account.',
                            WC_EL_INV_TEXTDOMAIN),
                    'attrs'       => array(
                        'readonly' => 'readonly',
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_general',
            'field_args'     => array('class' => 'license_key hidden'),
        );
        $this->fieldsArgs[]                      = array(
            'field_id'       => 'key_options_fields',
            'field_title'    => esc_html__('License key confirmation', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\KeyField(array(
                    'id'          => 'wc_el_inv-settings-key',
                    'name'        => 'wc_el_inv-settings-key',
                    'description' => esc_html__('NB: re-enter the license key for confirmation.',
                        WC_EL_INV_TEXTDOMAIN),
                    'attrs'       => array(
                        'readonly' => 'readonly',
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_general',
            'field_args'     => array('class' => 'license_key hidden'),
        );
        $this->fieldsArgs[]                      = array(
            'field_id'       => 'secret_key_options_fields',
            'field_title'    => esc_html__('Api Key', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => 'WcElectronInvoice\\Admin\\Settings\\Fields\\KeyField::secretKey',
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_general',
            'field_args'     => array('class' => 'secret_key hidden'),
        );
        // POP account disconnect -------------------- /
        $this->fieldsArgs[] = array(
            'field_id'       => 'pop_cloud_disconnect',
            'field_title'    => '',
            'field_callback' => function () {
                $uidOption  = (int)get_option('pop_account_user_id', false);
                $licenseKey = OptionPage::init()->getOptions('license_key') ?? null;

                if ($uidOption) {
                    echo '<div class="GeneralInvoiceData_output_fields">';
                    $disconnect = esc_url_raw(add_query_arg([
                        'page'       => 'wc_el_inv-options-page',
                        'tab'        => 'general',
                        'disconnect' => 'true',
                    ], admin_url('/admin.php')));

                    $license_refresh_url = esc_url_raw(add_query_arg([
                        'page'                => 'wc_el_inv-options-page',
                        'tab'                 => 'general',
                        'forced_level_update' => '1',
                    ], admin_url('/admin.php')));

                    $country        = strtoupper(trim((string)GeneralFields::getGeneralInvoiceOptionCountryState()));
                    $taxRegime      = include \WcElectronInvoice\Plugin::getPluginDirPath('/inc/wc/taxRegime.php');
                    $regime         = get_option("wc_el_inv-general_store_tax_regime", false);
                    $storeTaxRegime = $regime;
                    if ($regime && $country && is_array($taxRegime)) {
                        $regimeLabel        = null;
                        $taxRegimeByCountry = $taxRegime[$country] ?? null;
                        if (is_array($taxRegimeByCountry) &&
                            isset($taxRegimeByCountry[$regime])
                        ) {
                            $regimeLabel = $taxRegimeByCountry[$regime];
                        }

                        if (is_string($regimeLabel) && '' !== $regimeLabel) {
                            $storeTaxRegime = $regime . ' - ' . $regimeLabel;
                        }
                    }

                    $name    = get_option("wc_el_inv-general_store_your_name", '');
                    $surname = get_option("wc_el_inv-general_store_your_surname", '');
                    $company = get_option("wc_el_inv-general_store_company_name", '');
                    $vat     = get_option("wc_el_inv-general_store_vat_number", '');

                    echo '<div class="pop_account_panel">';
                    echo '<p style="margin-bottom:5px;font-size:13px;">';
                    // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                    echo sprintf(esc_html__('You are logged in as %s %s (%s - %s)', WC_EL_INV_TEXTDOMAIN), $name,
                        $surname, $company, $vat);
                    echo '</p>';

                    echo '<p style="margin-bottom:5px;font-size:13px;">';
                    $licenseKey = OptionPage::init()->getOptions('license_key') ?? null;
                    echo sprintf('%s: <code>%s</code>', esc_html__('Active API key', WC_EL_INV_TEXTDOMAIN),
                        $licenseKey);
                    echo '</p>';

                    echo '<p style="margin-bottom:25px;font-size:13px;">';
                    // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                    echo sprintf('<a id="change_api_key" href="javascript:;">%s</a> %s',
                        esc_html__('Click here', WC_EL_INV_TEXTDOMAIN),
                        esc_html__('if you want to change the API key', WC_EL_INV_TEXTDOMAIN));
                    echo '</p>';

                    $currentEnv = get_option('wc_el_inv_environment', 'live');
                    echo '<p class="wc_el_inv_environment_div">';
                    echo '<label for="wc_el_inv_environment"><b>' . esc_html__('Environment:',
                            WC_EL_INV_TEXTDOMAIN) . ' </b></label>';
                    echo '<select id="wc_el_inv_environment" name="wc_el_inv_environment">';
                    echo '<option value="live" ' . selected($currentEnv, 'live', false) . '>' . esc_html__('Live',
                            WC_EL_INV_TEXTDOMAIN) . '</option>';
                    echo '<option value="sandbox" ' . selected($currentEnv, 'sandbox',
                            false) . '>' . esc_html__('Sandbox', WC_EL_INV_TEXTDOMAIN) . '</option>';
                    echo '</select>';
                    echo '<span class="wc_el_inv_environment_button_wrap"><button class="button button-secondary" type="submit" id="save_environment">' . esc_html__('Save',
                            WC_EL_INV_TEXTDOMAIN) . '</button></span>';
                    echo '</p>';

                    // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                    echo '<div class="pop_account_panel_actions" style="display: flex">';
                    echo sprintf('<a id="button_pop_cloud_license_refresh" class="button button-secondary" style="margin-right: 10px" href="%s">%s</a>',
                        esc_url($license_refresh_url),
                        esc_html__('Update license info', WC_EL_INV_TEXTDOMAIN)
                    );
                    echo sprintf('<a id="button_pop_cloud_disconnect" class="button button-primary" href="%s"><span class="dashicons dashicons-unlock"></span> %s</a>',
                        esc_url($disconnect),
                        esc_html__('Disconnect from POP', WC_EL_INV_TEXTDOMAIN)
                    );
                    echo '</div>';
                    echo '</div>';
                    // General invoice data
                    if (class_exists('\WcElectronInvoice\Admin\Settings\TableFields') &&
                        method_exists('\WcElectronInvoice\Admin\Settings\TableFields', 'output')
                    ) {
                        $level     = \WcElectronInvoice\Wizard::popGetUserLevel();
                        $paidLevel = \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic');

                        $getSdiPOPIntegrationData    = InvoiceApi::getSdiPOPIntegrationData();
                        $getPEPPOLPOPIntegrationData = \WcElectronInvoice\PeppolApi::getPEPPOLPOPIntegrationData();
                        $getKSeFPOPIntegrationData   = \WcElectronInvoice\KsefApi::getKsefPOPIntegrationData();
                        $getZohoPOPIntegrationData   = \WcElectronInvoice\ZohoApi::getZohoPOPIntegrationData();
                        $activeInvoiceChannel        = \WcElectronInvoice\Integrations::resolveActiveInvoiceChannel();
                        $taxRegime                   = include \WcElectronInvoice\Plugin::getPluginDirPath('/inc/wc/taxRegime.php');
                        $countryCode                 = GeneralFields::getGeneralInvoiceOptionCountryState() ?: 'IT';
                        $verificationField           = ! checkOptions('general') ? 'field-verification' : '';
                        $sanMarinoSupport            = \WcElectronInvoice\Functions\sanMarinoSupport();
                        $smCountry                   = $sanMarinoSupport->shopCountry;
                        $shopCountry                 = get_option('wc_el_inv-general_store_country', null);
                        $generalShopFields           = apply_filters('wc_el_inv-general_shop_fields', array(
                            // Invoice data
                            array(
                                'title' => '',
                                'type'  => 'title',
                                'desc'  => esc_html__(
                                    'This data will be used for the correct generation of XML and PDF documents',
                                    WC_EL_INV_TEXTDOMAIN
                                ),
                                'id'    => 'store_invoice',
                            ),
                            array(
                                'id'                => 'wc_el_inv-general_store_country',
                                'type'              => 'text',
                                'title'             => esc_html__('Company registration country:',
                                    WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => $verificationField,
                                'value'             => 'SM' === $smCountry ? $smCountry : $shopCountry,
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-general_store_your_name',
                                'type'              => 'text',
                                'title'             => esc_html__('Name:', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => $verificationField,
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-general_store_your_surname',
                                'type'              => 'text',
                                'title'             => esc_html__('Surname:', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => $verificationField,
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-general_store_company_name',
                                'type'              => 'text',
                                'title'             => esc_html__('(*) Company Name:', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                //esc_html__('Please enter your company name', WC_EL_INV_TEXTDOMAIN),
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => $verificationField,
                                'custom_attributes' => array(
                                    'required' => 'required',
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-general_store_vat_number',
                                'type'              => 'text',
                                'title'             => esc_html__('(*) VAT number:', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                //esc_html__('Please enter your VAT code (numbers only)', WC_EL_INV_TEXTDOMAIN),
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => $verificationField,
                                'custom_attributes' => array(
                                    'required' => 'required',
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-general_store_phone',
                                'type'              => 'text',
                                'title'             => esc_html__('Phone number:', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-general_store_email',
                                'type'              => 'text',
                                'title'             => esc_html__('Email address:', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'value'             => GeneralFields::getGeneralInvoiceOptionEmailAddress(),
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'type' => 'sectionend',
                                'id'   => 'store_invoice',
                            ),
                        ));

                        $generalShopFieldsForIT = [];
                        if ('IT' === $shopCountry) {
                            $generalShopFieldsForIT = array(
                                // Transmitter data
                                array(
                                    'title'             => '',
                                    'type'              => 'title',
                                    'desc'              => '',
                                    'id'                => 'store_invoice_company_data',
                                    'custom_attributes' => array(
                                        'disabled' => $uidOption ? 'disabled' : false,
                                        'readonly' => $uidOption ? 'readonly' : false,
                                    ),
                                ),
                                array(
                                    'id'                => 'wc_el_inv-general_store_tax_regime',
                                    'type'              => 'select',
                                    'title'             => esc_html__('(*) Tax Regime:', WC_EL_INV_TEXTDOMAIN),
                                    'desc'              => '',
                                    //esc_html__('Please select your tax regime', WC_EL_INV_TEXTDOMAIN),
                                    'options'           => ! empty($taxRegime[$countryCode]) ? $taxRegime[$countryCode] : array(),
                                    'class'             => 'wc-enhanced-select ' . $verificationField,
                                    'default'           => '',
                                    'custom_attributes' => array(
                                        'required' => 'required',
                                        'disabled' => $uidOption ? 'disabled' : false,
                                        'readonly' => $uidOption ? 'readonly' : false,
                                    ),
                                ),
                                array(
                                    'id'                => 'wc_el_inv-province_business_register_office',
                                    'type'              => 'text',
                                    'title'             => esc_html__('Province of Register of Companies office:',
                                        WC_EL_INV_TEXTDOMAIN),
                                    'desc'              => '',
                                    //esc_html__('Abbreviation of the province of the Register of Companies with which the company is registered eg: [MI], [RM], ...', WC_EL_INV_TEXTDOMAIN),
                                    'placeholder'       => '',
                                    'default'           => '',
                                    'custom_attributes' => array(
                                        'maxlength' => 2,
                                        'disabled'  => $uidOption ? 'disabled' : false,
                                        'readonly'  => $uidOption ? 'readonly' : false,
                                    ),
                                ),
                                array(
                                    'id'                => 'wc_el_inv-rea_registration_number',
                                    'type'              => 'text',
                                    'title'             => esc_html__('REA number:', WC_EL_INV_TEXTDOMAIN),
                                    'desc'              => '',
                                    //esc_html__('Company registration number', WC_EL_INV_TEXTDOMAIN),
                                    'placeholder'       => '',
                                    'default'           => '',
                                    'custom_attributes' => array(
                                        'maxlength' => 20,
                                        'disabled'  => $uidOption ? 'disabled' : false,
                                        'readonly'  => $uidOption ? 'readonly' : false,
                                    ),
                                ),
                                array(
                                    'id'                => 'wc_el_inv-liquidation_status',
                                    'type'              => 'text',
                                    'title'             => esc_html__('Liquidation status:', WC_EL_INV_TEXTDOMAIN),
                                    'desc'              => '',
                                    //esc_html__('Indicates whether the Company is in liquidation or not [LS] = in liquidation, [LN] = not in liquidation', WC_EL_INV_TEXTDOMAIN),
                                    'placeholder'       => '',
                                    'default'           => '',
                                    'custom_attributes' => array(
                                        'maxlength' => 2,
                                        'disabled'  => $uidOption ? 'disabled' : false,
                                        'readonly'  => $uidOption ? 'readonly' : false,
                                    ),
                                ),
                                array(
                                    'type' => 'sectionend',
                                    'id'   => 'store_invoice_company_data',
                                ),
                            );
                        }

                        $transmitterFields = array(
                            // Transmitter data
                            array(
                                'title'             => sprintf('%s',
                                    esc_html__('Transmission Data:', WC_EL_INV_TEXTDOMAIN)),
                                'type'              => 'title',
                                'desc'              => sprintf('%s',
                                    esc_html__('The sender is the person who sends the XML file directly to the Exchange System and can be the company itself or an intermediary on its behalf. (optional fields)',
                                        WC_EL_INV_TEXTDOMAIN)),
                                'id'                => 'store_invoice_transmitter',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-general_store_vat_number_transmitter',
                                'type'              => 'text',
                                'title'             => sprintf('%s',
                                    esc_html__('Transmitter ID:', WC_EL_INV_TEXTDOMAIN)),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'value'             => GeneralFields::getGeneralInvoiceTransmitterOptionVatNumber(),
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-general_store_phone_transmitter',
                                'type'              => 'text',
                                'title'             => sprintf('%s',
                                    esc_html__('Transmitter Phone number:', WC_EL_INV_TEXTDOMAIN)),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'value'             => GeneralFields::getGeneralInvoiceTransmitterOptionPhone(),
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-general_store_email_transmitter',
                                'type'              => 'text',
                                'title'             => sprintf('%s',
                                    esc_html__('Transmitter email address:', WC_EL_INV_TEXTDOMAIN)),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'value'             => GeneralFields::getGeneralInvoiceTransmitterOptionEmail(),
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'type' => 'sectionend',
                                'id'   => 'store_invoice_transmitter',
                            ),
                        );
                        // SdI
                        $sdiViaPOPFields = array(
                            // Sdi data
                            array(
                                'title' => sprintf('%s',
                                    esc_html__('SdI:', WC_EL_INV_TEXTDOMAIN)),
                                'type'  => 'title',
                                'desc'  => sprintf('<div class="pop_api_info"><p><b>%s</b></p><p>%s</p><ul><li>%s</li><li>%s</li></ul><p>%s</p><p><b>%s</b></p><p>%s</p><ul><li>%s</li><li>%s</li></ul></div>',
                                    _x('Credit Usage Information for Each Invoice', 'sdi_pop_api_info',
                                        WC_EL_INV_TEXTDOMAIN),
                                    _x("For every invoice sent to the SDI (Sistema di Interscambio), credits will be automatically deducted based on the services used. Here's how credit consumption works:",
                                        'sdi_pop_api_info', WC_EL_INV_TEXTDOMAIN),
                                    _x("- 1 credit is used for generating the XML file of the invoice.",
                                        'sdi_pop_api_info',
                                        WC_EL_INV_TEXTDOMAIN),
                                    _x("- 1 credit is used for sending the invoice to the SDI.", 'sdi_pop_api_info',
                                        WC_EL_INV_TEXTDOMAIN),
                                    _x('So, each invoice sent consumes at least 2 credits.', 'sdi_pop_api_info',
                                        WC_EL_INV_TEXTDOMAIN),
                                    _x('Additional Services (Optional)', 'sdi_pop_api_info', WC_EL_INV_TEXTDOMAIN),
                                    _x('If you enable one or more of the following services, additional credits will be deducted:',
                                        'sdi_pop_api_info', WC_EL_INV_TEXTDOMAIN),
                                    _x("- Digital preservation: 1 additional credit is used to store the invoice according to legal requirements.",
                                        'sdi_pop_api_info', WC_EL_INV_TEXTDOMAIN),
                                    _x("- Digital signature: 1 additional credit is used to digitally sign the invoice before sending.",
                                        'sdi_pop_api_info', WC_EL_INV_TEXTDOMAIN)
                                ),
                                'id'    => 'sdi_via_pop_data',
                            ),
                            // Live
                            array(
                                'type'      => 'info',
                                'title'     => esc_html__('Live:', WC_EL_INV_TEXTDOMAIN),
                                'id'        => 'sdi_via_pop_data',
                                'row_class' => 'environment_title',
                            ),
                            array(
                                'id'                => 'wc_el_inv-active_sdipop_integration',
                                'type'              => 'text',
                                'title_html'        => $paidLevel &&
                                                       $getSdiPOPIntegrationData->live_integration &&
                                                       $getSdiPOPIntegrationData->active_plugin_integration ?
                                    '<span class="color_green dashicons dashicons-yes-alt" title="' . esc_html__('active',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Integration status',
                                        WC_EL_INV_TEXTDOMAIN) :
                                    '<span class="color_red dashicons dashicons-dismiss" title="' . esc_html__('not available',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Integration status',
                                        WC_EL_INV_TEXTDOMAIN),
                                'desc'              => 'free' === $level ? sprintf(
                                    '%s <a href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
                                    esc_html__('Upgrade to use this feature.', WC_EL_INV_TEXTDOMAIN),
                                    esc_url('https://popapi.io/prezzi/'),
                                    esc_html__('View plans', WC_EL_INV_TEXTDOMAIN)
                                ) : '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => 'hidden',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-business_apply_signature',
                                'type'              => 'text',
                                'title_html'        => $paidLevel && $getSdiPOPIntegrationData->live_signature ?
                                    '<span class="color_green dashicons dashicons-yes-alt" title="' . esc_html__('active',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Apply digital signature before sending invoices to SdI',
                                        WC_EL_INV_TEXTDOMAIN) :
                                    '<span class="color_red dashicons dashicons-dismiss" title="' . esc_html__('not available',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Apply digital signature before sending invoices to SdI',
                                        WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => 'hidden',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-business_apply_legal_storage',
                                'type'              => 'text',
                                'title_html'        => $paidLevel && $getSdiPOPIntegrationData->live_storage ?
                                    '<span class="color_green dashicons dashicons-yes-alt" title="' . esc_html__('active',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Apply the legal storage for invoices sent',
                                        WC_EL_INV_TEXTDOMAIN) :
                                    '<span class="color_red dashicons dashicons-dismiss" title="' . esc_html__('not available',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Apply the legal storage for invoices sent',
                                        WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => 'hidden',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            // Sandbox
                            array(
                                'type'      => 'info',
                                'title'     => esc_html__('Sandbox:', WC_EL_INV_TEXTDOMAIN),
                                'id'        => 'sdi_via_pop_data',
                                'row_class' => 'environment_title',
                            ),
                            array(
                                'id'                => 'wc_el_inv-active_sdipop_integration_sandbox',
                                'type'              => 'text',
                                'title_html'        => $paidLevel &&
                                                       $getSdiPOPIntegrationData->sandbox_integration &&
                                                       $getSdiPOPIntegrationData->active_plugin_integration ?
                                    '<span class="color_green dashicons dashicons-yes-alt" title="' . esc_html__('active',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Integration status',
                                        WC_EL_INV_TEXTDOMAIN) :
                                    '<span class="color_red dashicons dashicons-dismiss" title="' . esc_html__('not available',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Integration status',
                                        WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => 'hidden',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-business_apply_signature_sandbox',
                                'type'              => 'text',
                                'title_html'        => $paidLevel && $getSdiPOPIntegrationData->sandbox_signature ?
                                    '<span class="color_green dashicons dashicons-yes-alt" title="' . esc_html__('active',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Apply digital signature before sending invoices to SdI',
                                        WC_EL_INV_TEXTDOMAIN) :
                                    '<span class="color_red dashicons dashicons-dismiss" title="' . esc_html__('not available',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Apply digital signature before sending invoices to SdI',
                                        WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => 'hidden',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-business_apply_legal_storage_sandbox',
                                'type'              => 'text',
                                'title_html'        => $paidLevel && $getSdiPOPIntegrationData->sandbox_storage ?
                                    '<span class="color_green dashicons dashicons-yes-alt" title="' . esc_html__('active',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Apply the legal storage for invoices sent',
                                        WC_EL_INV_TEXTDOMAIN) :
                                    '<span class="color_red dashicons dashicons-dismiss" title="' . esc_html__('not available',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Apply the legal storage for invoices sent',
                                        WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => 'hidden',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            /* --- */
                            array(
                                'type'       => 'text',
                                'title_html' => sprintf('<p class="pop_doc_links"><a target="_blank" href="' . WC_EL_INV_API_DOMAIN . '/mio-account/api-integrations/">%s</a> | <a target="_blank" href="https://docs.popapi.io/it/guides/integrations/sdi-via-pop/">%s</a></p>',
                                    __('Edit configuration', WC_EL_INV_TEXTDOMAIN),
                                    __('Documentation', WC_EL_INV_TEXTDOMAIN),
                                ),
                                'id'         => 'sdi_via_pop_data',
                            ),
                            array(
                                'type' => 'sectionend',
                                'id'   => 'sdi_via_pop_data',
                            ),
                        );
                        $isGermanyZugferdContext = \WcElectronInvoice\Integrations::isGermanyZugferdContext();

                        // PEPPOL
                        $peppolViaPOPFields = array(
                            // PEPPOL data
                            array(
                                'title' => sprintf('%s',
                                    esc_html__('PEPPOL:', WC_EL_INV_TEXTDOMAIN)),
                                'type'  => 'title',
                                'desc'  => sprintf('<div class="pop_api_info"><p><b>%s</b></p><p>%s</p><ul><li>%s</li><li>%s</li></ul><p>%s</p></div>',
                                    _x('Credit Usage Information for Each UBL Document', 'peppol_pop_api_info',
                                        WC_EL_INV_TEXTDOMAIN),
                                    _x("For every UBL document sent via the PEPPOL network, credits will be automatically deducted based on the services used. Here's how credit consumption works:",
                                        'peppol_pop_api_info', WC_EL_INV_TEXTDOMAIN),
                                    _x("- 1 credit is used for generating the UBL file of the document.",
                                        'peppol_pop_api_info',
                                        WC_EL_INV_TEXTDOMAIN),
                                    _x("- 1 credit is used for sending the UBL document through the PEPPOL network.",
                                        'peppol_pop_api_info',
                                        WC_EL_INV_TEXTDOMAIN),
                                    _x('So, each UBL document sent consumes at least 2 credits.', 'peppol_pop_api_info',
                                        WC_EL_INV_TEXTDOMAIN),
                                ),
                                'id'    => 'peppol_via_pop_data',
                            ),
                            // Live
                            array(
                                'type'      => 'info',
                                'title'     => esc_html__('Live:', WC_EL_INV_TEXTDOMAIN),
                                'id'        => 'peppol_via_pop_data',
                                'row_class' => 'environment_title',
                            ),
                            array(
                                'id'                => 'wc_el_inv-active_peppol_integration',
                                'type'              => 'text',
                                'title_html'        => $paidLevel &&
                                                       $getPEPPOLPOPIntegrationData->live_integration &&
                                                       $getPEPPOLPOPIntegrationData->active_plugin_integration ?
                                    '<span class="color_green dashicons dashicons-yes-alt" title="' . esc_html__('active',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Integration status',
                                        WC_EL_INV_TEXTDOMAIN) :
                                    '<span class="color_red dashicons dashicons-dismiss" title="' . esc_html__('not available',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Integration status',
                                        WC_EL_INV_TEXTDOMAIN),
                                'desc'              => 'free' === $level ? sprintf(
                                    '%s <a href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
                                    esc_html__('Upgrade to use this feature.', WC_EL_INV_TEXTDOMAIN),
                                    esc_url('https://popapi.io/prezzi/'),
                                    esc_html__('View plans', WC_EL_INV_TEXTDOMAIN)
                                ) : '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => 'hidden',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-peppol_identifier_scheme',
                                'type'              => 'text',
                                'title_html'        => esc_html__('Identifier scheme', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-peppol_endpoint_identifier_value',
                                'type'              => 'text',
                                'title_html'        => esc_html__('Identifier value', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-peppol_legal_entity_uuid',
                                'type'              => 'text',
                                'title_html'        => esc_html__('UUID', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-peppol_le_address',
                                'type'              => 'text',
                                'title_html'        => esc_html__('Address', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-peppol_le_city',
                                'type'              => 'text',
                                'title_html'        => esc_html__('City', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-peppol_le_zipcode',
                                'type'              => 'text',
                                'title_html'        => esc_html__('ZipCode', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            // Sandbox
                            array(
                                'type'      => 'info',
                                'title'     => esc_html__('Sandbox:', WC_EL_INV_TEXTDOMAIN),
                                'id'        => 'peppol_via_pop_data',
                                'row_class' => 'environment_title',
                            ),
                            array(
                                'id'                => 'wc_el_inv-active_peppol_integration_sandbox',
                                'type'              => 'text',
                                'title_html'        => $paidLevel &&
                                                       $getPEPPOLPOPIntegrationData->sandbox_integration &&
                                                       $getPEPPOLPOPIntegrationData->active_plugin_integration ?
                                    '<span class="color_green dashicons dashicons-yes-alt" title="' . esc_html__('active',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Integration status',
                                        WC_EL_INV_TEXTDOMAIN) :
                                    '<span class="color_red dashicons dashicons-dismiss" title="' . esc_html__('not available',
                                        WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Integration status',
                                        WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => 'hidden',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-peppol_identifier_scheme_sandbox',
                                'type'              => 'text',
                                'title_html'        => esc_html__('Identifier scheme', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-peppol_endpoint_identifier_value_sandbox',
                                'type'              => 'text',
                                'title_html'        => esc_html__('Identifier value', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-peppol_legal_entity_uuid_sandbox',
                                'type'              => 'text',
                                'title_html'        => esc_html__('UUID', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-peppol_le_address_sandbox',
                                'type'              => 'text',
                                'title_html'        => esc_html__('Address', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-peppol_le_city_sandbox',
                                'type'              => 'text',
                                'title_html'        => esc_html__('City', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-peppol_le_zipcode_sandbox',
                                'type'              => 'text',
                                'title_html'        => esc_html__('ZipCode', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            /* --- */
                            array(
                                'type'       => 'text',
                                'title_html' => sprintf('<p class="pop_doc_links"><a target="_blank" href="' . WC_EL_INV_API_DOMAIN . '/mio-account/api-integrations/">%s</a> | <a target="_blank" href="https://docs.popapi.io/it/guides/integrations/peppol/">%s</a></p>',
                                    __('Edit configuration', WC_EL_INV_TEXTDOMAIN),
                                    __('Documentation', WC_EL_INV_TEXTDOMAIN),
                                ),
                                'id'         => 'peppol_via_pop_data',
                            ),
                            array(
                                'type' => 'sectionend',
                                'id'   => 'peppol_via_pop_data',
                            ),
                        );
                        $zugferdViaPOPFields = array(
                            array(
                                'title' => sprintf('%s', esc_html__('ZUGFeRD:', WC_EL_INV_TEXTDOMAIN)),
                                'type'  => 'title',
                                'desc'  => sprintf(
                                    '<div class="pop_api_info"><p><b>%s</b></p><p>%s</p><ul><li>%s</li></ul><p>%s</p></div>',
                                    esc_html(_x('Credit Usage Information for Each ZUGFeRD Document', 'zugferd_pop_api_info', WC_EL_INV_TEXTDOMAIN)),
                                    esc_html(_x('For every ZUGFeRD document generated, the consumer uses one bundle operation with a fixed cost.', 'zugferd_pop_api_info', WC_EL_INV_TEXTDOMAIN)),
                                    esc_html(_x('- 2 credits are used for each ZUGFeRD bundle generation.', 'zugferd_pop_api_info', WC_EL_INV_TEXTDOMAIN)),
                                    esc_html(_x('This panel does not use PEPPOL live/sandbox statuses because ZUGFeRD follows a dedicated Germany corridor.', 'zugferd_pop_api_info', WC_EL_INV_TEXTDOMAIN))
                                ),
                                'id'    => 'zugferd_via_pop_data',
                            ),
                            array(
                                'type' => 'sectionend',
                                'id'   => 'zugferd_via_pop_data',
                            ),
                        );
                        // KSeF
                        $ksefViaPOPFields = array(
                            array(
                                'title' => sprintf('%s', esc_html__('KSeF:', WC_EL_INV_TEXTDOMAIN)),
                                'type'  => 'title',
                                'desc'  => sprintf(
                                    '<div class="pop_api_info"><p><b>%s</b></p><p>%s</p><ul><li>%s</li><li>%s</li></ul><p>%s</p></div>',
                                    _x('Credit Usage Information for Each KSeF Document', 'ksef_pop_api_info', WC_EL_INV_TEXTDOMAIN),
                                    _x("For every invoice sent to the Polish KSeF system, credits will be automatically deducted based on the services used. Here's how credit consumption works:", 'ksef_pop_api_info', WC_EL_INV_TEXTDOMAIN),
                                    _x('- 1 credit is used for generating the KSeF FA(3) XML file of the document.', 'ksef_pop_api_info', WC_EL_INV_TEXTDOMAIN),
                                    _x('- 1 credit is used for sending the document through the KSeF network.', 'ksef_pop_api_info', WC_EL_INV_TEXTDOMAIN),
                                    _x('So, each KSeF document sent consumes at least 2 credits.', 'ksef_pop_api_info', WC_EL_INV_TEXTDOMAIN)
                                ),
                                'id'    => 'ksef_via_pop_data',
                            ),
                            // Live
                            array(
                                'type'      => 'info',
                                'title'     => esc_html__('Live:', WC_EL_INV_TEXTDOMAIN),
                                'id'        => 'ksef_via_pop_data',
                                'row_class' => 'environment_title',
                            ),
                            array(
                                'id'                => 'wc_el_inv-active_ksef_integration',
                                'type'              => 'text',
                                'title_html'        => $paidLevel &&
                                                       $getKSeFPOPIntegrationData->live_integration &&
                                                       $getKSeFPOPIntegrationData->active_plugin_integration ?
                                    '<span class="color_green dashicons dashicons-yes-alt" title="' . esc_html__('active', WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Integration status', WC_EL_INV_TEXTDOMAIN) :
                                    '<span class="color_red dashicons dashicons-dismiss" title="' . esc_html__('not available', WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Integration status', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => 'free' === $level ? sprintf(
                                    '%s <a href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
                                    esc_html__('Upgrade to use this feature.', WC_EL_INV_TEXTDOMAIN),
                                    esc_url('https://popapi.io/prezzi/'),
                                    esc_html__('View plans', WC_EL_INV_TEXTDOMAIN)
                                ) : '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => 'hidden',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-ksef_legal_entity_uuid',
                                'type'              => 'text',
                                'title_html'        => esc_html__('UUID', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-ksef_le_nip',
                                'type'              => 'text',
                                'title_html'        => esc_html__('NIP', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-ksef_le_name',
                                'type'              => 'text',
                                'title_html'        => esc_html__('Company name', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            // Sandbox
                            array(
                                'type'      => 'info',
                                'title'     => esc_html__('Sandbox:', WC_EL_INV_TEXTDOMAIN),
                                'id'        => 'ksef_via_pop_data',
                                'row_class' => 'environment_title',
                            ),
                            array(
                                'id'                => 'wc_el_inv-active_ksef_integration_sandbox',
                                'type'              => 'text',
                                'title_html'        => $paidLevel &&
                                                       $getKSeFPOPIntegrationData->sandbox_integration &&
                                                       $getKSeFPOPIntegrationData->active_plugin_integration ?
                                    '<span class="color_green dashicons dashicons-yes-alt" title="' . esc_html__('active', WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Integration status', WC_EL_INV_TEXTDOMAIN) :
                                    '<span class="color_red dashicons dashicons-dismiss" title="' . esc_html__('not available', WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Integration status', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => 'hidden',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-ksef_legal_entity_uuid_sandbox',
                                'type'              => 'text',
                                'title_html'        => esc_html__('UUID', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-ksef_le_nip_sandbox',
                                'type'              => 'text',
                                'title_html'        => esc_html__('NIP', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-ksef_le_name_sandbox',
                                'type'              => 'text',
                                'title_html'        => esc_html__('Company name', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            /* --- */
                            array(
                                'type'       => 'text',
                                'title_html' => sprintf(
                                    '<p class="pop_doc_links"><a target="_blank" href="' . WC_EL_INV_API_DOMAIN . '/mio-account/api-integrations/">%s</a> | <a target="_blank" href="https://docs.popapi.io/it/guides/integrations/ksef/">%s</a></p>',
                                    __('Edit configuration', WC_EL_INV_TEXTDOMAIN),
                                    __('Documentation', WC_EL_INV_TEXTDOMAIN)
                                ),
                                'id'         => 'ksef_via_pop_data',
                            ),
                            array(
                                'type' => 'sectionend',
                                'id'   => 'ksef_via_pop_data',
                            ),
                        );
                        $zohoViaPOPFields = array(
                            array(
                                'title' => sprintf('%s', esc_html__('Zoho:', WC_EL_INV_TEXTDOMAIN)),
                                'type'  => 'title',
                                'desc'  => sprintf(
                                    '<div class="pop_api_info"><p><b>%s</b></p><p>%s</p><ul><li>%s</li></ul><p>%s</p></div>',
                                    esc_html(_x('Credit Usage Information for Each Zoho Document', 'zoho_pop_api_info', WC_EL_INV_TEXTDOMAIN)),
                                    esc_html(_x('For every document synced to Zoho in live mode, POP consumes one credit for the sync operation.', 'zoho_pop_api_info', WC_EL_INV_TEXTDOMAIN)),
                                    esc_html(_x('- 1 credit is used for each Zoho document sync in live mode.', 'zoho_pop_api_info', WC_EL_INV_TEXTDOMAIN)),
                                    esc_html(_x('This panel is informational only: Zoho activation remains controlled from the Integrations tab and uses a single exclusive local channel selection.', 'zoho_pop_api_info', WC_EL_INV_TEXTDOMAIN))
                                ),
                                'id'    => 'zoho_via_pop_data',
                            ),
                            array(
                                'id'                => 'wc_el_inv-zoho_integration_status',
                                'type'              => 'text',
                                'title_html'        => $paidLevel &&
                                                       $getZohoPOPIntegrationData->zoho_integration ?
                                    '<span class="color_green dashicons dashicons-yes-alt" title="' . esc_html__('active', WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Zoho status', WC_EL_INV_TEXTDOMAIN) :
                                    '<span class="color_red dashicons dashicons-dismiss" title="' . esc_html__('not available', WC_EL_INV_TEXTDOMAIN) . '"></span> ' . esc_html__('Zoho status', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => 'free' === $level ? sprintf(
                                    '%s <a href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
                                    esc_html__('Upgrade to use this feature.', WC_EL_INV_TEXTDOMAIN),
                                    esc_url('https://popapi.io/prezzi/'),
                                    esc_html__('View plans', WC_EL_INV_TEXTDOMAIN)
                                ) : '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => 'hidden',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-zoho_plugin_status',
                                'type'              => 'text',
                                'title_html'        => (! empty($getZohoPOPIntegrationData->active_plugin_integration) ?
                                    '<span class="color_green dashicons dashicons-yes-alt" title="' . esc_html__('enabled', WC_EL_INV_TEXTDOMAIN) . '"></span> ' :
                                    '<span class="color_red dashicons dashicons-dismiss" title="' . esc_html__('disabled', WC_EL_INV_TEXTDOMAIN) . '"></span> ') .
                                                       esc_html__('Local plugin integration', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => 'hidden',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                            ),
                            array(
                                'id'                => 'wc_el_inv-zoho_active_connector',
                                'type'              => 'text',
                                'title_html'        => esc_html__('POP account connector', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                                'value'             => $getZohoPOPIntegrationData->active_connector ?: esc_html__('none', WC_EL_INV_TEXTDOMAIN),
                            ),
                            array(
                                'id'                => 'wc_el_inv-zoho_connected',
                                'type'              => 'text',
                                'title_html'        => esc_html__('Zoho connected', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                                'value'             => $getZohoPOPIntegrationData->connected ? esc_html__('Yes', WC_EL_INV_TEXTDOMAIN) : esc_html__('No', WC_EL_INV_TEXTDOMAIN),
                            ),
                            array(
                                'id'                => 'wc_el_inv-zoho_product',
                                'type'              => 'text',
                                'title_html'        => esc_html__('Zoho product', WC_EL_INV_TEXTDOMAIN),
                                'desc'              => '',
                                'placeholder'       => '',
                                'default'           => '',
                                'class'             => '',
                                'custom_attributes' => array(
                                    'disabled' => $uidOption ? 'disabled' : false,
                                    'readonly' => $uidOption ? 'readonly' : false,
                                ),
                                'value'             => $getZohoPOPIntegrationData->product ?: esc_html__('not available', WC_EL_INV_TEXTDOMAIN),
                            ),
                            array(
                                'type'       => 'text',
                                'title_html' => sprintf('<p class="pop_doc_links"><a target="_blank" href="' . WC_EL_INV_API_DOMAIN . '/mio-account/api-integrations/">%s</a> | <a target="_blank" href="https://docs.popapi.io/it/guides/integrations/zoho/">%s</a></p>',
                                    __('Edit configuration', WC_EL_INV_TEXTDOMAIN),
                                    __('Documentation', WC_EL_INV_TEXTDOMAIN)
                                ),
                                'id'         => 'zoho_via_pop_data',
                            ),
                            array(
                                'type' => 'sectionend',
                                'id'   => 'zoho_via_pop_data',
                            ),
                        );

                        // Not allowed PEPPOL data
                        if (defined('WC_EL_INV_UBL_COUNTRIES') && ! in_array($shopCountry, WC_EL_INV_UBL_COUNTRIES)) {
                            $peppolViaPOPFields = [];
                        }

                        if ($isGermanyZugferdContext) {
                            $peppolViaPOPFields = [];
                        } else {
                            $zugferdViaPOPFields = [];
                        }

                        // Not allowed KSeF data
                        if ('PL' !== $shopCountry) {
                            $ksefViaPOPFields = [];
                        }

                        $sanMarinoSupport = \WcElectronInvoice\Functions\sanMarinoSupport();
                        $shopCountry      = get_option('wc_el_inv-general_store_country', null);
                        if ('IT' !== $shopCountry && 'SM' !== $sanMarinoSupport->shopCountry) {
                            // Reset array if country not IT
                            $transmitterFields = [];
                            $sdiViaPOPFields   = [];
                        } else {
                            // Reset array if country is IT
                            $peppolViaPOPFields  = [];
                            $zugferdViaPOPFields = [];
                            $ksefViaPOPFields    = [];
                        }

                        if (\WcElectronInvoice\Integrations::CHANNEL_ZOHO === $activeInvoiceChannel) {
                            $transmitterFields   = [];
                            $sdiViaPOPFields     = [];
                            $peppolViaPOPFields  = [];
                            $zugferdViaPOPFields = [];
                            $ksefViaPOPFields    = [];
                        }

                        // Transmitter data.
                        $generalShopFields = array_merge($generalShopFields, $generalShopFieldsForIT,
                            $transmitterFields, $sdiViaPOPFields, $peppolViaPOPFields, $zugferdViaPOPFields, $ksefViaPOPFields, $zohoViaPOPFields);
                        \WcElectronInvoice\Admin\Settings\TableFields::output((array)$generalShopFields);
                    }
                    echo '</div>';
                } else {
                    add_action('wc_el_inv-after_settings_form', function () {
                        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                        echo sprintf(' <div class="pop_account_panel_connect"><div class="overlay"></div><div class="pop_account_panel_connect_content"><h2>%1$s</h2><p>%2$s</p><p><a class="button button-primary" href="%3$s">%4$s</a></p></div></div>',
                            esc_html__('Connect the POP APIs now!', WC_EL_INV_TEXTDOMAIN),
                            esc_html__('To start using POP, you need an account. Click the button to launch the setup wizard.',
                                WC_EL_INV_TEXTDOMAIN),
                            esc_url(admin_url("admin.php?page=wc_el_inv-options-page&tab=wizard&wizard=init")),
                            esc_html__('Configure Account', WC_EL_INV_TEXTDOMAIN)
                        );
                    });
                }
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_general',
            'field_args'     => array('class' => 'pop_account'),
        );
        // ------------------------------------------- /
        break;
    // Numeration
    case 'setting_section_numeration':
        $this->sectionArgs['wc_el_inv_settings'] = array(
            'section_id'       => 'setting_section_numeration',
            'section_title'    => '', //esc_html__('Numeration', WC_EL_INV_TEXTDOMAIN),
            'section_callback' => '',
            'section_page'     => 'wc_el_inv-options-page',
        );
        // Global
        $this->fieldsArgs[] = array(
            'field_id'       => 'numeration_global_title',
            'field_title'    => sprintf('<h4>%s</h4>', esc_html__('Global', WC_EL_INV_TEXTDOMAIN)),
            'field_callback' => function () {
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'number_digits_in_invoice_options_fields',
            'field_title'    => esc_html__('Number of digits (enter 4 to display 13 as 0013)', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'type'        => 'number',
                    'id'          => 'wc_el_inv-settings-number_digits_in_invoice',
                    'name'        => 'wc_el_inv-settings-number_digits_in_invoice',
                    'value'       => 3,
                    'description' => sprintf('%s',
                        esc_html__('Enter a value from 1 to 6.', WC_EL_INV_TEXTDOMAIN)
                    ),
                    'attrs'       => array(
                        'min' => 1,
                        'max' => 6,
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'number_digits'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'reset_numerations_year_change_options_fields',
            'field_title'    => esc_html__('Reset the numbers at each year change', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                    'id'          => 'wc_el_inv-settings-reset_numerations_year_change',
                    'name'        => 'wc_el_inv-settings-reset_numerations_year_change',
                    'label'       => esc_html__('Reset the numbers', WC_EL_INV_TEXTDOMAIN),
                    'description' => esc_html__('The numbering of invoices, receipts and credit notes will be reset every year on January 1st',
                        WC_EL_INV_TEXTDOMAIN),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'reset_numerations'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'suffix_invoice_number_options_fields',
            'field_title'    => esc_html__('Suffix', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'id'          => 'wc_el_inv-settings-suffix_invoice_number',
                    'name'        => 'wc_el_inv-settings-suffix_invoice_number',
                    'description' => esc_html__('Enter a letter as a suffix (or select the option below "year as suffix")',
                        WC_EL_INV_TEXTDOMAIN),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'suffix_invoice'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'suffix_year_invoice_number_options_fields',
            'field_title'    => esc_html__('Suffix year', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                    'id'          => 'wc_el_inv-settings-suffix_year_invoice_number',
                    'name'        => 'wc_el_inv-settings-suffix_year_invoice_number',
                    'label'       => esc_html__('Set the year as a suffix', WC_EL_INV_TEXTDOMAIN),
                    'description' => esc_html__('Selecting the option, the year of order creation will be set as a suffix.',
                        WC_EL_INV_TEXTDOMAIN),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'suffix_year'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'suffix_year_format_invoice_number_options_fields',
            'field_title'    => esc_html__('Format date', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Radio(array(
                    'id'          => 'wc_el_inv-settings-suffix_year_format_invoice_number',
                    'name'        => 'wc_el_inv-settings-suffix_year_format_invoice_number',
                    'description' => esc_html__('Set the year format', WC_EL_INV_TEXTDOMAIN),
                    'default'     => 'Y',
                    'options'     => array(
                        'y' => sprintf('<code>/%s</code>',
                            date('y', time())
                        ),
                        'Y' => sprintf('<code>/%s</code>',
                            date('Y', time())
                        ),
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'suffix_year_format'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'hr_numeration_global_bottom',
            'field_title'    => '',
            'field_callback' => function () {
                echo '<hr>';
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
        );
        // Invoice
        $this->fieldsArgs[] = array(
            'field_id'       => 'numeration_invoice_title',
            'field_title'    => sprintf('<h4>%s</h4>', esc_html__('Invoice', WC_EL_INV_TEXTDOMAIN)),
            'field_callback' => function () {
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'prefix_invoice_number_options_fields',
            'field_title'    => esc_html__('Prefix invoice', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'id'          => 'wc_el_inv-settings-prefix_invoice_number',
                    'name'        => 'wc_el_inv-settings-prefix_invoice_number',
                    'value'       => '',
                    'description' => null,
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'prefix_invoice'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'number_next_invoice_options_fields',
            'field_title'    => esc_html__('Number of the next invoice', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'type'        => 'number',
                    'id'          => 'wc_el_inv-settings-number_next_invoice',
                    'name'        => 'wc_el_inv-settings-number_next_invoice',
                    'value'       => 1,
                    'class'       => ! checkOptions('numeration') ? 'field-verification' : '',
                    'description' => sprintf('%s',
                        esc_html__('Enter a number from which to start generating the invoice numbering',
                            WC_EL_INV_TEXTDOMAIN)
                    ),
                    'attrs'       => array(
                        'required' => 'required',
                        'min'      => 1,
                        'disabled' => $invoiceNumberDisabled,
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'number_next_invoice'),
        );

        // Hook for extend invoice progressive number
        do_action('wc_el_inv-page_settings_fields_extend_invoice_progressive_number', $section, $this);

        $this->fieldsArgs[] = array(
            'field_id'       => 'hr_numeration_invoice_bottom',
            'field_title'    => '',
            'field_callback' => function () {
                echo '<hr>';
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
        );
        // Receipt
        $this->fieldsArgs[] = array(
            'field_id'       => 'numeration_receipt_title',
            'field_title'    => sprintf('<h4>%s</h4>', esc_html__('Receipt', WC_EL_INV_TEXTDOMAIN)),
            'field_callback' => function () {
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'prefix_receipt_number_options_fields',
            'field_title'    => esc_html__('Prefix receipt', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'id'          => 'wc_el_inv-settings-prefix_receipt_number',
                    'name'        => 'wc_el_inv-settings-prefix_receipt_number',
                    'value'       => '',
                    'description' => null,
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'prefix_receipt'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'number_next_receipt_options_fields',
            'field_title'    => esc_html__('Number of the next receipt', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'type'        => 'number',
                    'id'          => 'wc_el_inv-settings-number_next_receipt',
                    'name'        => 'wc_el_inv-settings-number_next_receipt',
                    'value'       => 1,
                    'description' => sprintf('%s',
                        esc_html__('Enter the starting number for receipt numbering (minimum 1). Receipts must always use their own separate numbering sequence.',
                            WC_EL_INV_TEXTDOMAIN)
                    ),
                    'attrs'       => array(
                        'required' => 'required',
                        'min'      => 1,
                        'disabled' => $receiptNumberDisabled,
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'number_next_receipt'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'hr_numeration_receipt_bottom',
            'field_title'    => '',
            'field_callback' => function () {
                echo '<hr>';
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
        );
        // Credit note invoice
        $this->fieldsArgs[] = array(
            'field_id'       => 'numeration_credit_note_title',
            'field_title'    => sprintf('<h4>%s %s</h4>',
                esc_html__('Credit note', WC_EL_INV_TEXTDOMAIN),
                esc_html__('(relating to invoices)', WC_EL_INV_TEXTDOMAIN)
            ),
            'field_callback' => function () {
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
        );
        if ($premiumSettingsDisabled) {
            $this->fieldsArgs[count($this->fieldsArgs) - 1]['field_title'] = sprintf(
                '<h4>%s %s%s</h4>',
                esc_html__('Credit note', WC_EL_INV_TEXTDOMAIN),
                esc_html__('(relating to invoices)', WC_EL_INV_TEXTDOMAIN),
                $paidOnlyBadge
            );
        }
        $this->fieldsArgs[] = array(
            'field_id'       => 'prefix_credit_note_number_options_fields',
            'field_title'    => esc_html__('Prefix credit note', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'id'          => 'wc_el_inv-settings-prefix_credit_note_number',
                    'name'        => 'wc_el_inv-settings-prefix_credit_note_number',
                    'value'       => '',
                    'description' => null,
                    'attrs'       => $premiumFieldAttrs,
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'prefix_credit_note'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'numeration_credit_note_active',
            'field_title'    => esc_html__('Separate numbering', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                    'id'          => 'wc_el_inv-settings-numeration_credit_note_active',
                    'name'        => 'wc_el_inv-settings-numeration_credit_note_active',
                    'label'       => esc_html__('Use separate numbering', WC_EL_INV_TEXTDOMAIN),
                    'description' => esc_html__('Selecting the option you will be able to define separate numbering',
                        WC_EL_INV_TEXTDOMAIN),
                    'attrs'       => $premiumFieldAttrs,
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'numeration_credit_note'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'number_next_credit_note_options_fields',
            'field_title'    => esc_html__('Number of the next credit note', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'type'        => 'number',
                    'id'          => 'wc_el_inv-settings-number_next_credit_note',
                    'name'        => 'wc_el_inv-settings-number_next_credit_note',
                    'value'       => 0,
                    'label'       => esc_html__('Numerator for credit notes generated from an invoice',
                        WC_EL_INV_TEXTDOMAIN),
                    'description' => sprintf('%s',
                        esc_html__('Enter a number from which to start generating the credit note numbering (set zero to use invoice numbering)',
                            WC_EL_INV_TEXTDOMAIN)
                    ),
                    'attrs'       => array(
                        'required' => 'required',
                        'min'      => 0,
                        'disabled' => $premiumSettingsDisabled ? 'disabled' : $creditNoteNumberDisabled,
                        'readonly' => $premiumSettingsDisabled ? 'readonly' : false,
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'number_next_credit_note'),
        );
        // Credit note receipt
        $this->fieldsArgs[] = array(
            'field_id'       => 'numeration_credit_note_receipt_title',
            'field_title'    => sprintf('<h4>%s %s</h4>',
                esc_html__('Credit note', WC_EL_INV_TEXTDOMAIN),
                esc_html__('(relating to receipts)', WC_EL_INV_TEXTDOMAIN)
            ),
            'field_callback' => function () {
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
        );
        if ($premiumSettingsDisabled) {
            $this->fieldsArgs[count($this->fieldsArgs) - 1]['field_title'] = sprintf(
                '<h4>%s %s%s</h4>',
                esc_html__('Credit note', WC_EL_INV_TEXTDOMAIN),
                esc_html__('(relating to receipts)', WC_EL_INV_TEXTDOMAIN),
                $paidOnlyBadge
            );
        }
        $this->fieldsArgs[] = array(
            'field_id'       => 'prefix_credit_note_receipt_number_options_fields',
            'field_title'    => esc_html__('Prefix credit note', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'id'          => 'wc_el_inv-settings-prefix_credit_note_receipt_number',
                    'name'        => 'wc_el_inv-settings-prefix_credit_note_receipt_number',
                    'value'       => '',
                    'description' => null,
                    'attrs'       => $premiumFieldAttrs,
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'prefix_credit_note_receipt'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'numeration_credit_note_receipt_active',
            'field_title'    => esc_html__('Separate numbering', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                    'id'          => 'wc_el_inv-settings-numeration_credit_note_receipt_active',
                    'name'        => 'wc_el_inv-settings-numeration_credit_note_receipt_active',
                    'label'       => esc_html__('Use separate numbering', WC_EL_INV_TEXTDOMAIN),
                    'description' => esc_html__('Selecting the option you will be able to define separate numbering',
                        WC_EL_INV_TEXTDOMAIN),
                    'attrs'       => $premiumFieldAttrs,
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'numeration_credit_note_receipt'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'number_next_credit_note_receipt_options_fields',
            'field_title'    => esc_html__('Number of the next credit note', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'type'        => 'number',
                    'id'          => 'wc_el_inv-settings-number_next_credit_note_receipt',
                    'name'        => 'wc_el_inv-settings-number_next_credit_note_receipt',
                    'value'       => 0,
                    'label'       => esc_html__('Numerator for credit notes generated from a receipt',
                        WC_EL_INV_TEXTDOMAIN),
                    'description' => sprintf('%s',
                        esc_html__('Enter a number from which to start generating the credit note numbering (set zero to use invoice numbering)',
                            WC_EL_INV_TEXTDOMAIN)
                    ),
                    'attrs'       => array(
                        'required' => 'required',
                        'min'      => 0,
                        'disabled' => $premiumSettingsDisabled ? 'disabled' : $creditNoteReceiptNumberDisabled,
                        'readonly' => $premiumSettingsDisabled ? 'readonly' : false,
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_numeration',
            'field_args'     => array('class' => 'number_next_credit_note_receipt'),
        );
        break;
    // Invoice / Documents
    case 'setting_section_invoice':
        $this->sectionArgs['wc_el_inv_settings'] = array(
            'section_id'       => 'setting_section_invoice',
            'section_title'    => '', //esc_html__('Documents', WC_EL_INV_TEXTDOMAIN),
            'section_callback' => '',
            'section_page'     => 'wc_el_inv-options-page',
        );
        // Global
        $this->fieldsArgs[] = array(
            'field_id'       => 'hr_invoice',
            'field_title'    => sprintf('<h4>%s</h4>', esc_html__('Global', WC_EL_INV_TEXTDOMAIN)),
            'field_callback' => function () {
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'disable_invoice_number_order_zero_options_fields',
            'field_title'    => esc_html__('Disable document if total zero', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                    'id'          => 'wc_el_inv-settings-disable_invoice_number_order_zero',
                    'name'        => 'wc_el_inv-settings-disable_invoice_number_order_zero',
                    'label'       => esc_html__('Disable document', WC_EL_INV_TEXTDOMAIN),
                    'description' => esc_html__('Disable document and disable the number increment if order total is zero.',
                        WC_EL_INV_TEXTDOMAIN),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
            'field_args'     => array('class' => 'disable_invoice_number_order_zero'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'remove_product_from_invoice_is_total_zero_options_fields',
            'field_title'    => esc_html__('Remove products with a zero total the invoice', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                    'id'          => 'wc_el_inv-settings-remove_product_from_invoice_is_total_zero',
                    'name'        => 'wc_el_inv-settings-remove_product_from_invoice_is_total_zero',
                    'label'       => esc_html__('Remove products', WC_EL_INV_TEXTDOMAIN),
                    'description' => esc_html__('Remove products with a zero total from the invoice',
                        WC_EL_INV_TEXTDOMAIN),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
            'field_args'     => array('class' => 'remove_product_from_invoice_is_total_zero'),
        );

        $shopCountry = get_option('wc_el_inv-general_store_country', null);
        if ('IT' === $shopCountry && ('RF19' !== GeneralFields::getGeneralInvoiceOptionTaxRegime() &&
                                      'RF02' !== GeneralFields::getGeneralInvoiceOptionTaxRegime())
        ) {
            $this->fieldsArgs[] = array(
                'field_id'       => 'invoice_ref_normative_N4_nature',
                'field_title'    => esc_html__('Normative reference for exempt transactions (N4 nature)',
                    WC_EL_INV_TEXTDOMAIN),
                'field_callback' => array(
                    new \WcElectronInvoice\Admin\Settings\Fields\Select(array(
                        'id'          => 'wc_el_inv-settings-invoice_ref_normative_N4_nature',
                        'name'        => 'wc_el_inv-settings-invoice_ref_normative_N4_nature',
                        'label'       => esc_html__('Please select the normative reference to use',
                            WC_EL_INV_TEXTDOMAIN),
                        'options'     => array(
                            '999' => esc_html__("Select", WC_EL_INV_TEXTDOMAIN),
                            // N4 nature reference options
                            '19'  => esc_html__("Exempt VAT pursuant to art.10 of D.P.R 633/1972",
                                WC_EL_INV_TEXTDOMAIN),
                            '24'  => esc_html__("Exempt VAT pursuant to art. 10, paragraph 1, no. 18 of D.P.R. 633/1972",
                                WC_EL_INV_TEXTDOMAIN),
                            '25'  => esc_html__("Exempt VAT pursuant to art. 10, paragraph 20 of D.P.R. 633/72",
                                WC_EL_INV_TEXTDOMAIN),
                            '27'  => esc_html__("Exempt VAT pursuant to art.10 no.27 of D.P.R 633/1972",
                                WC_EL_INV_TEXTDOMAIN),
                            '37'  => esc_html__("Exempt VAT pursuant to art. 10, paragraph 9 of D.P.R. 633/72",
                                WC_EL_INV_TEXTDOMAIN),
                            '45'  => esc_html__("Non taxable pursuant to art. 9", WC_EL_INV_TEXTDOMAIN),
                        ),
                        'description' => sprintf('%s',
                            esc_html__('This regulatory reference will be displayed in the xml and pdf invoice when the transactions are N4 (Exempt) in nature',
                                WC_EL_INV_TEXTDOMAIN)
                        ),
                        'attrs'       => array(
                            'required' => 'required',
                        ),
                    ), $this, $page),
                    'field',
                ),
                'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
                'field_section'  => 'setting_section_invoice',
                'field_args'     => array('class' => 'invoice_ref_normative_N4'),
            );
            $this->fieldsArgs[] = array(
                'field_id'       => 'invoice_ref_normative_N5_nature',
                'field_title'    => esc_html__('Normative reference for Exempt transactions (N5 nature)',
                    WC_EL_INV_TEXTDOMAIN),
                'field_callback' => array(
                    new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                        'id'          => 'wc_el_inv-settings-invoice_ref_normative_N5_nature',
                        'name'        => 'wc_el_inv-settings-invoice_ref_normative_N5_nature',
                        'label'       => esc_html__('Please set the normative reference to use', WC_EL_INV_TEXTDOMAIN),
                        'description' => sprintf('%s',
                            esc_html__('This regulatory reference will be displayed in the xml and pdf invoice when the transactions are N5 (Exempt) in nature',
                                WC_EL_INV_TEXTDOMAIN)
                        ),
                        'value'       => \WcElectronInvoice\Functions\getN5RefNormative() ?? "Escluso Art.74 ter D.P.R. 633/72",
                    ), $this, $page),
                    'field',
                ),
                'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
                'field_section'  => 'setting_section_invoice',
                'field_args'     => array('class' => 'invoice_ref_normative_N4'),
            );
        }
        $this->fieldsArgs[] = array(
            'field_id'       => 'hr_doc_global_bottom',
            'field_title'    => '',
            'field_callback' => function () {
                echo '<hr>';
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
        );
        // Save xml dir
        $this->fieldsArgs[] = array(
            'field_id'       => 'hr_xml_saving',
            'field_title'    => sprintf(
                '<h4>%s%s</h4>',
                esc_html__('XML Directory', WC_EL_INV_TEXTDOMAIN),
                $premiumSettingsDisabled ? $paidOnlyBadge : ''
            ),
            'field_callback' => function () {
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'invoice_saving_directory_xml_enable',
            'field_title'    => esc_html__('Enable saving to directory', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                    'id'          => 'wc_el_inv-settings-invoice_saving_directory_xml_enable',
                    'name'        => 'wc_el_inv-settings-invoice_saving_directory_xml_enable',
                    'label'       => esc_html__('Enable saving',
                        WC_EL_INV_TEXTDOMAIN),
                    'description' => sprintf('%s',
                        esc_html__('By activating this option you can save the xml file in a directory on your server',
                            WC_EL_INV_TEXTDOMAIN)
                    ),
                    'attrs'       => $premiumFieldAttrs,
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
            'field_args'     => array('class' => 'invoice_product_meta'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'invoice_saving_directory_xml',
            'field_title'    => esc_html__('XML saving directory',
                WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'id'          => 'wc_el_inv-settings-invoice_saving_directory_xml',
                    'name'        => 'wc_el_inv-settings-invoice_saving_directory_xml',
                    'label'       => esc_html__('Please set the directory', WC_EL_INV_TEXTDOMAIN),
                    'description' => sprintf('%s',
                        esc_html__('Sets the directory for saving xml. the xml is saved when the order status changes to "completed". 
                        the default directory is "wp-content/uploads/pop-invoice" - NB: if you use a custom directory the folder must be present on the server',
                            WC_EL_INV_TEXTDOMAIN)
                    ),
                    'attrs'       => $premiumFieldAttrs,
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
            'field_args'     => array('class' => 'invoice_ref_normative_N4'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'hr_xml_saving_bottom',
            'field_title'    => '',
            'field_callback' => function () {
                echo '<hr>';
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
        );
        // PDF
        $this->fieldsArgs[] = array(
            'field_id'       => 'hr_pdf',
            'field_title'    => sprintf('<h4>%s</h4>', esc_html__('PDF Documents', WC_EL_INV_TEXTDOMAIN)),
            'field_callback' => function () {
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'invoice_in_my_orders_options_fields',
            'field_title'    => esc_html__('My Orders documents', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                    'id'          => 'wc_el_inv-settings-invoice_in_my_orders',
                    'name'        => 'wc_el_inv-settings-invoice_in_my_orders',
                    'label'       => esc_html__('Download PDF', WC_EL_INV_TEXTDOMAIN),
                    'description' => esc_html__('Activate to view the link to download the pdf in the list of orders in my account',
                        WC_EL_INV_TEXTDOMAIN),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
            'field_args'     => array('class' => 'invoice_in_my_orders'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'invoice_via_email_options_fields',
            'field_title'    => esc_html__('Email documents', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                    'id'          => 'wc_el_inv-settings-invoice_via_email',
                    'name'        => 'wc_el_inv-settings-invoice_via_email',
                    'label'       => esc_html__('Proforma invoice via email', WC_EL_INV_TEXTDOMAIN),
                    'description' => esc_html__('Active the sending of the invoice/receipt in PDF format via e-mail upon completion of the order',
                        WC_EL_INV_TEXTDOMAIN),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
            'field_args'     => array('class' => 'invoice_via_email'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'invoice_html_options_fields',
            'field_title'    => esc_html__('HTML documents', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                    'id'          => 'wc_el_inv-settings-invoice_html',
                    'name'        => 'wc_el_inv-settings-invoice_html',
                    'label'       => esc_html__('(*) Generate proforma in HTML', WC_EL_INV_TEXTDOMAIN),
                    'description' => sprintf('%s - (*) %s',
                        esc_html__('View the invoice (pdf) in HTML - (activate only if the PDF generation presents problems)',
                            WC_EL_INV_TEXTDOMAIN),
                        esc_html__('NB: by activating this option the document will not be attached to the email',
                            WC_EL_INV_TEXTDOMAIN)
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
            'field_args'     => array('class' => 'invoice_html'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'invoice_pdf_logo_url_options_fields',
            'field_title'    => esc_html__('PDF Logo', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Text(array(
                    'type'        => 'url',
                    'id'          => 'wc_el_inv-settings-invoice_pdf_logo_url',
                    'name'        => 'wc_el_inv-settings-invoice_pdf_logo_url',
                    'description' => sprintf('%s - %s',
                        esc_html__('Enter the url of the logo for the invoice (.jpg format)',
                            WC_EL_INV_TEXTDOMAIN),
                        esc_html__('(Leave the field blank if you want the company name to be inserted as text)',
                            WC_EL_INV_TEXTDOMAIN)
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
            'field_args'     => array('class' => 'invoice_pdf_logo'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'invoice_pdf_footer_options_fields',
            'field_title'    => esc_html__('PDF footer text', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\TextArea(array(
                    'id'          => 'wc_el_inv-settings-invoice_pdf_footer',
                    'name'        => 'wc_el_inv-settings-invoice_pdf_footer',
                    'description' => esc_html__('Enter the text for the PDF invoice footer.', WC_EL_INV_TEXTDOMAIN),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
            'field_args'     => array('class' => 'invoice_pdf_footer'),
        );
        $this->fieldsArgs[] = array(
            'field_id'       => 'hr_pdf_bottom',
            'field_title'    => '',
            'field_callback' => function () {
                echo '<hr>';
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_invoice',
        );

        if ('IT' === \WcElectronInvoice\WooCommerce\Fields\GeneralFields::getGeneralInvoiceOptionCountryState()) {
            // Stamp duty
            $this->fieldsArgs[] = array(
                'field_id'       => 'hr_stamp_duty',
                'field_title'    => sprintf('<h4>%s</h4>', esc_html__('Stamp duty', WC_EL_INV_TEXTDOMAIN)),
                'field_callback' => function () {
                },
                'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
                'field_section'  => 'setting_section_invoice',
            );
            $this->fieldsArgs[] = array(
                'field_id'       => 'add_stamp_duty_options_fields',
                'field_title'    => esc_html__('Add virtual stamp duty on invoices', WC_EL_INV_TEXTDOMAIN),
                'field_callback' => array(
                    new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                        'id'          => 'wc_el_inv-settings-add_stamp_duty',
                        'name'        => 'wc_el_inv-settings-add_stamp_duty',
                        'label'       => esc_html__('Add virtual stamp', WC_EL_INV_TEXTDOMAIN),
                        'description' => esc_html__('The duty stamp must be applied when electronic invoices (and pdfs) are issued without VAT and if the amount exceeds 77.47€.',
                            WC_EL_INV_TEXTDOMAIN),
                    ), $this, $page),
                    'field',
                ),
                'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
                'field_section'  => 'setting_section_invoice',
                'field_args'     => array('class' => 'add_stamp_duty'),
            );
        }

        /**
         * Extend options fields
         */
        do_action('wc_el_inv-page_setting_section_invoice', $section, $this->sectionArgs, $this->fieldsArgs);

        if ('IT' === \WcElectronInvoice\WooCommerce\Fields\GeneralFields::getGeneralInvoiceOptionCountryState()) {
            // Close section
            if (! doing_action('wc_el_inv-page_setting_section_invoice')) {
                $this->fieldsArgs[] = array(
                    'field_id'       => 'hr_doc_stamp_duty_bottom',
                    'field_title'    => '',
                    'field_callback' => function () {
                        echo '<hr>';
                    },
                    'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
                    'field_section'  => 'setting_section_invoice',
                );
            }
        }

        break;
    // Provider Integration
    case 'setting_section_provider-integration':
        $this->sectionArgs['wc_el_inv_settings'] = array(
            'section_id'       => 'setting_section_provider-integration',
            'section_title'    => '', //esc_html__('Checkout', WC_EL_INV_TEXTDOMAIN),
            'section_callback' => array($page, 'fieldsVatRules'),
            'section_page'     => 'wc_el_inv-options-page',
        );
        $this->fieldsArgs[]                      = array(
            'field_id'       => 'checkout_title',
            'field_title'    => sprintf('<h4>%s</h4>', esc_html__('Checkout', WC_EL_INV_TEXTDOMAIN)),
            'field_callback' => function () {
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_provider-integration',
        );
        $this->fieldsArgs[]                      = array(
            'field_id'       => 'invoice_required_options_fields',
            'field_title'    => esc_html__('VAT number and tax code for EU customers',
                WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Radio(array(
                    'id'          => 'wc_el_inv-settings-invoice_required',
                    'name'        => 'wc_el_inv-settings-invoice_required',
                    'description' => '',
                    'default'     => 'not-required',
                    'class'       => ! checkOptions('checkout') ? 'field-verification' : '',
                    'options'     => array(
                        'required'     => esc_html__('Yes, make the fields required', WC_EL_INV_TEXTDOMAIN),
                        'not-required' => esc_html__('No, don\'t make the fields required', WC_EL_INV_TEXTDOMAIN),
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_provider-integration',
            'field_args'     => array('class' => 'invoice_required'),
        );
        $this->fieldsArgs[]                      = array(
            'field_id'       => 'hide_outside_ue_options_fields',
            'field_title'    => esc_html__('VAT number and tax code for non-EU customers',
                WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Radio(array(
                    'id'          => 'wc_el_inv-settings-hide_outside_ue',
                    'name'        => 'wc_el_inv-settings-hide_outside_ue',
                    'description' => '',
                    'default'     => 'hide',
                    'options'     => array(
                        'show' => esc_html__('Yes, show fields', WC_EL_INV_TEXTDOMAIN),
                        'hide' => esc_html__('No, don\'t show the fields',
                            WC_EL_INV_TEXTDOMAIN),
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_provider-integration',
            'field_args'     => array('class' => 'hide_outside_ue'),
        );
        // Invoice billing fields position
        $this->fieldsArgs[] = array(
            'field_id'       => 'billing_fields_position_options_fields',
            'field_title'    => esc_html__('Position of the fields (e-invoice) in the checkout form',
                WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Radio(array(
                    'id'          => 'wc_el_inv-settings-billing_fields_position',
                    'name'        => 'wc_el_inv-settings-billing_fields_position',
                    'description' => '',
                    'default'     => 'bottom',
                    'options'     => array(
                        'top'    => sprintf('<img title="%1$s" alt="%1$s" width="80" src="%2$s"><br>%1$s',
                            esc_html__('Place on the head', WC_EL_INV_TEXTDOMAIN),
                            esc_url(WC_EL_INV_URL . 'assets/images/top.png')
                        ),
                        'bottom' => sprintf('<img title="%1$s" alt="%1$s" width="80" src="%2$s"><br>%1$s',
                            esc_html__('Place on the bottom', WC_EL_INV_TEXTDOMAIN),
                            esc_url(WC_EL_INV_URL . 'assets/images/bottom.png')
                        ),
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_provider-integration',
            'field_args'     => array('class' => 'billing_fields_position'),
        );
        // Billing type list
        $this->fieldsArgs[] = array(
            'field_id'       => 'billing_invoice_type_list_options_fields',
            'field_title'    => esc_html__('Customer type list', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\TextArea(array(
                    'id'           => 'wc_el_inv-settings-billing_invoice_type_list',
                    'name'         => 'wc_el_inv-settings-billing_invoice_type_list',
                    'label_html'   => sprintf('<img id="billing_invoice_type" alt="%1$s" src="%2$s">',
                        esc_html__('Customer type list', WC_EL_INV_TEXTDOMAIN),
                        esc_url(WC_EL_INV_URL . 'assets/images/customer_type.jpg')
                    ),
                    'description'  => sprintf('%s - %s - %s',
                        esc_html__('Enter the list in the order you prefer (remember that the "company, freelance, private" keys cannot be modified)',
                            WC_EL_INV_TEXTDOMAIN),
                        esc_html__('Format: (key:Label) enter one "key:Label" per line without spaces',
                            WC_EL_INV_TEXTDOMAIN),
                        esc_html__('To insert label composed of multiple words, use "_" e.g. Custom_customer',
                            WC_EL_INV_TEXTDOMAIN)
                    ),
                    'value'        => "private:Private\ncompany:Company\nfreelance:Freelance",
                    'allowed_html' => false,
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_provider-integration',
            'field_args'     => array('class' => 'invoice_type_list'),
        );
        // Checkbox checkout option
        $this->fieldsArgs[] = array(
            'field_id'       => 'invoice_choice_type_options_fields',
            'field_title'    => esc_html__('Invoice or Receipt', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                    'id'          => 'wc_el_inv-settings-invoice_choice_type',
                    'name'        => 'wc_el_inv-settings-invoice_choice_type',
                    'label'       => esc_html__('Activate the choice of receipt', WC_EL_INV_TEXTDOMAIN),
                    'description' => esc_html__('Activate the select for choosing the type of document (invoice or receipt)',
                            WC_EL_INV_TEXTDOMAIN) . ' - ' .
                                     esc_html__('Attention: if the customer chooses the receipt in this case a tax document will have to be issued.',
                                         WC_EL_INV_TEXTDOMAIN
                                     ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_provider-integration',
            'field_args'     => array('class' => 'invoice_choice_type'),
        );
        if (! \WcElectronInvoice\Integrations::isPeppolContext()) {
            $this->fieldsArgs[] = array(
                'field_id'       => 'invoice_disable_pec_sdi_options_fields',
                'field_title'    => esc_html__('Disable PEC/SDI', WC_EL_INV_TEXTDOMAIN),
                'field_callback' => array(
                    new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                        'id'          => 'wc_el_inv-settings-invoice_disable_pec_sdi',
                        'name'        => 'wc_el_inv-settings-invoice_disable_pec_sdi',
                        'label'       => esc_html__('Disable PEC/unique code field in (checkout / my-account)',
                            WC_EL_INV_TEXTDOMAIN),
                        'description' => sprintf('%s',
                            esc_html__('Disable the PEC/unique code field in the checkout (the recipient code will be set to "0000000")',
                                WC_EL_INV_TEXTDOMAIN)
                        ),
                    ), $this, $page),
                    'field',
                ),
                'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
                'field_section'  => 'setting_section_provider-integration',
                'field_args'     => array('class' => 'invoice_disable_pec_sdi'),
            );
            $this->fieldsArgs[] = array(
                'field_id'       => 'invoice_disable_cf_options_fields',
                'field_title'    => esc_html__('Disable Fiscal Code', WC_EL_INV_TEXTDOMAIN),
                'field_callback' => array(
                    new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                        'id'          => 'wc_el_inv-settings-invoice_disable_cf',
                        'name'        => 'wc_el_inv-settings-invoice_disable_cf',
                        'label'       => esc_html__('Disable the tax code field in (checkout / my-account)',
                            WC_EL_INV_TEXTDOMAIN),
                        'description' => sprintf('%s',
                            esc_html__('Disable the tax code from the checkout and from my-account (only for companies and freelancers)',
                                WC_EL_INV_TEXTDOMAIN)
                        ),
                    ), $this, $page),
                    'field',
                ),
                'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
                'field_section'  => 'setting_section_provider-integration',
                'field_args'     => array('class' => 'invoice_disable_cf'),
            );
            $this->fieldsArgs[] = array(
                'field_id'       => 'invoice_active_js_cf_check_options_fields',
                'field_title'    => esc_html__('Verify Tax Code', WC_EL_INV_TEXTDOMAIN),
                'field_callback' => array(
                    new \WcElectronInvoice\Admin\Settings\Fields\Checkbox(array(
                        'id'          => 'wc_el_inv-settings-invoice_active_js_cf_check',
                        'name'        => 'wc_el_inv-settings-invoice_active_js_cf_check',
                        'label'       => esc_html__('Enable checking of the tax code field (client side)',
                            WC_EL_INV_TEXTDOMAIN),
                        'description' => sprintf('%s',
                            esc_html__('By activating the control of the Fiscal Code only for the "Private" customer type, the value of the Fiscal Code will be validated through a correspondence between the Fiscal Code and the Name and Surname fields',
                                WC_EL_INV_TEXTDOMAIN)
                        ),
                    ), $this, $page),
                    'field',
                ),
                'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
                'field_section'  => 'setting_section_provider-integration',
                'field_args'     => array('class' => 'invoice_active_js_cf_check'),
            );
        }
        break;
    // Xml Invoice Tab
    case 'setting_section_xml':
        $this->sectionArgs['wc_el_inv_settings'] = array(
            'section_id'       => 'setting_section_xml',
            'section_title'    => array(//esc_html__('Invoice table', WC_EL_INV_TEXTDOMAIN),
            ),
            // After option form
            'section_callback' => function () {
                new \WcElectronInvoice\Admin\Settings\Fields\XmlOrdersList();
            },
            'section_page'     => 'wc_el_inv-options-page',
        );
        break;
    // Advanced
    case 'setting_section_advanced':
        $this->sectionArgs['wc_el_inv_settings'] = array(
            'section_id'       => 'setting_section_advanced',
            'section_title'    => '',
            'section_callback' => function () {
                echo '<nav class="nav_section_advanced" id="wc_output_fields_nav"><ul>';
                /**
                 * Extend nav
                 */
                do_action('wc_el_inv-page_setting_provider_integration_nav');

                $sanMarinoSupport = \WcElectronInvoice\Functions\sanMarinoSupport();
                $shopCountry      = \WcElectronInvoice\WooCommerce\Fields\GeneralFields::getGeneralInvoiceOptionCountryState();
                if ('IT' === $shopCountry || 'SM' === $sanMarinoSupport->shopCountry ||
                    in_array($shopCountry, \WcElectronInvoice\Xml\CreateXml::$allowedUBLZone)
                ) {
                    echo sprintf('<li><a href="#automatic-sending">%s</a></li>',
                        esc_html__('Automatic invoice sending', WC_EL_INV_TEXTDOMAIN)
                    );
                }

                echo sprintf('<li><a href="#webhook">%s</a></li>',
                    esc_html__('Webhook', WC_EL_INV_TEXTDOMAIN)
                );

                echo sprintf('<li><a href="#import-export">%s</a></li>',
                    esc_html__('Import/Export', WC_EL_INV_TEXTDOMAIN)
                );
                echo '</ul></nav>';
            },
            'section_page'     => 'wc_el_inv-options-page',
        );
        $this->fieldsArgs[]                      = array(
            'field_id'       => 'export_collections_options_fields',
            'field_title'    => esc_html__('Export options', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\TextArea(array(
                    'id'          => 'wc_el_inv-settings-export_collections',
                    'name'        => 'wc_el_inv-settings-export_collections',
                    'description' => esc_html__('Copy this collection of options to import your POP configuration into another installation',
                        WC_EL_INV_TEXTDOMAIN),
                    'value'       => OptionPage::init()->getOptionJsonCollections(),
                    'attrs'       => array(
                        'readonly' => 'readonly',
                    ),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_advanced',
            'field_args'     => array('class' => 'export_collections'),
        );
        $this->fieldsArgs[]                      = array(
            'field_id'       => 'import_collections_options_fields',
            'field_title'    => esc_html__('Import options', WC_EL_INV_TEXTDOMAIN),
            'field_callback' => array(
                new \WcElectronInvoice\Admin\Settings\Fields\TextArea(array(
                    'id'          => 'wc_el_inv-settings-import_collections',
                    'name'        => 'wc_el_inv-settings-import_collections',
                    'description' => esc_html__('Paste the options collection from another installation here to import the POP configuration',
                        WC_EL_INV_TEXTDOMAIN),
                ), $this, $page),
                'field',
            ),
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_advanced',
            'field_args'     => array('class' => 'import_collections'),
        );
        // Reverse charge
        $this->fieldsArgs[] = array(
            'field_id'       => 'reverse_charge_options_fields',
            'field_title'    => '',
            'field_callback' => function () {
                /**
                 * Extend fields
                 */
                do_action('wc_el_inv-page_setting_provider_integration_fields');
                /**
                 * Reverse options for all provider
                 */
                if (! \WcElectronInvoice\Functions\isWooCommerceActive() &&
                    \WcElectronInvoice\Functions\haveAnActiveProvider() &&
                    in_array(\WcElectronInvoice\WooCommerce\Fields\GeneralFields::getGeneralInvoiceOptionCountryState(),
                        \WcElectronInvoice\WooCommerce\Fields\GeneralFields::getEuCountries())
                ) {
                    $level = \WcElectronInvoice\Wizard::popGetUserLevel();
                    add_action('wc_el_inv-page_setting_provider_integration_fields', function () {
                        $shopCountry             = \WcElectronInvoice\WooCommerce\Fields\GeneralFields::getGeneralInvoiceOptionCountryState();
                        $level                   = \WcElectronInvoice\Wizard::popGetUserLevel();
                        $premiumDisabled         = ! \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic');
                        $paidOnlyBadge           = sprintf(
                            ' <span class="pop-premium-badge">%s</span>',
                            esc_html__('Paid only', WC_EL_INV_TEXTDOMAIN)
                        );
                        $premiumCustomAttributes = $premiumDisabled ? array(
                            'disabled' => 'disabled',
                            'readonly' => 'readonly',
                        ) : array();
                        if ('ES' === $shopCountry) {
                            $nature = include \WcElectronInvoice\Plugin::getPluginDirPath('/inc/wc/nature-es.php');
                        } else {
                            $nature = include \WcElectronInvoice\Plugin::getPluginDirPath('/inc/wc/nature.php');
                        }
                        echo '<div class="ReverseChargeData_output_fields">';
                        $taxInvoiceFields = apply_filters('wc_el_inv-reverse_charge_inputs_args', array(
                            array(
                                'title_html' => sprintf(
                                    '%s%s',
                                    esc_html__('Reverse Charge', WC_EL_INV_TEXTDOMAIN),
                                    $premiumDisabled ? $paidOnlyBadge : ''
                                ),
                                'type'       => 'title',
                                'desc'       => '',
                                'id'         => 'reverse_charge_invoice',
                            ),

                            ...\WcElectronInvoice\WooCommerce\Fields\ReverseChargeSettings::getSettingsMappingFields(
                                ! empty($nature) ? $nature : array(),
                                $premiumCustomAttributes,
                                $shopCountry
                            ),

                            array(
                                'type' => 'sectionend',
                                'id'   => 'tax_invoice',
                            ),
                        ));
                        // Reverse Charge fields
                        \WcElectronInvoice\Admin\Settings\TableFields::output((array)$taxInvoiceFields);
                        echo '</div>';
                    });
                }
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_advanced',
            'field_args'     => array('class' => 'reverse_charge'),
        );
        // Automatic sending
        $this->fieldsArgs[] = array(
            'field_id'       => 'automatic_sending_options_fields',
            'field_title'    => '',
            'field_callback' => function () {
                $sanMarinoSupport = \WcElectronInvoice\Functions\sanMarinoSupport();
                $shopCountry      = \WcElectronInvoice\WooCommerce\Fields\GeneralFields::getGeneralInvoiceOptionCountryState();
                $paidOnlyBadge    = sprintf(
                    ' <span class="pop-premium-badge">%s</span>',
                    esc_html__('Paid only', WC_EL_INV_TEXTDOMAIN)
                );

                $level                       = \WcElectronInvoice\Wizard::popGetUserLevel();
                $getSdiPOPIntegrationData    = InvoiceApi::getSdiPOPIntegrationData();
                $getPEPPOLPOPIntegrationData = \WcElectronInvoice\PeppolApi::getPEPPOLPOPIntegrationData();
                $getKSeFPOPIntegrationData   = \WcElectronInvoice\KsefApi::getKsefPOPIntegrationData();
                $getZohoPOPIntegrationData   = \WcElectronInvoice\ZohoApi::getZohoPOPIntegrationData();
                $activeInvoiceChannel        = \WcElectronInvoice\Integrations::resolveActiveInvoiceChannel();
                echo '<div class="AutomaticInvoiceSending_output_fields">';

                $statusDesc = $timeDesc = '';
                $automaticSendingEnabled = \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic');

                if (\WcElectronInvoice\Integrations::CHANNEL_ZOHO === $activeInvoiceChannel) {
                    $statusDesc = esc_html__('Select the order status (e.g., completed, processing, etc.) that should trigger the automatic invoice sync with Zoho. When an order reaches the selected status, a cron job will be scheduled to automatically send the document through the Zoho sync route.',
                        WC_EL_INV_TEXTDOMAIN);
                    $timeDesc   = esc_html__('Specify how many hours should pass after the selected order status is set before automatically syncing the document with Zoho. The value defines the delay time, in hours, before the cron job is triggered.',
                        WC_EL_INV_TEXTDOMAIN);
                    $automaticSendingEnabled = $automaticSendingEnabled &&
                                               $getZohoPOPIntegrationData->active_plugin_integration &&
                                               $getZohoPOPIntegrationData->zoho_integration;
                } elseif ('IT' === $shopCountry || 'SM' === $sanMarinoSupport->shopCountry) {
                    $statusDesc = esc_html__('Select the order status (e.g., completed, processing, etc.) that should trigger the automatic invoice submission to SDI. When an order reaches the selected status, a cron job will be scheduled to automatically send the invoice to the Italian Exchange System (SDI).',
                        WC_EL_INV_TEXTDOMAIN);
                    $timeDesc   = esc_html__('Specify how many hours should pass after the selected order status is set before automatically sending the invoice to SDI. The value defines the delay time, in hours, before the cron job for invoice submission is triggered.',
                        WC_EL_INV_TEXTDOMAIN);
                    $automaticSendingEnabled = $automaticSendingEnabled &&
                                               $getSdiPOPIntegrationData->active_plugin_integration;
                } elseif (\WcElectronInvoice\Integrations::CHANNEL_KSEF === $activeInvoiceChannel) {
                    $statusDesc = esc_html__('Select the order status (e.g., completed, processing, etc.) that should trigger the automatic invoice submission to KSeF. When an order reaches the selected status, a cron job will be scheduled to automatically send the invoice through the Polish KSeF system.',
                        WC_EL_INV_TEXTDOMAIN);
                    $timeDesc   = esc_html__('Specify how many hours should pass after the selected order status is set before automatically sending the invoice to KSeF. The value defines the delay time, in hours, before the cron job for invoice submission is triggered.',
                        WC_EL_INV_TEXTDOMAIN);
                    $automaticSendingEnabled = $automaticSendingEnabled &&
                                               $getKSeFPOPIntegrationData->active_plugin_integration &&
                                               $getKSeFPOPIntegrationData->ksef_integration;
                } elseif (in_array($shopCountry, \WcElectronInvoice\Xml\CreateXml::$allowedUBLZone)) {
                    $statusDesc = esc_html__('Select the order status (e.g., completed, processing, etc.) that should trigger the automatic invoice submission via PEPPOL. When an order reaches the selected status, a cron job will be scheduled to automatically send the invoice through the PEPPOL network.',
                        WC_EL_INV_TEXTDOMAIN);
                    $timeDesc   = esc_html__('Specify how many hours should pass after the selected order status is set before automatically sending the invoice via PEPPOL. The value defines the delay time, in hours, before the cron job for invoice submission through the PEPPOL network is triggered.',
                        WC_EL_INV_TEXTDOMAIN);
                    $automaticSendingEnabled = $automaticSendingEnabled &&
                                               $getPEPPOLPOPIntegrationData->active_plugin_integration &&
                                               $getPEPPOLPOPIntegrationData->peppol_integration;
                }

                $sdiPOPAutomations = apply_filters('wc_el_inv-automatic_sending_inputs_args', array(
                    array(
                        'title_html' => sprintf(
                            '%s%s',
                            esc_html__('Automations', WC_EL_INV_TEXTDOMAIN),
                            ! \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic') ? $paidOnlyBadge : ''
                        ),
                        'type'       => 'title',
                        'desc'       => '',
                        'id'         => 'automatic_sending_invoice',
                    ),
                    array(
                        'id'                => 'wc_el_inv-enable_automatic_sending',
                        'type'              => 'checkbox',
                        'title'             => esc_html__('Automatic sending:', WC_EL_INV_TEXTDOMAIN),
                        'desc'              => esc_html__('Enable automatic sending', WC_EL_INV_TEXTDOMAIN),
                        'class'             => 'enable-automatic-sending',
                        'desc_tip'          => false,
                        'default'           => '',
                        'custom_attributes' => array(
                            $automaticSendingEnabled ? false : 'disabled' => 'disabled',
                            $automaticSendingEnabled ? false : 'readonly' => 'readonly',
                        ),
                    ),
                    array(
                        'id'                => 'wc_el_inv-automatic_sending_status',
                        'type'              => 'select',
                        'title'             => esc_html__('Auto-send status:', WC_EL_INV_TEXTDOMAIN),
                        'desc'              => '<small>' . $statusDesc . '</small>',
                        'options'           => apply_filters('wc_el_inv-sdi_pop_cron_job_statuses', [
                            'completed'  => __('Completed', WC_EL_INV_TEXTDOMAIN),
                            'processing' => __('Processing', WC_EL_INV_TEXTDOMAIN),
                        ]),
                        'class'             => 'wc-enhanced-select automatic-sending-status-select',
                        'desc_tip'          => false,
                        'default'           => '',
                        'custom_attributes' => array(
                            $automaticSendingEnabled ? false : 'disabled' => 'disabled',
                            $automaticSendingEnabled ? false : 'readonly' => 'readonly',
                        ),
                    ),
                    array(
                        'id'                => 'wc_el_inv-automatic_sending_time',
                        'type'              => 'number',
                        'title'             => esc_html__('Delay before sending (in hours)', WC_EL_INV_TEXTDOMAIN),
                        'desc'              => '<small>' . $timeDesc . '</small>',
                        'class'             => 'automatic-sending-time',
                        'desc_tip'          => false,
                        'default'           => '1',
                        'custom_attributes' => array(
                            $automaticSendingEnabled ? false : 'disabled' => 'disabled',
                            $automaticSendingEnabled ? false : 'readonly' => 'readonly',
                        ),
                    ),
                    array(
                        'type' => 'sectionend',
                        'id'   => 'automatic_sending',
                    ),
                ));

                \WcElectronInvoice\Admin\Settings\TableFields::output((array)$sdiPOPAutomations);
                echo '</div>';
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_advanced',
            'field_args'     => array('class' => 'automatic_sending'),
        );
        // Webhook
        $this->fieldsArgs[] = array(
            'field_id'       => 'pop_webhook_options_fields',
            'field_title'    => '',
            'field_callback' => function () {
                $level         = \WcElectronInvoice\Wizard::popGetUserLevel();
                $paidOnlyBadge = sprintf(
                    ' <span class="pop-premium-badge">%s</span>',
                    esc_html__('Paid only', WC_EL_INV_TEXTDOMAIN)
                );
                echo '<div class="POPWebhook_output_fields">';
                $popWebhook = apply_filters('wc_el_inv-pop_webhook_inputs_args', array(
                    array(
                        'title_html' => sprintf(
                            '%s%s',
                            esc_html__('Webhook', WC_EL_INV_TEXTDOMAIN),
                            ! \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic') ? $paidOnlyBadge : ''
                        ),
                        'type'       => 'title',
                        'desc'       => '',
                        'id'         => 'pop_webhook',
                    ),
                    array(
                        'id'                => 'wc_el_inv-enable_pop_webhook',
                        'type'              => 'checkbox',
                        'title'             => esc_html__('Active:', WC_EL_INV_TEXTDOMAIN),
                        'desc'              => esc_html__('Enable webhook', WC_EL_INV_TEXTDOMAIN),
                        'class'             => 'enable-pop-webhook',
                        'desc_tip'          => false,
                        'default'           => '',
                        'custom_attributes' => array(
                            \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic') ?
                                false : 'disabled' => 'disabled',
                            \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic') ?
                                false : 'readonly' => 'readonly',
                        ),
                    ),
                    array(
                        'id'                => 'wc_el_inv-pop_webhook_id',
                        'type'              => 'text',
                        'title'             => esc_html__('Webhook id', WC_EL_INV_TEXTDOMAIN),
                        'desc'              => '<small>' . esc_html__('Copy the webhook id from your account > integrations > webhook and enter the id you want to activate here.',
                                WC_EL_INV_TEXTDOMAIN) . '</small>',
                        'class'             => 'pop-webhook-id',
                        'desc_tip'          => false,
                        'default'           => '',
                        'placeholder'       => 'popWh_9fuitylf',
                        'custom_attributes' => array(
                            \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic') ?
                                false : 'disabled' => 'disabled',
                            \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic') ?
                                false : 'readonly' => 'readonly',
                        ),
                    ),
                    array(
                        'id'                => 'wc_el_inv-enable_automatic_sending_webhook',
                        'type'              => 'checkbox',
                        'title'             => esc_html__('Automatic sending:', WC_EL_INV_TEXTDOMAIN),
                        'desc'              => esc_html__('Enable automatic sending', WC_EL_INV_TEXTDOMAIN),
                        'class'             => 'enable-automatic-sending',
                        'desc_tip'          => false,
                        'default'           => '',
                        'custom_attributes' => array(
                            \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic') ?
                                false : 'disabled' => 'disabled',
                            \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic') ?
                                false : 'readonly' => 'readonly',
                        ),
                    ),
                    array(
                        'id'                => 'wc_el_inv-automatic_sending_webhook_status',
                        'type'              => 'select',
                        'title'             => esc_html__('Auto-send status:', WC_EL_INV_TEXTDOMAIN),
                        'desc'              => '<small>' . esc_html__('Select the order status (e.g. completed, processing, etc.) that should trigger automatic sending of the xml invoice or JSON data. When an order reaches the selected status, a cron job will be scheduled to automatically send to the webhook.',
                                WC_EL_INV_TEXTDOMAIN) . '</small>',
                        'options'           => apply_filters('wc_el_inv-webhook_cron_job_statuses', [
                            'completed'  => __('Completed', WC_EL_INV_TEXTDOMAIN),
                            'processing' => __('Processing', WC_EL_INV_TEXTDOMAIN),
                        ]),
                        'class'             => 'wc-enhanced-select automatic-sending-status-select',
                        'desc_tip'          => false,
                        'default'           => '',
                        'custom_attributes' => array(
                            \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic') ?
                                false : 'disabled' => 'disabled',
                            \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic') ?
                                false : 'readonly' => 'readonly',
                        ),
                    ),
                    array(
                        'id'                => 'wc_el_inv-automatic_sending_webhook_time',
                        'type'              => 'number',
                        'title'             => esc_html__('Delay before sending (in hours)', WC_EL_INV_TEXTDOMAIN),
                        'desc'              => '<small>' . esc_html__('Specifies how many hours should elapse after the selected order status is set before automatically sending data to the webhook. The value defines the delay time, in hours, before the cron job is triggered to send.',
                                WC_EL_INV_TEXTDOMAIN) . '</small>',
                        'class'             => 'automatic-sending-time',
                        'desc_tip'          => false,
                        'default'           => '1',
                        'custom_attributes' => array(
                            \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic') ?
                                false : 'disabled' => 'disabled',
                            \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic') ?
                                false : 'readonly' => 'readonly',
                        ),
                    ),
                    array(
                        'type' => 'sectionend',
                        'id'   => 'pop_webhook',
                    ),
                ));
                \WcElectronInvoice\Admin\Settings\TableFields::output((array)$popWebhook);
                echo '</div>';
            },
            'field_page'     => $this->sectionArgs['wc_el_inv_settings']['section_page'],
            'field_section'  => 'setting_section_advanced',
            'field_args'     => array('class' => 'pop_webhook'),
        );
        break;
    // Addon
    case 'setting_section_addon':
        $this->sectionArgs['wc_el_inv_settings'] = array(
            'section_id'       => 'setting_section_addon',
            'section_title'    => array(),
            // After option form
            'section_callback' => function () {
                do_action('wc_el_inv-addon');
            },
            'section_page'     => 'wc_el_inv-options-page',
        );
        break;
    // Integrations
    case 'setting_section_integration':
        // @phpstan-ignore-next-line
        $this->sectionArgs['wc_el_inv_settings'] = array(
            'section_id'       => 'setting_section_integration',
            'section_title'    => array(),
            // After option form
            'section_callback' => function () {
                include \WcElectronInvoice\Plugin::getPluginDirPath('/inc/integrations.php');
                do_action('wc_el_inv-integration');
            },
            'section_page'     => 'wc_el_inv-options-page',
        );
        break;
    default:
        // @phpstan-ignore-next-line
        $this->sectionArgs = array();
        // @phpstan-ignore-next-line
        $this->fieldsArgs[] = array();
        break;
}

/**
 * Extend options fields
 */
// @phpstan-ignore-next-line
do_action('wc_el_inv-page_settings_fields', $section, $this);
