<?php

namespace KupShop\AdminBundle\Admin;

class UsersFilter
{
    protected $template = 'block.usersFilter.tpl';
    protected $params;

    public function getFilterData(): array
    {
        $data = [];

        // figure
        $figure = [
            'Y' => translate('figureActive', 'usersFilter'),
            'N' => translate('figureInactive', 'usersFilter'),
        ];
        $data['figure'] = $figure;

        // newsletter
        $newsletter = [
            'Y' => translate('newsletterSubscribed', 'usersFilter'),
            'N' => translate('newsletterUnsubscribed', 'usersFilter'),
        ];
        $data['newsletter'] = $newsletter;

        return $data;
    }

    public function getFilter($filter = [])
    {
        if ($filter) {
            foreach ($filter as $key => $item) {
                if (is_array($item)) {
                    $values = array_values($item);
                    $filter[$key] = array_combine($values, $values);
                }
            }
        }

        return $filter;
    }

    public static function cleanFilter(array $filter): array
    {
        foreach ($filter as $key => $value) {
            if (is_array($value) && empty(array_filter($value, 'strlen'))) { // 'strlen' to leave 0 (zero) values
                unset($filter[$key]);
            }
        }

        return $filter;
    }

    public function getTemplate()
    {
        return $this->template;
    }
}
