<?php
namespace Avirtum\GutenDraw\System;

defined( 'ABSPATH' ) || exit;

use Avirtum\GutenDraw\Models\AccessModel;

class Feedback {
    public function __construct() {
        add_action( 'init', [ $this, 'init' ] );
    }

    public function init() {
        add_filter( 'plugin_action_links_' . GUTENDRAW_PLUGIN_BASE_NAME, [ $this, 'pluginActionLinks' ], 10, 4);
        add_action( 'admin_footer', [ $this, 'adminFooter' ] );
    }

    public function adminFooter() {
        if ( get_current_screen() && get_current_screen()->base !== 'plugins' ) {
            return;
        }

        $globals = [
            'version' => GUTENDRAW_PLUGIN_VERSION,
            'token' => AccessModel::getToken(),
            'api' => [
                'feedback_url' => GUTENDRAW_FEEDBACK_URL
            ]
        ];

        wp_enqueue_style( 'gutendraw-feedback', GUTENDRAW_PLUGIN_URL . 'assets/css/feedback.css', [], GUTENDRAW_PLUGIN_VERSION );
        wp_enqueue_script( 'gutendraw-feedback', GUTENDRAW_PLUGIN_URL . 'assets/js/feedback.js', ['jquery'], GUTENDRAW_PLUGIN_VERSION, false );
        wp_localize_script( 'gutendraw-feedback', 'gutendraw_feedback_globals', $globals );

        require_once( GUTENDRAW_PLUGIN_PATH . '/includes/Views/feedback.php' );
    }

    public function pluginActionLinks($actions) {
        $links = [];
        $links['settings'] = '<a href="' . network_admin_url('admin.php?page=gutendraw-settings') . '">Settings</a>';

        return array_merge($actions, $links);
    }
}
