<?php

namespace PWH_DCFH\App\Base;

if (!defined('ABSPATH')) {
    exit;
}
if (!class_exists('PWH_DCFH_Plugin_Meta_Links')) {
    class PWH_DCFH_Plugin_Meta_Links
    {
        /**
         * Initializer Of The Class
         * Add/Remove Necessary Actions/Filters
         */
        public function init()
        {
            add_filter('plugin_action_links', [$this, 'maybe_action_links'], 10, 2);
            add_filter('plugin_row_meta', [$this, 'maybe_plugin_row_meta'], 10, 4);
        }

        /**
         * Add Plugin Links
         *
         * @param $links
         * @param $file
         *
         * @return mixed
         */
        public function maybe_action_links($links, $file)
        {
            if (PWH_DCFH_PLUGIN_BASENAME !== $file) {
                return $links;
            }
            $url = admin_url("admin.php?page=".pwh_dcfh_wp_helpers()::get_divi_setting_slug()."#wrap-pwh-dcfh-epanel");
            /* translators: 1: URL to page, 2: Link Title. */
            $settings_link = sprintf('<a href="%1$s">%2$s</a>', $url, __('Settings', 'pwh-dcfh'));
            array_unshift($links, $settings_link);

            return $links;
        }

        /**
         * Plugin Row Meta
         *
         * @param $plugin_meta
         * @param $plugin_file
         * @param $plugin_data
         * @param $status
         *
         * @return array|mixed
         */
        public function maybe_plugin_row_meta($plugin_meta, $plugin_file, $plugin_data, $status)
        {
            if (PWH_DCFH_PLUGIN_BASENAME !== $plugin_file) {
                return $plugin_meta;
            }
            $plugin_meta ['pwh_dcfh_doc_support'] = sprintf('<a href="%1$s" target="_blank">%2$s</a>', esc_url('https://www.peeayecreative.com/docs/divi-contact-form-helper/'), __('Documentation & Support', 'pwh-dcfh'));

            return $plugin_meta;
        }

    }
}