<?php
namespace Foxstudio\Plugins\Template\Utils;
use Foxstudio\Plugins\Template\Repository as Repository;
class LabelingTab {
    public function __construct()
    {
        add_filter('woocommerce_product_tabs', [$this, 'addCustomTab']);
    }

    function addCustomTab($tabs)
    {

        // Adds the new tab

        $tabs['labeling_tab'] = array(
            'title' => __('Tabela znakowań', 'pandaGadzety'),
            'priority' => 50,
            'callback' => [$this, 'customTabData']
        );

        return $tabs;

    }
    
    function customTabData()
    {
        global $product;
        \wp_enqueue_style("labelingStyle", plugins_url("/pandaGadzety/assets/css/labeling.css"));
        $sku = $product->get_sku();
        $product_repository = new Repository\ProductRepository(SERVER_URL);
        $results = $product_repository->getLabelingInfo($sku);
        // The new tab content

        $html = "<div id='labeling'>";
        $html .= "<table>";
        foreach ($results as $data) {
            $html .= $this->get_labeling_block($data['image'], $data['technology'], $data['name']);
        }
        $html .= "</table>";
        $html .= "</div>";

        echo $html;
    }

    public function get_labeling_block($img, $technology, $position) {
        $html = "<tr>";
        $html .= "<td><img src='" . $img . "'/></td>";
        $html .= "<td>";
        $html .= "<b>Technologia: </b> ". $technology."<br>";
        $html .= "<b>Pozycja: </b> ". $position."";
        $html .= "</td>";
        $html .= "</tr>";
        // $html = "<div>";
        // $html .= "<div class='photo'><img src='" . $img . "'/></div>";
        // $html .= "<div class='data'>";
        // $html .= "<p><b>Technologia: </b> ". $technology."</p>";
        // $html .= "</div>";
        // $html .= "</div>";

        return $html;
    } 
    
}