<?php
namespace ModulesAbstract\ElectronicInvoice\EntityQueueListing;

use App\Mvc\View\Utils\Types\ListingColumn;

abstract class View_List extends \App\Mvc\View_Window_PaginatedListing_ListAbstract
{
	protected $resultsPerPageList= [5, 10, 15, 20, 25, 30, 50, 100];

	protected function list_getThDetails()
	{
		return \App\Mvc\View\Utils\Types\ListingColumns::create()
			->append(
				ListingColumn::create('idInvoice')
			)
			->append(
				ListingColumn::create('invoiceDate')
			)
			->append(
				ListingColumn::create('client')
			)

			->append(
				ListingColumn::create('addTime')
					->setSortable('DESC')
			)
			->append(
				ListingColumn::create('status')
					->setSortable('DESC')
			)
			->append(
				ListingColumn::create('lastUpdateTime')
					->setType('datetime')
					->setSortable('DESC')
			)
		->loadLabels($this->lang['index']['listCols'])
		->loadSettings($this->input['listingParams']->getDynamicColumnsSettings());
	}


	abstract protected function createValidator();

	/**
	 * Retrieves the CSS class for a given status.
	 *
	 * @param string $status
	 * @return string The CSS class for the given status.
	 */
	public function getStatusCssClass($status)
    {
        $validator = $this->createValidator();
        $initialStatuses =  $validator->getInitialStatuses();
        $intermediaryStatuses =  $validator->getIntermediaryStatuses();
        $finalStatuses =  $validator->getFinalStatuses();

		$errorStatuses = array_filter($validator->getAllStatuses(), function($s) {
            return preg_match("/.+:error$/", $s);
        });
		$ignoreStatuses = array_filter($validator->getAllStatuses(), function($s) {
            return preg_match("/^ignored$/", $s);
        });

		if (in_array($status, $ignoreStatuses)) {
            return 'status-ignored';
        }

        if (in_array($status, $errorStatuses)) {
            return 'status-error';
        }
        if (in_array($status, $initialStatuses)) {
            return 'status-initial';
        }
        if (in_array($status, $intermediaryStatuses)) {
            return 'status-pending';
        }
        if (in_array($status, $finalStatuses)) {
            return 'status-success';
        }


        return 'status-undefined';
    }
}