<?php

namespace Macymed\MacymedLinkTracker\Utils;

if (! defined('ABSPATH')) {
    exit; // Sécurité
}

/**
 * Class Functions
 */
class Utils
{
    public static function get_current_domain()
    {
        return wp_parse_url(home_url(), PHP_URL_HOST);
    }
    /**
     * Return the plugin slug.
     *
     * @return string plugin slug.
     */
    public static function get_plugin_slug()
    {
        $path = dirname(plugin_basename(MACYMED_LINK_TRACKER_FILE));
        if (strpos($path, 'wpcontent') !== false) {
            $path = str_replace('wpcontent', 'wp-content', $path);
        }
        return $path;
    }

    /**
     * Return the basefile for the plugin.
     *
     * @return string base file for the plugin.
     */
    public static function get_plugin_file()
    {
        $path = plugin_basename(MACYMED_LINK_TRACKER_FILE);
        if (strpos($path, 'wpcontent') !== false) {
            $path = str_replace('wpcontent', 'wp-content', $path);
        }
        return $path;
    }

    /**
     * Return the version for the plugin.
     *
     * @return float version for the plugin.
     */
    public static function get_plugin_version()
    {
        // Chemin complet vers le fichier principal du plugin
        $plugin_file = plugin_dir_path(MACYMED_LINK_TRACKER_FILE) . 'macymed_link_tracker.php';

        // Vérifier si la fonction existe
        if (! function_exists('get_plugin_data')) {
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }

        // Récupérer les données du plugin
        $plugin_data = get_plugin_data($plugin_file);

        // Retourner la version
        return $plugin_data['Version'];
    }

    public static function get_plugin_dir_path()
    {
        $path = plugin_dir_path(MACYMED_LINK_TRACKER_FILE);
        if (strpos($path, 'wpcontent') !== false) {
            $path = str_replace('wpcontent', 'wp-content', $path);
        }
        return $path;
    }

    public static function get_plugin_url()
    {
        $path = plugin_dir_url(MACYMED_LINK_TRACKER_FILE);
        if (strpos($path, 'wpcontent') !== false) {
            $path = str_replace('wpcontent', 'wp-content', $path);
        }
        return $path;
    }
    public static function get_plugin_icon()
    {
        $iconUrl = Utils::get_plugin_url() . 'dist/img/icon-only.svg' ;
        return $iconUrl;
    }
    
}
