<?php

namespace Easymailing\App\Core\Provider\Woocommerce\Widgets;

use Easymailing\App\Core\Provider\Woocommerce\Service\MetadataHelper;
use Easymailing\App\Core\Provider\Woocommerce\Service\SynchronizationViewHandler;


class CategoryWidgets
{
	private $synchronizationViewHandler;

	public function __construct(SynchronizationViewHandler $synchronizationViewHandler)
	{
		$this->synchronizationViewHandler = $synchronizationViewHandler;
	}

	function addWidgets($term): void
    {
        $status = get_term_meta($term->term_id, MetadataHelper::getSynchronizationStatus(), true);
        $content = $this->synchronizationViewHandler->getWidgetContent($status, $term->term_id, 'category');
        echo $content;
    }

    public function addSynchronizationColumn($columns): array
    {
        $columns[MetadataHelper::getSynchronizationStatus()] = __('Sincronización Easymailing', 'easymailing');
        return $columns;
    }

    function showCustomCategoryColumnData($content, $columnName, $termId): string
    {
        if (MetadataHelper::getSynchronizationStatus() === $columnName) {
            $status = get_term_meta($termId, MetadataHelper::getSynchronizationStatus(), true);
            return $this->synchronizationViewHandler->getTableContent($status, $termId, 'category');
        }

        return $content;
    }
}
