<?php

namespace PSSG_Sync_Sheet\Admin;

use PSSG_Sync_Sheet\App\Core\Base;
use PSSG_Sync_Sheet\App\Core\Admin_Base;
use PSSG_Sync_Sheet\App\Service\Products;
use PSSG_Sync_Sheet\App\Http\Sheet;
use PSSG_Sync_Sheet\App\Http\Api;
use PSSG_Sync_Sheet\App\Handle\Form_Submit;
use PSSG_Sync_Sheet\App\Handle\Quick_Table;
use PSSG_Sync_Sheet\App\Handle\Setup_Wizard;
use PSSG_Sync_Sheet\App\Handle\Inactive_Element;
use PSSG_Sync_Sheet\App\Service\Standalone;
use PSSG_Sync_Sheet\App\Service\Request_Log;

class Page_Loader extends Admin_Base
{

    use Standalone;
    //Has transferred to Admin_Base
    // public $main_slug = 'pssg-sync';
    public $page_folder_dir;
    public $topbar_file;
    public $topbar_sub_title;


    public $Products;
    public $Sheet;
    public $Api;
    public $Quick_Table;


    public $all_enequeue_loaded = false;

    public function __construct()
    {
        parent::__construct();


        $this->Products = Products::init();
        $this->Sheet = Sheet::init();
        $this->Api = Api::init();

        $this->page_folder_dir = $this->base_dir . 'admin/pages/';
        $this->topbar_file = $this->page_folder_dir . 'topbar.php';
        $this->topbar_sub_title = __("Next door to Google Sheets", 'product-sync-master-sheet');
    }

    public function run()
    {

        add_action('admin_menu', [$this, 'admin_menu']);
        add_action('admin_notices', [$this, 'premium_version_update_notice']);

        add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']);

        add_action('wp_ajax_pssg_setting_wizard_submit', [$this, 'form_submit']);
        add_action('wp_ajax_pssg_configure_form_submit', [$this, 'form_submit']);
        add_action('wp_ajax_handle_json_file_upload', [$this, 'handle_json_file_upload']);
        
        // Access Key AJAX handlers
        add_action('wp_ajax_pssg_generate_access_key', [$this, 'ajax_generate_access_key']);
        add_action('wp_ajax_pssg_regenerate_access_key', [$this, 'ajax_regenerate_access_key']);
        add_action('wp_ajax_pssg_reset_settings', [$this, 'reset_settings']);
        add_action('wp_ajax_pssg_reset_column_order', [$this, 'reset_column_order']);

        add_action('admin_body_class', [$this, 'admin_body_class']);
        if (!$this->is_premium) {
            Inactive_Element::init();
        }

        if ( class_exists( '\PSSG_Sync_Sheet\Admin\Appseros\Src\Client' ) ) {
            $client = new \PSSG_Sync_Sheet\Admin\Appseros\Src\Client( '7337d6e7-cf9c-49cb-8ba0-028320b91146', PSSG_PLUGIN_NAME, PSSG_FILE );
            $client->insights()->init();
        }
    }

    public function admin_menu()
    {

        $capability = apply_filters('pssg_menu_capability', 'manage_woocommerce');

        $min_max_img = $this->base_url . 'assets/images/logo.gif';
        $page_title = __('Sync Master Sheet', 'product-sync-master-sheet');
        $menu_title = __('Sync Master Sheet', 'product-sync-master-sheet');
        $menu_slug = $this->main_slug;
        $callback = [$this, 'main_page'];
        $icon_url = 'dashicons-media-spreadsheet';
        $position = 55.5;


        $sw_page_title = __('Setting - Sync Master Sheet', 'product-sync-master-sheet');
        $sw_menu_title = __('Settings', 'product-sync-master-sheet');

        $qt_page_title = __('Product Quick Edit', 'product-sync-master-sheet');
        $qt_menu_title = __('Product Quick Edit', 'product-sync-master-sheet');

        $log_page_title = __('API Logs', 'product-sync-master-sheet');
        $log_menu_title = __('API Logs', 'product-sync-master-sheet');

        $multiple_site_title = __('Multiple Site Connect', 'product-sync-master-sheet');
        $multiple_site_menu_title = __('Multiple Site Connect', 'product-sync-master-sheet');

        //Adding premium word at the title actually
        if ($this->is_premium) {
            $page_title .=  __(' Premium', 'product-sync-master-sheet');
            $qt_page_title .=  __(' Premium', 'product-sync-master-sheet');
            $sw_page_title .=  __(' Premium', 'product-sync-master-sheet');
            $log_page_title .=  __(' Premium', 'product-sync-master-sheet');
            $multiple_site_title .=  __(' Premium', 'product-sync-master-sheet');
        }

        add_menu_page($page_title, $menu_title, $capability, $menu_slug, $callback, $icon_url, $position);
        add_submenu_page($menu_slug, $sw_page_title, $sw_menu_title, $capability, 'pssg-setup-wizard', [$this, 'config_settings_page']);
        add_submenu_page($menu_slug, $qt_page_title, $qt_menu_title, $capability, 'pssg-quick-edit', [$this, 'quick_edit_page']);
        add_submenu_page($menu_slug, $log_page_title, $log_menu_title, $capability, 'pssg-api-logs', [$this, 'request_log_page']);

        if ( ! $this->is_premium) {
            add_submenu_page($menu_slug, $multiple_site_title, $multiple_site_menu_title, $capability, 'pssg-multisite-connection', [$this, 'multiple_site_menu_page_render']);
        }
    }

