<?php

namespace Itgalaxy\Elementor\Form\Infusionsoft\Integration\Admin\PageParts;

use Itgalaxy\PluginCommon\AdminGenerator\Themes\DefaultTheme;

class HeaderPagePart
{
    /**
     * @return void
     */
    public static function render()
    {
        DefaultTheme::pageHeader(
            esc_html__('Integration settings', 'el-pro-form-infusionsoft-integration'),
            esc_html__(
                'Formation of contacts in Infusionsoft from the hits that users send on your site, using the Elementor Pro Form Widget.',
                'el-pro-form-infusionsoft-integration'
            ),
            [
                [
                    'type' => 'button-link',
                    'classes' => ['btn-light'],
                    'text' => '<i class="icon-svg icon-svg-question"></i> ' . esc_html__('Documentation', 'el-pro-form-infusionsoft-integration'),
                    'attributes' => [
                        'title' => esc_html__('Documentation', 'el-pro-form-infusionsoft-integration'),
                        'href' => 'https://itgalaxy.company/en/software/elementor-pro-form-widget-infusionsoft-keap-crm-integration/elementor-pro-form-widget-infusionsoft-keap-crm-integration-instructions/',
                        'target' => '_blank',
                    ],
                ],
                [
                    'type' => 'button-link',
                    'classes' => ['btn-light'],
                    'text' => '<i class="icon-svg icon-svg-support"></i> ' . esc_html__('Support', 'el-pro-form-infusionsoft-integration'),
                    'attributes' => [
                        'title' => esc_html__('Support', 'el-pro-form-infusionsoft-integration'),
                        'href' => 'https://codecanyon.net/item/elementor-pro-form-widget-infusionsoft-keap-crm-integration/33704547/support',
                        'target' => '_blank',
                    ],
                ],
            ]
        );

        self::showNotices();
    }

    /**
     * @return void
     */
    private static function showNotices()
    {
        if (isset($_GET['success'])) {
            DefaultTheme::callout(
                esc_html__('Settings successfully updated.', 'el-pro-form-infusionsoft-integration'),
                'success'
            );
        } elseif (isset($_GET['error-required-fields'])) {
            DefaultTheme::callout(
                esc_html__('ERROR', 'el-pro-form-infusionsoft-integration') . ': '
                . esc_html__('API Key and API Secret is required fields.', 'el-pro-form-infusionsoft-integration'),
                'danger'
            );
        } elseif (isset($_GET['success-fields-reload'])) {
            DefaultTheme::callout(
                esc_html__('Fields cache updated successfully.', 'el-pro-form-infusionsoft-integration'),
                'success'
            );
        }
    }
}
