<?php

namespace Booktics\Extensions;

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

use Booktics\Booktics;

class Extension_Icon {
    /**
     * Get icon
     *
     * @param string $extension_name
     *
     * @return string
     */
    public static function get( string $extension_name ): string {
        return self::get_svg( $extension_name );
    }

    /**
     * Get svg icon
     *
     * @param string $file_name
     */
    public static function get_svg( string $file_name ) {
        $extensions = array( 'svg', 'jpg', 'png', 'webp' );
        $base_url   = Booktics::assets_url() . 'images/addons/';
        $base_path  = BOOKTICS_DIR . '/assets/images/addons/';

        foreach ( $extensions as $ext ) {
            $file = $base_path . $file_name . '.' . $ext;
            if ( file_exists( $file ) ) {
                return $ext === 'svg' ? file_get_contents( $file ) : $base_url . $file_name . '.' . $ext;
            }
        }
        return '';
    }
}