    /**
     * To set class on admin body tag
     *
     * @param string $classes
     * @return void
     */
    public function admin_body_class( $classes )
    {
        if ( $this->is_premium) {
            $classes .= ' pssg-body-premium ';
        }else{
            $classes .= ' pssg-body-free ';
        }
        
        return $classes;
    }

    public function main_page()
    {
        $this->topbar_sub_title = __("Installation Wizard", 'product-sync-master-sheet');
        $main_page_file = $this->page_folder_dir . 'setup-wizard.php';
        if (! is_file($main_page_file)) return;
        include $main_page_file;
    }

    public function multiple_site_menu_page_render()
    {
        $this->topbar_sub_title = __("Sync Stock with Multiple Sites", 'product-sync-master-sheet');
        $multsite_con_html = $this->page_folder_dir . 'multsite_con_demo.php';
        if (! is_file($multsite_con_html)) return;
        include $multsite_con_html;
    }

    public function config_settings_page()
    {

        $this->topbar_sub_title = __("Settings", 'product-sync-master-sheet');
        // $setting_page = $this->page_folder_dir . 'setup-wizard.php';
        $setting_page =  $this->page_folder_dir . 'settings.php';;
        if (! is_file($setting_page)) return;
        include $setting_page;
    }

    public function quick_edit_page()
    {
        $this->topbar_sub_title = __("Quick Edits", 'product-sync-master-sheet');
        $this->Quick_Table = Quick_Table::init();
        $quick_edit = $this->page_folder_dir . 'quick-edit.php';
        if (! is_file($quick_edit)) return;
        include $quick_edit;
    }

    public function request_log_page()
    {
        $this->topbar_sub_title = __("API Logs", 'product-sync-master-sheet');
        $request_log = $this->page_folder_dir . 'request-log.php';
        if (! is_file($request_log)) return;
        include $request_log;
    }

