<?php

namespace ThurData\Servers\KerioEmail\Core\UI\Traits;

use ThurData\Servers\KerioEmail\Core\Http\Request;

/**
 * Search field related functions
 *
 * @autor ThurData <info@thurdata.ch>
 */
trait Searchable
{
    protected $searchable = false;

    public function isSearchable()
    {
        return $this->searchable;
    }

    protected function getSearchKey()
    {
        $request = Request::build();
        if ($request->get('sSearch', false))
        {
            return $request->get('sSearch');
        }

        return false;
    }

    public function insertSearchForm()
    {
        if ($this->searchable)
        {
            $searchForm = new \ThurData\Servers\KerioEmail\Core\UI\Searchable();

            return $searchForm->getHtml();
        }

        return '';
    }
    
    public function insertHiddenSearchForm()
    {
        if ($this->searchable)
        {
            $searchForm = new \ThurData\Servers\KerioEmail\Core\UI\HiddenSearchable();

            return $searchForm->getHtml();
        }

        return '';
    }    
}
