<?php

use WcElectronInvoice\InvoiceApi;
use function WcElectronInvoice\Functions\sanMarinoSupport;

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

<div class="pop-integration-wrapper">
    <h1><span class="dashicons dashicons-store"></span> <?php echo esc_html_x('All integrations', 'integration',
            WC_EL_INV_TEXTDOMAIN); ?></h1>
    <p><?php
        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        echo sprintf("%s<br><small>%s <b>%s</b></small>",
            esc_html_x('Here you will find all our pro extensions to easily integrate advanced solutions and automate your invoicing.',
                'integration', WC_EL_INV_TEXTDOMAIN),
            esc_html_x('Do you have special needs or do you need to integrate other services? Write to us at',
                'integration', WC_EL_INV_TEXTDOMAIN),
            'info@popapi.io'
        ); ?>
    </p>

    <?php
    $shopCountry      = get_option('wc_el_inv-general_store_country', null);
    $sanMarinoSupport = sanMarinoSupport();
    $allowedAddon     = \WcElectronInvoice\Plugin::allowedAddon();
    $list             = \WcElectronInvoice\Functions\getListKeyValue($allowedAddon, 'item_code', 'status');
    $licenseKey       = \WcElectronInvoice\Admin\Settings\OptionPage::init()->getOptions('license_key') ?: null;
    $uidOption        = (int)get_option('pop_account_user_id', false);
    $isWizardCompleted = ! empty($licenseKey) && $uidOption > 0;
    $preWizardMessage  = __('Complete the wizard/activate your plan to use this integration.', WC_EL_INV_TEXTDOMAIN);
    // Addon level >= pro
    $statusFic    = \WcElectronInvoice\Functions\getActiveAddon('WP-POP-FIC', $list);
    $statusFicRc  = \WcElectronInvoice\Functions\getActiveAddon('WP-POP-FIC-RC', $list);
    $statusFicMs  = \WcElectronInvoice\Functions\getActiveAddon('WP-POP-FIC-MS', $list);
    $statusAruba  = \WcElectronInvoice\Functions\getActiveAddon('WP-POP-AR', $list);
    $statusSdiPec = \WcElectronInvoice\Functions\getActiveAddon('WP-POP-SDI-PEC', $list);
    // Addon level >= free
    $czmPms             = \WcElectronInvoice\Functions\getActiveAddon('WP-POP-CZM-PMS', $list);
    $pmPro              = \WcElectronInvoice\Functions\getActiveAddon('WP-POP-PMPRO', $list);
    $isWooCommerceActive  = \WcElectronInvoice\Functions\isWooCommerceActive();
    $showWooEntrypoint    = true;
    $isCozmosActive      = \WcElectronInvoice\Functions\isCozmoslabsPaidMemberSubscriptionsActive();
    $isPmProActive       = \WcElectronInvoice\Functions\isPaidMembershipsProActive();
    $statusCozMosPms     = $isCozmosActive && $czmPms;
    $statusPMPro         = $isPmProActive && $pmPro;
    $hasCozmosEntrypoint = in_array('wc_el_inv-addon-cozmos', \WcElectronInvoice\Integrations::$addonPlugins, true);
    $hasPmProEntrypoint  = in_array('wc_el_inv-addon-pmpro', \WcElectronInvoice\Integrations::$addonPlugins, true);

    $ficActive        = boolval(get_option('wc_el_inv-addon-fattureincloud'));
    $ficStockActive   = boolval(get_option('wc_el_inv-addon-fattureincloud-stock'));
    $ficReceiptActive = boolval(get_option('wc_el_inv-addon-fattureincloud-receipts'));
    $sdiPecActive     = boolval(get_option('wc_el_inv-addon-sdi-pec'));
    $arubaActive      = boolval(get_option('wc_el_inv-addon-aruba'));
    $czmActive        = boolval(get_option('wc_el_inv-addon-cozmos'));
    $pmProActive      = boolval(get_option('wc_el_inv-addon-pmpro'));
    $sdiPOPActive     = boolval(get_option('wc_el_inv-addon-sdi-via-pop'));
    $peppolPOPActive  = boolval(get_option('wc_el_inv-addon-peppol-via-pop'));
    $ksefPOPActive    = boolval(get_option('wc_el_inv-addon-ksef-via-pop'));
    $zohoPOPActive    = boolval(get_option('wc_el_inv-addon-zoho-via-pop'));

    // Sdi via POP
    $statusSdiViaPop = InvoiceApi::getSdiPOPIntegrationData();
    // PEPPOL via POP
    $statusPEPPOLViaPop = \WcElectronInvoice\PeppolApi::getPEPPOLPOPIntegrationData();
    // KSeF via POP
    $statusKSeFViaPop = \WcElectronInvoice\KsefApi::getKsefPOPIntegrationData();
    // Zoho via POP
    $statusZohoViaPop = \WcElectronInvoice\ZohoApi::getZohoPOPIntegrationData();
    $level              = \WcElectronInvoice\Wizard::popGetUserLevel();
    $isBasicLevel       = \WcElectronInvoice\Wizard::isUserLevelGte($level, 'basic');
    $isProLevel         = \WcElectronInvoice\Wizard::isUserLevelGte($level, 'pro');
    $isFreeLevel        = 'free' === $level;
    $isBasicOnlyLevel   = 'basic' === $level;
    $isItalyCountry     = 'IT' === $shopCountry;
    $isItalyEndpointCountry = $isItalyCountry || 'SM' === $sanMarinoSupport->shopCountry;
    $isUblCountry       = defined('WC_EL_INV_UBL_COUNTRIES') && in_array($shopCountry, WC_EL_INV_UBL_COUNTRIES);
    $isPolandCountry    = \WcElectronInvoice\Integrations::isKsefCountryContext($shopCountry);
    $activeInvoiceChannel = \WcElectronInvoice\Integrations::resolveActiveInvoiceChannel();
    $exclusiveInvoiceMessage = __('This site can use only one invoice channel at a time. Disable the current channel before enabling another one.', WC_EL_INV_TEXTDOMAIN);
    $hasExclusiveInvoiceConflict = static function (string $channel) use ($activeInvoiceChannel): bool {
        return \WcElectronInvoice\Integrations::CHANNEL_NONE !== $activeInvoiceChannel &&
               $activeInvoiceChannel !== $channel;
    };
    $sdiPopConflict    = $hasExclusiveInvoiceConflict(\WcElectronInvoice\Integrations::CHANNEL_SDIPOP);
    $arubaConflict     = $hasExclusiveInvoiceConflict(\WcElectronInvoice\Integrations::CHANNEL_ARUBA);
    $ficConflict       = $hasExclusiveInvoiceConflict(\WcElectronInvoice\Integrations::CHANNEL_FIC);
    $sdiPecConflict    = $hasExclusiveInvoiceConflict(\WcElectronInvoice\Integrations::CHANNEL_SDIPEC);
    $peppolConflict    = $hasExclusiveInvoiceConflict(\WcElectronInvoice\Integrations::CHANNEL_PEPPOL);
    $ksefConflict      = $hasExclusiveInvoiceConflict(\WcElectronInvoice\Integrations::CHANNEL_KSEF);
    $zohoConflict      = $hasExclusiveInvoiceConflict(\WcElectronInvoice\Integrations::CHANNEL_ZOHO);
    $upgradePlansMessage = 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)
    );
    ?>
    <div class="integration-wrapper">
        <div class="integration">
            <?php
            // Global Addon Entrypoint
            if ($showWooEntrypoint || $hasCozmosEntrypoint || $hasPmProEntrypoint) : ?>
                <h3 style="padding: 0 15px;"><?php echo esc_html__('Entrypoint:', WC_EL_INV_TEXTDOMAIN); ?></h3>
                <div class="d-flex">
                    <!-- woocommerce --->
                    <div class="col-3">
                        <div title="<?php echo ! $isWooCommerceActive ? esc_html__('not available',
                            WC_EL_INV_TEXTDOMAIN) : esc_html__('available', WC_EL_INV_TEXTDOMAIN); ?>"
                             class="tooltip-trigger card <?php echo ! $isWooCommerceActive ? 'disabled' : 'plugin-active'; ?>">
                            <img alt="pop-woocommerce"
                                 src="<?php echo "https://pub.popapi.io/assets/integrations/pop-woocommerce.jpg"; ?>">
                            <h5><?php echo esc_html__('WooCommerce', WC_EL_INV_TEXTDOMAIN); ?></h5>
                            <p><?php echo _x('POP was born on WooCommerce and knows it deeply: manage the entire e-invoicing cycle.',
                                    'integration_info', WC_EL_INV_TEXTDOMAIN); ?></p>
                            <a target="_blank" href="https://popapi.io/integration/woocommerce/">
                                <span class="dashicons dashicons-arrow-right-alt"></span> <?php echo esc_html__('Documentation',
                                    WC_EL_INV_TEXTDOMAIN); ?>
                            </a>
                        </div>
                    </div>
                    <!-- pmpro --->
                    <?php if ($hasPmProEntrypoint) : ?>
                        <div class="col-3">
                            <div title="<?php echo ! $statusPMPro ?
                                esc_html__('not available', WC_EL_INV_TEXTDOMAIN) :
                                esc_html__('available', WC_EL_INV_TEXTDOMAIN); ?>"
                                 data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                 data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"
                                 class="tooltip-trigger card save-option-button <?php echo ! $statusPMPro ? 'disabled' : '';
                                 echo $pmProActive && class_exists('POPxPMPro\Plugin') ? 'plugin-active' : ''; ?>"
                                 data-option-name="wc_el_inv-addon-pmpro"
                                 data-option-value="<?php echo $pmProActive ? 0 : 1 ?>">
                                <span class="integration_button"
                                      data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                      data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"></span>
                                <img alt="pop-pmpro"
                                     src="<?php echo "https://pub.popapi.io/assets/integrations/pop-paid-memberships-pro.jpg"; ?>">
                                <h5><?php echo _x('Paid Memberships Pro', 'integration_info',
                                        WC_EL_INV_TEXTDOMAIN); ?></h5>
                                <p><?php echo _x('Automate e-invoicing for your WordPress subscriptions and ensure full tax compliance with no hassle.',
                                        'integration_info', WC_EL_INV_TEXTDOMAIN); ?></p>
                                <a target="_blank" href="https://popapi.io/integration/paid-memberships-pro/">
                                    <span class="dashicons dashicons-arrow-right-alt"></span> <?php echo esc_html__('Documentation',
                                        WC_EL_INV_TEXTDOMAIN); ?>
                                </a>
                                <?php
                                if (! $statusPMPro) : ?>
                                    <?php if (! $isWizardCompleted || $isPmProActive) : ?>
                                        <div class="custom-tooltip"><?php echo esc_html($preWizardMessage); ?></div>
                                    <?php else : ?>
                                        <div class="custom-tooltip"><?php echo sprintf('%s <a href="https://popapi.io/integrazioni/paid-memberships-pro/" target="_blank">%s</a></a>',
                                                __('Activate the related plugin first.', WC_EL_INV_TEXTDOMAIN),
                                                __('Learn how', WC_EL_INV_TEXTDOMAIN)
                                            ); ?>
                                        </div>
                                    <?php endif; ?>
                                <?php endif; ?>
                            </div>
                        </div>
                    <?php endif; ?>
                    <!-- cozmos --->
                    <?php if ($hasCozmosEntrypoint) : ?>
                        <div class="col-3">
                            <div title="<?php echo ! $statusCozMosPms ?
                                esc_html__('not available', WC_EL_INV_TEXTDOMAIN) :
                                esc_html__('available', WC_EL_INV_TEXTDOMAIN); ?>"
                                 data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                 data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"
                                 class="tooltip-trigger card save-option-button <?php echo ! $statusCozMosPms ? 'disabled' : '';
                                 echo $czmActive && class_exists('WooPoPCozmosLabsPMS\Plugin') ? 'plugin-active' : ''; ?>"
                                 data-option-name="wc_el_inv-addon-cozmos"
                                 data-option-value="<?php echo $czmActive ? 0 : 1 ?>">
                                <span class="integration_button"
                                      data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                      data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"></span>
                                <img alt="pop-cozmos"
                                     src="<?php echo "https://pub.popapi.io/assets/integrations/pop-paid-member-subscriptions.jpg"; ?>">
                                <h5><?php echo _x('Paid Member Subscriptions', 'integration_info',
                                        WC_EL_INV_TEXTDOMAIN); ?></h5>
                                <p><?php echo _x('Automate e-invoicing for your subscriptions and manage everything from WordPress, with a single tool.',
                                        'integration_info', WC_EL_INV_TEXTDOMAIN); ?></p>
                                <a target="_blank" href="https://popapi.io/integration/paid-member-subscriptions/">
                                    <span class="dashicons dashicons-arrow-right-alt"></span> <?php echo esc_html__('Documentation',
                                        WC_EL_INV_TEXTDOMAIN); ?>
                                </a>
                                <?php
                                if (! $statusCozMosPms) : ?>
                                    <?php if (! $isWizardCompleted || $isCozmosActive) : ?>
                                        <div class="custom-tooltip"><?php echo esc_html($preWizardMessage); ?></div>
                                    <?php else : ?>
                                        <div class="custom-tooltip"><?php echo sprintf('%s <a href="https://popapi.io/integrazioni/paid-member-subscriptions/" target="_blank">%s</a></a>',
                                                __('Activate the related plugin first.', WC_EL_INV_TEXTDOMAIN),
                                                __('Learn how', WC_EL_INV_TEXTDOMAIN)
                                            ); ?>
                                        </div>
                                    <?php endif; ?>
                                <?php endif; ?>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            <?php endif; ?>
            <?php // Addon Endpoint for italy ?>
                <h3 style="padding: 0 15px;"><?php echo esc_html__('Endpoint:', WC_EL_INV_TEXTDOMAIN); ?></h3>

                <div class="d-flex">
                    <!-- sdi via pop --->
                    <div class="col-3">
                        <div title="<?php echo ! $statusSdiViaPop->active_integration || ! $isBasicLevel || ! $isItalyEndpointCountry ?
                            esc_html__('not available', WC_EL_INV_TEXTDOMAIN) : esc_html__('available',
                                WC_EL_INV_TEXTDOMAIN); ?>"
                             class="tooltip-trigger card save-option-button <?php echo ! $statusSdiViaPop->active_integration || ! $isBasicLevel || ! $isItalyEndpointCountry || $sdiPopConflict ? 'disabled' : ''; ?> <?php if ($statusSdiViaPop->active_integration && $sdiPOPActive): ?>plugin-active<?php endif; ?>"
                             data-option-name="wc_el_inv-addon-sdi-via-pop"
                             data-option-value="<?php echo $statusSdiViaPop->active_integration && $sdiPOPActive ? 0 : 1 ?>">
                            <span class="integration_button"
                                  data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                  data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"></span>
                            <img alt="sdi-via-pop"
                                 src="<?php echo "https://pub.popapi.io/assets/integrations/pop-sdi.jpg"; ?>">
                            <h5><?php echo _x('SdI (official)', 'integration_info', WC_EL_INV_TEXTDOMAIN); ?></h5>
                            <p><?php echo _x('Send invoices to SdI without external management software: everything directly from POP, automatically.',
                                    'integration_info', WC_EL_INV_TEXTDOMAIN); ?></p>
                            <a target="_blank" href="https://popapi.io/integration/sdi/">
                                <span class="dashicons dashicons-arrow-right-alt"></span> <?php echo esc_html__('Documentation',
                                    WC_EL_INV_TEXTDOMAIN); ?>
                            </a>
                            <?php if ($isWizardCompleted && $isFreeLevel && ! $sdiPopConflict) : ?>
                                <div class="custom-tooltip"><?php echo wp_kses_post($upgradePlansMessage); ?></div>
                            <?php endif; ?>
                            <?php if (! $isWizardCompleted) : ?>
                                <div class="custom-tooltip"><?php echo esc_html($preWizardMessage); ?></div>
                            <?php endif; ?>
                            <?php if ($isWizardCompleted && $sdiPopConflict) : ?>
                                <div class="custom-tooltip"><?php echo esc_html($exclusiveInvoiceMessage); ?></div>
                            <?php
                            elseif (! $statusSdiViaPop->active_integration &&
                                $isWizardCompleted &&
                                $isBasicLevel &&
                                $isItalyEndpointCountry) : ?>
                                <div class="custom-tooltip"><?php echo sprintf('%s <a href="https://docs.popapi.io/it/guides/integrations/sdi-via-pop/" target="_blank">%s</a></a>',
                                        __('Activate the integration in your account first.', WC_EL_INV_TEXTDOMAIN),
                                        __('Learn how', WC_EL_INV_TEXTDOMAIN)
                                    ); ?>
                                </div>
                            <?php endif; ?>
                            <?php if ($isWizardCompleted && ! $sdiPopConflict && ! $isItalyEndpointCountry) : ?>
                                <div class="custom-tooltip"><?php echo __('You cannot activate SdI (official): the country configured for this account does not support this endpoint.',
                                        WC_EL_INV_TEXTDOMAIN); ?></div>
                            <?php endif; ?>
                        </div>
                    </div>
                    <!-- aruba --->
                    <?php if (in_array('wc_el_inv-addon-aruba',
                        \WcElectronInvoice\Integrations::$addonPlugins)) : ?>
                        <div class="col-3">
                            <div title="<?php echo ! $isProLevel || ! $statusAruba && 'prod' === WC_EL_INV_ENV || ! $isItalyEndpointCountry || $arubaConflict ? esc_html__('not available',
                                WC_EL_INV_TEXTDOMAIN) : esc_html__('available', WC_EL_INV_TEXTDOMAIN); ?>"
                                 class="tooltip-trigger card save-option-button <?php echo ! $isProLevel || ! $statusAruba && 'prod' === WC_EL_INV_ENV || ! $isItalyEndpointCountry || $arubaConflict ? 'disabled' : ''; ?> <?php if ($arubaActive && class_exists('WooPoPToFattureAruba\Plugin')): ?>plugin-active<?php endif; ?>"
                                 data-option-name="wc_el_inv-addon-aruba"
                                 data-option-value="<?php echo $arubaActive ? 0 : 1 ?>">
                                <span class="integration_button"
                                      data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                      data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"></span>
                                <img alt="pop-aruba"
                                     src="<?php echo "https://pub.popapi.io/assets/integrations/pop-aruba-business.jpg"; ?>">
                                <h5><?php echo _x('Aruba Business', 'integration_info', WC_EL_INV_TEXTDOMAIN); ?></h5>
                                <p><?php echo _x('Send invoices to Aruba Business from your e-commerce in a compliant and automated way.',
                                        'integration_info', WC_EL_INV_TEXTDOMAIN); ?></p>
                                <a target="_blank" href="https://popapi.io/integration/aruba-business/">
                                    <span class="dashicons dashicons-arrow-right-alt"></span> <?php echo esc_html__('Documentation',
                                        WC_EL_INV_TEXTDOMAIN); ?>
                                </a>
                                <?php if ($isWizardCompleted && ! $isProLevel && ! $arubaConflict) : ?>
                                    <div class="custom-tooltip"><?php echo wp_kses_post($upgradePlansMessage); ?></div>
                                <?php endif; ?>
                                <?php if (! $isWizardCompleted) : ?>
                                    <div class="custom-tooltip"><?php echo esc_html($preWizardMessage); ?></div>
                                <?php endif; ?>
                                <?php if ($isWizardCompleted && $arubaConflict) : ?>
                                    <div class="custom-tooltip"><?php echo esc_html($exclusiveInvoiceMessage); ?></div>
                                <?php endif; ?>
                                <?php if ($isWizardCompleted && ! $arubaConflict && ! $isItalyEndpointCountry) : ?>
                                    <div class="custom-tooltip"><?php echo __('You cannot activate Aruba Business: the country configured for this account does not support this endpoint.',
                                            WC_EL_INV_TEXTDOMAIN); ?></div>
                                <?php endif; ?>
                            </div>
                        </div>
                    <?php endif; ?>
                    <!-- fatture in cloud --->
                    <?php if (in_array('wc_el_inv-addon-fattureincloud',
                        \WcElectronInvoice\Integrations::$addonPlugins)) : ?>
                        <div class="col-3">
                            <div title="<?php echo ! $isProLevel || ! $statusFic && 'prod' === WC_EL_INV_ENV || ! $isItalyEndpointCountry || $ficConflict ? esc_html__('not available',
                                WC_EL_INV_TEXTDOMAIN) : esc_html__('available', WC_EL_INV_TEXTDOMAIN); ?>"
                                 class="tooltip-trigger card save-option-button <?php echo ! $isProLevel || ! $statusFic && 'prod' === WC_EL_INV_ENV || ! $isItalyEndpointCountry || $ficConflict ? 'disabled' : ''; ?> <?php if ($ficActive && class_exists('WooPoPToFattureInCloud\Plugin')): ?>plugin-active<?php endif; ?>"
                                 data-option-name="wc_el_inv-addon-fattureincloud"
                                 data-option-value="<?php echo $ficActive ? 0 : 1 ?>">
                            <span class="integration_button"
                                  data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                  data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"></span>
                                <img alt="pop-fatture-in-cloud"
                                     src="<?php echo "https://pub.popapi.io/assets/integrations/pop-fatture-in-cloud.jpg"; ?>">
                                <h5><?php echo _x('Fatture in Cloud', 'integration_info', WC_EL_INV_TEXTDOMAIN); ?></h5>
                                <p><?php echo _x('Automate invoicing, warehouse management, and SdI delivery with POP and Fatture in Cloud.',
                                        'integration_info', WC_EL_INV_TEXTDOMAIN); ?></p>
                                <a target="_blank" href="https://popapi.io/integration/fatture-in-cloud/">
                                    <span class="dashicons dashicons-arrow-right-alt"></span> <?php echo esc_html__('Documentation',
                                        WC_EL_INV_TEXTDOMAIN); ?>
                                </a>
                                <?php if ($isWizardCompleted && ! $isProLevel && ! $ficConflict) : ?>
                                    <div class="custom-tooltip"><?php echo wp_kses_post($upgradePlansMessage); ?></div>
                                <?php endif; ?>
                                <?php if (! $isWizardCompleted) : ?>
                                    <div class="custom-tooltip"><?php echo esc_html($preWizardMessage); ?></div>
                                <?php endif; ?>
                                <?php if ($isWizardCompleted && $ficConflict) : ?>
                                    <div class="custom-tooltip"><?php echo esc_html($exclusiveInvoiceMessage); ?></div>
                                <?php endif; ?>
                                <?php if ($isWizardCompleted && ! $ficConflict && ! $isItalyEndpointCountry) : ?>
                                    <div class="custom-tooltip"><?php echo __('You cannot activate Fatture in Cloud: the country configured for this account does not support this endpoint.',
                                            WC_EL_INV_TEXTDOMAIN); ?></div>
                                <?php endif; ?>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
                <div class="d-flex">
                    <!-- fatture in cloud receipt --->
                    <?php if (in_array('wc_el_inv-addon-fattureincloud-receipts',
                        \WcElectronInvoice\Integrations::$addonPlugins)) : ?>
                        <div class="col-3">
                            <div title="<?php echo ! $isProLevel || ! $statusFicRc && 'prod' === WC_EL_INV_ENV || ! $isItalyEndpointCountry || ! $ficActive || $ficConflict ? esc_html__('not available',
                                WC_EL_INV_TEXTDOMAIN) : esc_html__('available', WC_EL_INV_TEXTDOMAIN); ?>"
                                 class="tooltip-trigger card save-option-button <?php echo ! $isProLevel || ! $statusFicRc && 'prod' === WC_EL_INV_ENV || ! $isItalyEndpointCountry || ! $ficActive || $ficConflict ? 'disabled' : ''; ?> <?php if ($ficActive && $ficReceiptActive && class_exists('WooPoPToFattureInCloud\Plugin') && defined('WP_FATT_CLOUD_RECEIPTS_NAME')): ?>plugin-active<?php endif; ?>"
                                 data-option-name="wc_el_inv-addon-fattureincloud-receipts"
                                 data-option-value="<?php echo $ficReceiptActive ? 0 : 1 ?>">
                                <span class="integration_button"
                                      data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                      data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"></span>
                                <img alt="pop-fatture-in-cloud-corrispettivi"
                                     src="<?php echo "https://pub.popapi.io/assets/integrations/pop-fatture-in-cloud-corrispettivi.jpg"; ?>">
                                <h5><?php echo _x('Fatture in Cloud (receipts)', 'integration_info',
                                        WC_EL_INV_TEXTDOMAIN); ?></h5>
                                <p><?php echo _x('Generate receipts from e-commerce orders with the POP integration for Fatture in Cloud.',
                                        'integration_info', WC_EL_INV_TEXTDOMAIN); ?></p>
                                <a target="_blank"
                                   href="https://popapi.io/integration/fatture-in-cloud-receipts/">
                                    <span class="dashicons dashicons-arrow-right-alt"></span> <?php echo esc_html__('Documentation',
                                        WC_EL_INV_TEXTDOMAIN); ?>
                                </a>
                                <?php if ($isWizardCompleted && ! $isProLevel && ! $ficConflict) : ?>
                                    <div class="custom-tooltip"><?php echo wp_kses_post($upgradePlansMessage); ?></div>
                                <?php endif; ?>
                                <?php if (! $isWizardCompleted) : ?>
                                    <div class="custom-tooltip"><?php echo esc_html($preWizardMessage); ?></div>
                                <?php endif; ?>
                                <?php if ($isWizardCompleted && $ficConflict) : ?>
                                    <div class="custom-tooltip"><?php echo esc_html($exclusiveInvoiceMessage); ?></div>
                                <?php endif; ?>
                                <?php if ($isWizardCompleted && ! $ficConflict && $isProLevel && $isItalyEndpointCountry && ! $ficActive) : ?>
                                    <div class="custom-tooltip custom-tooltip--dependency"><?php echo esc_html__('Activate Fatture in Cloud first to enable this add-on.',
                                            WC_EL_INV_TEXTDOMAIN); ?></div>
                                <?php endif; ?>
                                <?php if ($isWizardCompleted && ! $ficConflict && ! $isItalyEndpointCountry) : ?>
                                    <div class="custom-tooltip"><?php echo __('You cannot activate Fatture in Cloud (receipts): the country configured for this account does not support this endpoint.',
                                            WC_EL_INV_TEXTDOMAIN); ?></div>
                                <?php endif; ?>
                            </div>
                        </div>
                    <?php endif; ?>
                    <!-- fatture in cloud stock --->
                    <?php if (in_array('wc_el_inv-addon-fattureincloud-stock',
                        \WcElectronInvoice\Integrations::$addonPlugins)) : ?>
                        <div class="col-3">
                            <div title="<?php echo ! $isProLevel || ! $statusFicMs && 'prod' === WC_EL_INV_ENV || ! $isItalyEndpointCountry || ! $ficActive || $ficConflict ? esc_html__('not available',
                                WC_EL_INV_TEXTDOMAIN) : esc_html__('available', WC_EL_INV_TEXTDOMAIN); ?>"
                                 class="tooltip-trigger card save-option-button <?php echo ! $isProLevel || ! $statusFicMs && 'prod' === WC_EL_INV_ENV || ! $isItalyEndpointCountry || ! $ficActive || $ficConflict ? 'disabled' : ''; ?> <?php if ($ficActive && $ficStockActive && class_exists('WooPoPToFattureInCloud\Plugin') && defined('WP_FATT_CLOUD_STOCK_NAME')): ?>plugin-active<?php endif; ?>"
                                 data-option-name="wc_el_inv-addon-fattureincloud-stock"
                                 data-option-value="<?php echo $ficStockActive ? 0 : 1 ?>">
                                <span class="integration_button"
                                      data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                      data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"></span>
                                <img alt="pop-fatture-in-cloud-magazzino"
                                     src="<?php echo "https://pub.popapi.io/assets/integrations/pop-fatture-in-cloud-magazzino.jpg"; ?>">
                                <h5><?php echo _x('Fatture in Cloud (warehouse management)', 'integration_info',
                                        WC_EL_INV_TEXTDOMAIN); ?></h5>
                                <p><?php echo _x('Sync stock between your e-commerce and Fatture in Cloud to eliminate errors and duplicates.',
                                        'integration_info', WC_EL_INV_TEXTDOMAIN); ?></p>
                                <a target="_blank"
                                   href="https://popapi.io/integration/fatture-in-cloud-inventory-management/">
                                    <span class="dashicons dashicons-arrow-right-alt"></span> <?php echo esc_html__('Documentation',
                                        WC_EL_INV_TEXTDOMAIN); ?>
                                </a>
                                <?php if ($isWizardCompleted && ! $isProLevel && ! $ficConflict) : ?>
                                    <div class="custom-tooltip"><?php echo wp_kses_post($upgradePlansMessage); ?></div>
                                <?php endif; ?>
                                <?php if (! $isWizardCompleted) : ?>
                                    <div class="custom-tooltip"><?php echo esc_html($preWizardMessage); ?></div>
                                <?php endif; ?>
                                <?php if ($isWizardCompleted && $ficConflict) : ?>
                                    <div class="custom-tooltip"><?php echo esc_html($exclusiveInvoiceMessage); ?></div>
                                <?php endif; ?>
                                <?php if ($isWizardCompleted && ! $ficConflict && $isProLevel && $isItalyEndpointCountry && ! $ficActive) : ?>
                                    <div class="custom-tooltip custom-tooltip--dependency"><?php echo esc_html__('Activate Fatture in Cloud first to enable this add-on.',
                                            WC_EL_INV_TEXTDOMAIN); ?></div>
                                <?php endif; ?>
                                <?php if ($isWizardCompleted && ! $ficConflict && ! $isItalyEndpointCountry) : ?>
                                    <div class="custom-tooltip"><?php echo __('You cannot activate Fatture in Cloud (warehouse management): the country configured for this account does not support this endpoint.',
                                            WC_EL_INV_TEXTDOMAIN); ?></div>
                                <?php endif; ?>
                            </div>
                        </div>
                    <?php endif; ?>
                    <!-- sdi via pec --->
                    <?php if (in_array('wc_el_inv-addon-sdi-pec',
                        \WcElectronInvoice\Integrations::$addonPlugins)) : ?>
                        <div class="col-3">
                            <div title="<?php echo ! $isProLevel || ! $statusSdiPec && 'prod' === WC_EL_INV_ENV || ! $isItalyEndpointCountry || $sdiPecConflict ? esc_html__('not available',
                                WC_EL_INV_TEXTDOMAIN) : esc_html__('available', WC_EL_INV_TEXTDOMAIN); ?>"
                                 class="tooltip-trigger card save-option-button <?php echo ! $isProLevel || ! $statusSdiPec && 'prod' === WC_EL_INV_ENV || ! $isItalyEndpointCountry || $sdiPecConflict ? 'disabled' : ''; ?> <?php if ($sdiPecActive && class_exists('WooPoPToSdIPec\Plugin')): ?>plugin-active<?php endif; ?>"
                                 data-option-name="wc_el_inv-addon-sdi-pec"
                                 data-option-value="<?php echo $sdiPecActive ? 0 : 1 ?>">
                                <span class="integration_button"
                                      data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                      data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"></span>
                                <img alt="pop-sdi-pec"
                                     src="<?php echo "https://pub.popapi.io/assets/integrations/pop-sdi-pec.jpg"; ?>">
                                <h5><?php echo _x('SdI via PEC', 'integration_info', WC_EL_INV_TEXTDOMAIN); ?></h5>
                                <p><?php echo _x('Send invoices to SdI via PEC from your e-commerce, with control and simplicity.',
                                        'integration_info', WC_EL_INV_TEXTDOMAIN); ?></p>
                                <a target="_blank" href="https://popapi.io/integration/pec-interchange-system/">
                                    <span class="dashicons dashicons-arrow-right-alt"></span> <?php echo esc_html__('Documentation',
                                        WC_EL_INV_TEXTDOMAIN); ?>
                                </a>
                                <?php if ($isWizardCompleted && ! $isProLevel && ! $sdiPecConflict) : ?>
                                    <div class="custom-tooltip"><?php echo wp_kses_post($upgradePlansMessage); ?></div>
                                <?php endif; ?>
                                <?php if (! $isWizardCompleted) : ?>
                                    <div class="custom-tooltip"><?php echo esc_html($preWizardMessage); ?></div>
                                <?php endif; ?>
                                <?php if ($isWizardCompleted && $sdiPecConflict) : ?>
                                    <div class="custom-tooltip"><?php echo esc_html($exclusiveInvoiceMessage); ?></div>
                                <?php endif; ?>
                                <?php if ($isWizardCompleted && ! $sdiPecConflict && ! $isItalyEndpointCountry) : ?>
                                    <div class="custom-tooltip"><?php echo __('You cannot activate SdI via PEC: the country configured for this account does not support this endpoint.',
                                            WC_EL_INV_TEXTDOMAIN); ?></div>
                                <?php endif; ?>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            <?php // Addon Endpoint for UBL countries and PL country (KSeF) ?>
                <div class="d-flex">
                    <!-- peppol via pop --->
                    <div class="col-3">
                        <div title="<?php echo ! $statusPEPPOLViaPop->peppol_integration || ! $isBasicLevel || ! $isUblCountry || $isItalyCountry ?
                            esc_html__('not available', WC_EL_INV_TEXTDOMAIN) : esc_html__('available',
                                WC_EL_INV_TEXTDOMAIN); ?>"
                             class="tooltip-trigger card save-option-button <?php echo ! $statusPEPPOLViaPop->peppol_integration || ! $isBasicLevel || ! $isUblCountry || $isItalyCountry || $peppolConflict ? 'disabled' : ''; ?> <?php if ($statusPEPPOLViaPop->peppol_integration && $peppolPOPActive): ?>plugin-active<?php endif; ?>"
                             data-option-name="wc_el_inv-addon-peppol-via-pop"
                             data-option-value="<?php echo $statusPEPPOLViaPop->peppol_integration && $peppolPOPActive ? 0 : 1 ?>">
                            <span class="integration_button"
                                  data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                  data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"></span>
                            <img alt="sdi-via-pop"
                                 src="<?php echo "https://pub.popapi.io/assets/integrations/pop-peppol.jpg"; ?>">
                            <h5><?php echo _x('PEPPOL (official)', 'integration_info', WC_EL_INV_TEXTDOMAIN); ?></h5>
                            <p><?php echo _x('Send invoices through the PEPPOL network without external management software: everything directly from POP, automatically.',
                                    'integration_info', WC_EL_INV_TEXTDOMAIN); ?></p>
                            <a target="_blank" href="https://popapi.io/integration/peppol/">
                                <span class="dashicons dashicons-arrow-right-alt"></span> <?php echo esc_html__('Documentation',
                                    WC_EL_INV_TEXTDOMAIN); ?>
                            </a>
                            <?php if ($isWizardCompleted && $isFreeLevel && ! $peppolConflict) : ?>
                                <div class="custom-tooltip"><?php echo wp_kses_post($upgradePlansMessage); ?></div>
                            <?php endif; ?>
                            <?php if (! $isWizardCompleted) : ?>
                                <div class="custom-tooltip"><?php echo esc_html($preWizardMessage); ?></div>
                            <?php endif; ?>
                            <?php if ($isWizardCompleted && $peppolConflict) : ?>
                                <div class="custom-tooltip"><?php echo esc_html($exclusiveInvoiceMessage); ?></div>
                            <?php
                            elseif (! $statusPEPPOLViaPop->peppol_integration &&
                                $isWizardCompleted &&
                                $isBasicLevel &&
                                $isUblCountry) : ?>
                                <div class="custom-tooltip"><?php echo sprintf('%s <a href="https://docs.popapi.io/it/guides/integrations/peppol/" target="_blank">%s</a></a>',
                                        __('Activate the integration in your account first.', WC_EL_INV_TEXTDOMAIN),
                                        __('Learn how', WC_EL_INV_TEXTDOMAIN)
                                    ); ?>
                                </div>
                            <?php endif; ?>
                            <?php if ($isWizardCompleted && ! $peppolConflict && $isBasicLevel && (! $isUblCountry || $isItalyCountry)) : ?>
                                <div class="custom-tooltip"><?php echo __('You cannot activate PEPPOL (official): the country configured for this account does not support this endpoint.',
                                        WC_EL_INV_TEXTDOMAIN); ?></div>
                            <?php endif; ?>
                        </div>
                    </div>
                    <!-- ksef via pop --->
                    <div class="col-3">
                        <div title="<?php echo ! $statusKSeFViaPop->ksef_integration || ! $isBasicLevel || ! $isPolandCountry ?
                            esc_html__('not available', WC_EL_INV_TEXTDOMAIN) : esc_html__('available',
                                WC_EL_INV_TEXTDOMAIN); ?>"
                             class="tooltip-trigger card save-option-button <?php echo ! $statusKSeFViaPop->ksef_integration || ! $isBasicLevel || ! $isPolandCountry || $ksefConflict ? 'disabled' : ''; ?> <?php if ($statusKSeFViaPop->ksef_integration && $ksefPOPActive): ?>plugin-active<?php endif; ?>"
                             data-option-name="wc_el_inv-addon-ksef-via-pop"
                             data-option-value="<?php echo $statusKSeFViaPop->ksef_integration && $ksefPOPActive ? 0 : 1 ?>">
                            <span class="integration_button"
                                  data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                  data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"></span>
                            <img alt="ksef-via-pop"
                                 src="<?php echo "https://pub.popapi.io/assets/integrations/pop-ksef.jpg"; ?>">
                            <h5><?php echo _x('KSeF (official)', 'integration_info', WC_EL_INV_TEXTDOMAIN); ?></h5>
                            <p><?php echo _x('Send invoices to the Polish National e-Invoicing System (KSeF) without external management software: everything directly from POP, automatically.',
                                    'integration_info', WC_EL_INV_TEXTDOMAIN); ?></p>
                            <a target="_blank" href="https://popapi.io/integration/ksef/">
                                <span class="dashicons dashicons-arrow-right-alt"></span> <?php echo esc_html__('Documentation',
                                    WC_EL_INV_TEXTDOMAIN); ?>
                            </a>
                            <?php if ($isWizardCompleted && $isFreeLevel && ! $ksefConflict) : ?>
                                <div class="custom-tooltip"><?php echo wp_kses_post($upgradePlansMessage); ?></div>
                            <?php endif; ?>
                            <?php if (! $isWizardCompleted) : ?>
                                <div class="custom-tooltip"><?php echo esc_html($preWizardMessage); ?></div>
                            <?php endif; ?>
                            <?php if ($isWizardCompleted && $ksefConflict) : ?>
                                <div class="custom-tooltip"><?php echo esc_html($exclusiveInvoiceMessage); ?></div>
                            <?php
                            elseif (! $statusKSeFViaPop->ksef_integration &&
                                $isWizardCompleted &&
                                $isBasicLevel &&
                                $isPolandCountry) : ?>
                                <div class="custom-tooltip"><?php echo sprintf('%s <a href="https://docs.popapi.io/it/guides/integrations/ksef/" target="_blank">%s</a>',
                                        __('Activate the integration in your account first.', WC_EL_INV_TEXTDOMAIN),
                                        __('Learn how', WC_EL_INV_TEXTDOMAIN)
                                    ); ?>
                                </div>
                            <?php endif; ?>
                            <?php if ($isWizardCompleted && ! $ksefConflict && $isBasicLevel && ! $isPolandCountry) : ?>
                                <div class="custom-tooltip"><?php echo __('You cannot activate KSeF (official): the country configured for this account does not support this endpoint.',
                                        WC_EL_INV_TEXTDOMAIN); ?></div>
                            <?php endif; ?>
                        </div>
                    </div>
                    <!-- zoho via pop --->
                    <div class="col-3">
                        <div title="<?php echo ! $statusZohoViaPop->zoho_integration || ! $isBasicLevel ?
                            esc_html__('not available', WC_EL_INV_TEXTDOMAIN) : esc_html__('available',
                                WC_EL_INV_TEXTDOMAIN); ?>"
                             class="tooltip-trigger card save-option-button <?php echo ! $statusZohoViaPop->zoho_integration || ! $isBasicLevel || $zohoConflict ? 'disabled' : ''; ?> <?php if ($statusZohoViaPop->zoho_integration && $zohoPOPActive): ?>plugin-active<?php endif; ?>"
                             data-option-name="wc_el_inv-addon-zoho-via-pop"
                             data-option-value="<?php echo $statusZohoViaPop->zoho_integration && $zohoPOPActive ? 0 : 1 ?>">
                            <span class="integration_button"
                                  data-enable="<?php esc_html_e('Activate', WC_EL_INV_TEXTDOMAIN); ?>"
                                  data-disable="<?php esc_html_e('Deactivate', WC_EL_INV_TEXTDOMAIN); ?>"></span>
                            <img alt="zoho-via-pop"
                                 src="<?php echo "https://pub.popapi.io/assets/integrations/pop-zoho.jpg"; ?>">
                            <h5><?php echo _x('Zoho (via POP)', 'integration_info', WC_EL_INV_TEXTDOMAIN); ?></h5>
                            <p><?php echo _x('Send invoices to Zoho through POP as the exclusive channel for this site, with the same local activation flow used by the native POP integrations.',
                                    'integration_info', WC_EL_INV_TEXTDOMAIN); ?></p>
                            <a target="_blank" href="https://popapi.io/integration/zoho/">
                                <span class="dashicons dashicons-arrow-right-alt"></span> <?php echo esc_html__('Documentation',
                                    WC_EL_INV_TEXTDOMAIN); ?>
                            </a>
                            <?php if ($isWizardCompleted && $isFreeLevel && ! $zohoConflict) : ?>
                                <div class="custom-tooltip"><?php echo wp_kses_post($upgradePlansMessage); ?></div>
                            <?php endif; ?>
                            <?php if (! $isWizardCompleted) : ?>
                                <div class="custom-tooltip"><?php echo esc_html($preWizardMessage); ?></div>
                            <?php endif; ?>
                            <?php if ($isWizardCompleted && $zohoConflict) : ?>
                                <div class="custom-tooltip"><?php echo esc_html($exclusiveInvoiceMessage); ?></div>
                            <?php endif; ?>
                            <?php if (! $zohoConflict && ! $statusZohoViaPop->zoho_integration && $isWizardCompleted && $isBasicLevel) : ?>
                                <div class="custom-tooltip"><?php echo sprintf('%s <a href="%s" target="_blank">%s</a>',
                                        __('Activate and connect Zoho in your POP account first.', WC_EL_INV_TEXTDOMAIN),
                                        esc_url('https://popapi.io/integration/zoho/'),
                                        __('Learn how', WC_EL_INV_TEXTDOMAIN)
                                    ); ?>
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
        </div>
        <div class="help-center sidebar">
            <h3><a class="" target="_blank" href="https://docs.popapi.io/it/"><span
                            class="dashicons dashicons-sos"></span> <?php echo esc_html_x('Help Center',
                        WC_EL_INV_TEXTDOMAIN); ?></a>
            </h3>

            <ol>
                <li><a target="_blank"
                       href="https://docs.popapi.io/it/guides/getting-started/"><?php echo esc_html_x('Introduction',
                            'help_link', WC_EL_INV_TEXTDOMAIN); ?></a></li>
                <li><a target="_blank"
                       href="https://docs.popapi.io/it/guides/configuration/"><?php echo esc_html_x('General configuration',
                            'help_link', WC_EL_INV_TEXTDOMAIN); ?></a></li>
                <li><a target="_blank"
                       href="https://docs.popapi.io/it/guides/integrations/paid-memberships-pro/"><?php echo esc_html_x('Paid Memberships Pro',
                            'help_link', WC_EL_INV_TEXTDOMAIN); ?></a></li>
                <li><a target="_blank"
                       href="https://docs.popapi.io/it/guides/integrations/sdi-via-pop/"><?php echo esc_html_x('SdI via POP',
                            'help_link', WC_EL_INV_TEXTDOMAIN); ?></a></li>
                <li><a target="_blank"
                       href="https://docs.popapi.io/it/guides/integrations/peppol/"><?php echo esc_html_x('PEPPOL',
                            'help_link', WC_EL_INV_TEXTDOMAIN); ?></a></li>
                <li><a target="_blank"
                       href="https://docs.popapi.io/it/guides/integrations/webhook/"><?php echo esc_html_x('Webhook',
                            'help_link', WC_EL_INV_TEXTDOMAIN); ?></a></li>
                <li><a target="_blank"
                       href="https://docs.popapi.io/it/guides/integrations/fatture-in-cloud-connect/"><?php echo esc_html_x('Fatture in Cloud Add-on',
                            'help_link', WC_EL_INV_TEXTDOMAIN); ?></a></li>
                <li><a target="_blank"
                       href="https://docs.popapi.io/it/guides/integrations/fatture-in-cloud-corrispettivi/"><?php echo esc_html_x('Fatture in Cloud Fees Add-on',
                            'help_link', WC_EL_INV_TEXTDOMAIN); ?></a></li>
                <li><a target="_blank"
                       href="https://docs.popapi.io/it/guides/integrations/fatture-in-cloud-warehouse-sync/"><?php echo esc_html_x('Fatture in Cloud Warehouse Stock Add-on',
                            'help_link', WC_EL_INV_TEXTDOMAIN); ?></a></li>
                <li><a target="_blank"
                       href="https://docs.popapi.io/it/guides/integrations/sdi-via-pec/"><?php echo esc_html_x('SdI via PEC Add-on',
                            'help_link', WC_EL_INV_TEXTDOMAIN); ?></a></li>
                <li><a target="_blank"
                       href="https://docs.popapi.io/it/guides/integrations/aruba-connect/"><?php echo esc_html_x('Aruba Add-on',
                            'help_link', WC_EL_INV_TEXTDOMAIN); ?></a></li>
                <li><a target="_blank"
                       href="https://docs.popapi.io/it/guides/troubleshooting/"><?php echo esc_html_x('Support',
                            'help_link', WC_EL_INV_TEXTDOMAIN); ?></a></li>
            </ol>
        </div>
    </div>
    <hr>
</div>