    /**
     * AJAX handler for generating access key
     */
    public function ajax_generate_access_key()
    {
        // Verify nonce
        if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'pssg_access_key_action')) {
            wp_send_json_error(['message' => __('Security check failed.', 'product-sync-master-sheet')]);
        }

        // Check capability
        if (!current_user_can('manage_woocommerce')) {
            wp_send_json_error(['message' => __('You do not have permission to perform this action.', 'product-sync-master-sheet')]);
        }

        // Generate new access key
        $new_key = Request_Log::generate_access_key();

        if ($new_key) {
            wp_send_json_success([
                'message' => __('Access Key generated successfully!', 'product-sync-master-sheet'),
                'access_key' => $new_key,
            ]);
        } else {
            wp_send_json_error(['message' => __('Failed to generate Access Key.', 'product-sync-master-sheet')]);
        }
    }

    /**
     * AJAX handler for regenerating access key
     */
    public function ajax_regenerate_access_key()
    {
        // Verify nonce
        if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'pssg_access_key_action')) {
            wp_send_json_error(['message' => __('Security check failed.', 'product-sync-master-sheet')]);
        }

        // Check capability
        if (!current_user_can('manage_woocommerce')) {
            wp_send_json_error(['message' => __('You do not have permission to perform this action.', 'product-sync-master-sheet')]);
        }

        // Regenerate access key
        $new_key = Request_Log::generate_access_key();

        if ($new_key) {
            wp_send_json_success([
                'message' => __('Access Key regenerated successfully! Remember to update the AppsScript in your Google Sheet.', 'product-sync-master-sheet'),
                'access_key' => $new_key,
            ]);
        } else {
            wp_send_json_error(['message' => __('Failed to regenerate Access Key.', 'product-sync-master-sheet')]);
        }
    }

    /**
     * AJAX handler to reset settings (pssg_config) to default
     *
     * @return void
     */
    public function reset_settings()
    {
        $nonce = sanitize_text_field( wp_unslash( $_POST['nonce'] ?? '' ) );
        if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, plugin_basename( PSSG_BASE_FILE ) ) ) {
            wp_send_json_error( [ 'message' => __( 'Security check failed.', 'product-sync-master-sheet' ) ] );
        }

        if ( ! current_user_can( 'manage_woocommerce' ) ) {
            wp_send_json_error( [ 'message' => __( 'You do not have permission to perform this action.', 'product-sync-master-sheet' ) ] );
        }

        delete_option( $this->config_key );

        wp_send_json_success( [ 'message' => __( 'Settings have been reset to default.', 'product-sync-master-sheet' ) ] );
    }

    /**
     * AJAX handler to reset only the column order (pssg_config -> column_order).
     *
     * @return void
     */
    public function reset_column_order()
    {
        $nonce = sanitize_text_field( wp_unslash( $_POST['nonce'] ?? '' ) );
        if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, plugin_basename( PSSG_BASE_FILE ) ) ) {
            wp_send_json_error( [ 'message' => __( 'Security check failed.', 'product-sync-master-sheet' ) ] );
        }

        if ( ! current_user_can( 'manage_woocommerce' ) ) {
            wp_send_json_error( [ 'message' => __( 'You do not have permission to perform this action.', 'product-sync-master-sheet' ) ] );
        }

        $config = get_option( $this->config_key, [] );
        unset( $config['column_order'] );
        update_option( $this->config_key, $config );

        wp_send_json_success( [ 'message' => __( 'Column order has been reset to default.', 'product-sync-master-sheet' ) ] );
    }

    public function premium_version_update_notice()
    {

        if (! defined('PSSGP_DEV_VERSION')) return;
        if (! defined('PSSGP_PLUGIN_NAME')) return;
        if (! $this->is_premium) return;
        global $current_screen;
        $s_id = isset($current_screen->id) ? $current_screen->id : '';
        $rand = rand(1, 7);
        $probale = true;
        if($rand == 1){
            $probale = false;
        }
        if ( strpos($s_id, $this->plugin_prefix) === false && $probale) return;
        $min_version = '1.0.7';
        if (version_compare(PSSGP_DEV_VERSION, $min_version, '<')) { ?>
            <div class="notice notice-error">
                <p style="color: #d00;">Your <b><?php echo PSSGP_PLUGIN_NAME; ?></b> <s>(V<i><strong><?php echo PSSGP_DEV_VERSION; ?></strong></i>)</s> is old.</p>
                <p style="color: #999;">Strongly recmmended V<i><b><?php echo $min_version; ?></b></i> or gatter. Please update it.</p>
                <p>Otherwise, all new fetures will not work properly.</p>
            </div>
<?php
        }
    }

    public function admin_enqueue_scripts()
    {
        global $current_screen;


        wp_register_style($this->plugin_prefix . '-common', $this->base_url . 'assets/css/sync-master-common.css', false, $this->dev_version);
        wp_enqueue_style($this->plugin_prefix . '-common');

        $s_id = isset($current_screen->id) ? $current_screen->id : '';

        //for this plugin and woocommerce
        if (strpos($s_id, $this->plugin_prefix) !== false){
            add_filter('admin_footer_text', [$this, 'admin_footer_text']);
            add_action('admin_footer', [$this, 'render_floating_sync_widget']);
            //For media upload
            wp_enqueue_media();

            $this->live_chat_script();

            $this->all_enequeue_load();
        }elseif (strpos($s_id, $this->plugin_prefix) !== false || $s_id == 'edit-product') {
            add_action('admin_footer', [$this, 'render_floating_sync_widget']);
            $this->all_enequeue_load();
            
        }
    }

    /**
     * Adding live chat script in admin footer
     *
     * @return void
     */
    protected function live_chat_script()
    {
        /**
         * how to disable live chat
         * add_filter('wpt_live_chat_bool','__return_false');
         */
        $live_chat_bool = apply_filters( 'pssg_live_chat_bool', true );
        if( ! $live_chat_bool ) return;
        ?>
        <!--Start of Tawk.to Script-->
        <script type="text/javascript">
        var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
        (function(){
        var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
        s1.async=true;
        s1.src='https://embed.tawk.to/628f5d4f7b967b1179915ad7/1g4009033';
        s1.charset='UTF-8';
        s1.setAttribute('crossorigin','*');
        s0.parentNode.insertBefore(s1,s0);
        })();
        </script>
        <!--End of Tawk.to Script-->
        <?php
    }
    public function all_enequeue_load()
    {
        if ($this->all_enequeue_loaded) return;

        //jquery
        wp_enqueue_script('jquery');

        $backend_js_name = $this->plugin_prefix . '-admin';
        wp_register_script($backend_js_name, $this->base_url . 'assets/js/backend.js', false, $this->dev_version);
        wp_enqueue_script($backend_js_name);

        $ajax_url = admin_url('admin-ajax.php');
        $PSSG_DATA = array(
            'ajaxurl'        => $ajax_url,
            'ajax_url'       => $ajax_url,
            'site_url'       => site_url(),
            'plugin_url'     => plugins_url(),
            'content_url'    => content_url(),
            'include_url'    => includes_url(),
            'text' => [
                'create_sheet'                  => __('Create Sheet', 'product-sync-master-sheet'),
                'checkout_sheet'                => __('Your Sheet', 'product-sync-master-sheet'),
                'invalid_file_type'             => __('Invalid file type. Please select a JSON file.', 'product-sync-master-sheet'),
                'all_syncronized_msg'           => __('All Syncronized', 'product-sync-master-sheet'),
                'sync_done_msg'                 => __('Sync Done', 'product-sync-master-sheet'),
                'syncing_msg'                   => __('Syncronizing...', 'product-sync-master-sheet'),
                'paused'                   => __('Paused', 'product-sync-master-sheet'),
                'pause'                   => __('Pause', 'product-sync-master-sheet'),
                'sync_limit_crossed'            => __('Done and Limit Crossed!', 'product-sync-master-sheet'),
                'check_error_msg'               => __('Check following Error', 'product-sync-master-sheet'),
                'response_error_code'           => __('Error Code: ', 'product-sync-master-sheet'),
                'check_connection_msg'          => __('Please check connection again!', 'product-sync-master-sheet'),
                'sync_success_msg'              => __('Wow Sync: total currentCount products', 'product-sync-master-sheet'),
                'delete_sheet'                  => __("Are you sure!\nWant to Destroy Sheet data.\n OK or Cancel.", 'product-sync-master-sheet'),
                'sheet_clear'                   => __('Sheet Cleared!', 'product-sync-master-sheet'),
                'sheet_clear_msg'               => __('Sheet has Cleared!', 'product-sync-master-sheet'),
                'deleting_msg'                  => __('Deleteing..', 'product-sync-master-sheet'),
                'saving_msg'                    => __('Saving..', 'product-sync-master-sheet'),
                'json_file_delating'            => __("Are you sure!\nDelete Service JSON file.\n OK or Cancel.", 'product-sync-master-sheet'),
                'file_selecting_msg'            => __('File selected: ', 'product-sync-master-sheet'),
                'email_copied_msg'              => __("Copied, Add this email as your Sheet's Editor", 'product-sync-master-sheet'),
                'script_copied_msg'             => __('Script Copied! - Now add to your Sheet.', 'product-sync-master-sheet'),
                'error_in_copy'                 => __('Unable to copy to clipboard', 'product-sync-master-sheet'),
                'show_all'                 => __('Show All', 'product-sync-master-sheet'),
                'access_key_not_generated'      => __('Access Key is not generated. Please generate an Access Key from the Security Settings before copying the AppsScript.', 'product-sync-master-sheet'),
                'regenerate_key_confirm'        => __('Are you sure you want to regenerate the Access Key? The current key will be invalidated and you will need to update the AppsScript in your Google Sheet.', 'product-sync-master-sheet'),
                'access_key_copied'             => __('Access Key copied to clipboard!', 'product-sync-master-sheet'),
                'reset_settings_confirm'        => __('Are you sure you want to reset all settings to default? This action cannot be undone.', 'product-sync-master-sheet'),
                'reset_settings_success'        => __('Settings have been reset to default.', 'product-sync-master-sheet'),
            ],
            'nonce' => wp_create_nonce(plugin_basename(PSSG_BASE_FILE)),
            'dev_version' => $this->dev_version,
            'plugin_version' => $this->plugin_version,
            'sync_btn_interval' => 2500, //in milliseconds - will change in premeium version

        );
        $PSSG_DATA = apply_filters('pssg_localize_data', $PSSG_DATA);
        wp_localize_script($backend_js_name, 'PSSG_DATA', $PSSG_DATA);

        wp_register_style($this->plugin_prefix . '-icon-font', $this->base_url . 'assets/fontello/css/pssg-icon.css', false, $this->dev_version);
        wp_enqueue_style($this->plugin_prefix . '-icon-font');


        wp_register_style($this->plugin_prefix . '-icon-animation', $this->base_url . 'assets/fontello/css/animation.css', false, $this->dev_version);
        wp_enqueue_style($this->plugin_prefix . '-icon-animation');




        wp_register_style($this->plugin_prefix . '-admin', $this->base_url . 'assets/css/dashboard.css', false, $this->dev_version);
        wp_enqueue_style($this->plugin_prefix . '-admin');

        //For all type css editing, which is not related with dashboard Design
        //And also this is not common which need to whole wp
        wp_register_style($this->plugin_prefix . '-backend', $this->base_url . 'assets/css/backend.css', false, $this->dev_version);
        wp_enqueue_style($this->plugin_prefix . '-backend');

        wp_register_style($this->plugin_prefix . '-quick-table', $this->base_url . 'assets/css/quick-edit-table.css', false, $this->dev_version);
        wp_enqueue_style($this->plugin_prefix . '-quick-table');

        wp_register_style($this->plugin_prefix . '-floating-sync', $this->base_url . 'assets/css/floating-sync.css', false, $this->dev_version);
        wp_enqueue_style($this->plugin_prefix . '-floating-sync');

        $this->all_enequeue_loaded = true;
    }

    public function form_submit()
    {
        $form = Form_Submit::init();
        $form->run();
    }

    public function handle_json_file_upload()
    {

        $nonce = sanitize_text_field(wp_unslash($_POST['nonce'] ?? ''));
        if (empty($nonce) || ! wp_verify_nonce($nonce, plugin_basename(PSSG_BASE_FILE))) {
            wp_send_json(['status' => 'failed', 'message' => '', 'error' => __('Nonce not founded', 'product-sync-master-sheet')]);
            wp_die();
        }

        $this->sheet = new Sheet();
        $service_json_key = $this->sheet->option_key; //pssg_service_json_data
        $akses_tokn_key = $this->sheet->tokn_key; //pssg_eta_holo_akses_tokn
        $response = $json_data = [];
        $response['client_email'] = '';
        if (isset($_FILES['json_file'])) {
            $file = $_FILES['json_file'];

            //working for save to database
            $temp_file = $file['tmp_name'] ?? '';
            if (! empty($temp_file)) {
                $service_fileArray = [];
                $json_content = pssg_file_get_content($temp_file);
                if (json_decode($json_content, true)) {
                    $service_fileArray = json_decode($json_content, true);
                    if (! empty($service_fileArray['type']) && $service_fileArray['type'] == 'service_account' && ! empty($service_fileArray['private_key'])  && ! empty($service_fileArray['client_email'])) {
                        $response['message'][] = __('Service file is OK', 'product-sync-master-sheet');
                        $response['status'] = 'success';

                        $json_data = $service_fileArray;
                    } else {
                        $response['errors'][] = __('Service file content is not right', 'product-sync-master-sheet');
                        $response['status'] = 'failed';
                    }
                } else {
                    $response['errors'][] = __('File content is not json!', 'product-sync-master-sheet');
                    $response['status'] = 'failed';
                }
            }

            if (! empty($response['status']) && $response['status'] == 'success') {
                // Handle the file upload (move it to the desired directory, etc.)
                $upload_dir = wp_upload_dir(); // You can change this to your desired directory
                $upload_path = $upload_dir['path'] . '/' . time() . '-' . $file['name'];
                $response['json_fil_path'] = $upload_path;
                $json_data['file_name'] = $file['name'];
                $json_data['upload_path'] = $upload_path;
                $response['client_email'] = $json_data['client_email'];
                $response['message'][] = 'File has upload to server';
                update_option($service_json_key, $json_data);
            } else {
                // $response['errors'][] = 'Old Data has been removed';
                $response['errors'][] = __('Wrong file is not uploaded to server', 'product-sync-master-sheet');
            }
        } elseif (isset($_POST['delete']) && sanitize_key($_POST['delete']) == 'json') {
            $response['client_email'] = $response['json_fil_path'] = '';
            $response['status'] = 'success';
            $response['message'] = __("Service json file has removed.", 'product-sync-master-sheet');
            update_option($service_json_key, []);
            $errors['upload_path'] = __('Service json file not founded.', 'product-sync-master-sheet');
        } else {
            $response['errors'][] = __('Sevcie file is not founded.', 'product-sync-master-sheet');
            $response['status'] = 'failed';
        }
        set_transient($akses_tokn_key, null, 0); //Akses tokn asole remove hobe jodi file upload hoy.
        wp_send_json($response);
        wp_die(); // Always use wp_die() to end AJAX requests in WordPress
    }
    /**
     * Render the floating sync widget HTML in the admin footer.
     * Visible on all plugin pages.
     *
     * @since 2.0.2.1
     * @return void
     */
    public function render_floating_sync_widget()
    {
        global $current_screen;
        $s_id = isset($current_screen->id) ? $current_screen->id : '';
        if($s_id == 'toplevel_page_pssg-sync') return; 
        $nonce    = wp_create_nonce( plugin_basename( PSSG_BASE_FILE ) );
        $limit    = $this->Products->get_one_load_limit();
        $per_page = $this->Products->posts_per_page;

        $submit_errors = $this->get_form_submited_errors();
        $has_errors = count( $submit_errors ) > 0;
        if( $has_errors )return; // If there are form submission errors, do not render the floating sync widget to avoid conflicts with error messages.
        
        ?>
        <div id="pssg-float-sync-widget" data-sync_status="waiting">

            <div id="pssg-float-sync-panel" class="pssg-float-panel" style="display:none;">
                <div class="pssg-float-panel-header">
                    <span><?php esc_html_e( 'Synchronize Sheet', 'product-sync-master-sheet' ); ?></span>
                    <button id="pssg-float-panel-close" class="pssg-float-panel-close" type="button"
                            aria-label="<?php esc_attr_e( 'Close', 'product-sync-master-sheet' ); ?>">&#x2715;</button>
                </div>
                <div class="pssg-float-panel-body">
                    <?php if(!empty($this->sheet_url)){ ?>
                    <a class="floting-box-sheet-url" style="margin-bottom: 8px;display:block;" href="<?php echo esc_url( $this->sheet_url ); ?>" target="_blank"><i class="pssg_icon-link"></i>
                        <strong><?php esc_html_e( 'Your Sheet', 'product-sync-master-sheet' ); ?></strong></a>
                    <?php } ?>
                    <a id="pssg-float-sync-btn" class="pssg-btn pssg-has-icon primary"
                       data-nonce="<?php echo esc_attr( $nonce ); ?>"
                       data-limit="<?php echo esc_attr( $limit ); ?>"
                       data-per_page="<?php echo esc_attr( $per_page ); ?>">
                        <span><i class="pssg_icon-spin3"></i></span>
                        <strong class="pssg-float-sync-btn-txt"><?php esc_html_e( 'Synchronize Sheet', 'product-sync-master-sheet' ); ?></strong>
                        <i class="product_count"></i>
                    </a>
                    <div class="pssg-float-message-area"></div>
                    <div class="pssg-float-errors-area">
                        <p class="error-code"></p>
                        <div class="errors-lists"></div>
                    </div>
                </div>
            </div>
            <?php
            $min_max_img = PSSG_BASE_URL . 'assets/images/logo.gif';
            ?>
            <img id="pssg-float-sync-toggle" class="pssg-float-toggle-btn" type="button"
                    title="<?php esc_attr_e( 'Synchronize Sheet', 'product-sync-master-sheet' ); ?>"
                    src="<?php echo esc_url( $min_max_img ); ?>" alt="<?php esc_attr_e( 'Synchronize Sheet', 'product-sync-master-sheet' ); ?>">
                

        </div>
        <?php
    }

    public function admin_footer_text($text)
    {
        $rev_link = 'https://www.trustpilot.com/review/codeastrology.com';
        $text = sprintf(
            __('Thank you for using our Plugin <a href="%s" target="_blank">%sPlease review us</a>.', 'product-sync-master-sheet'),
            $rev_link,
            '<i class="pssg-star-filled"></i><i class="pssg-star-filled"></i><i class="pssg-star-filled"></i><i class="pssg-star-filled"></i><i class="pssg-star-filled"></i>'
        );
        return '<span id="footer-thankyou" class="pssg-footer-thankyou">' . $text . '</span>';
    }
}
