<?php
/**
 * Livewire Component
 *
 * @version     3.0.$Revision:$
 * @version     SVN: $Id:$
 * @version     STUB: 4.2.0
 * @generated   2026-04-27 21:40:06
 * @package     bplan-base/globals
 * @subpackage  LivewireComponents
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 * @copyright   Copyright (C) 2025, 2026 bplan-solutions GmbH & Co. KG <https://www.bplan-solutions.de/>
 * /Δ\
 */

namespace BplanBase\Globals\Livewire\PrinterType;


use BplanBase\Globals\DataGrid\DataGrid;
use BplanBase\Globals\Models\PrinterType;
use BplanBase\Globals\Repositories\IndexCollectionRepository;
use BplanBase\Globals\Traits\WithDataGrid;
use Illuminate\Pagination\LengthAwarePaginator;
use Livewire\Component;
use Livewire\WithPagination;


/**
 * Livewire Component
 *
 * @version     1.0.0 / 2026-04-27
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
class Index extends Component
{


/* +++ TRAITS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */


    use WithDataGrid;
    use WithPagination;


/* +++ CLASS CONSTANTS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ OBJECT MEMBERS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     * @var     array
     */
    protected array $_formatCasts = [
        'active'           => 'boolean',
        'config_template'  => 'json',
        'created_at'       => 'datetime',
        'deleted_at'       => 'datetime',
        'payload_template' => 'json',
        'updated_at'       => 'datetime',
    ];


    /**
     * Specifies the columns to use and their order
     *
     * @var     array
     */
    protected array $_gridColumns = [
        'id',
        'brand',
        'model',
        'label',
    ];


    /**
     * @var     string
     */
    protected string $_gridLocaleFile = 'globals::printer-types';


    /**
     * @var     string
     */
    protected string $_modelClass = PrinterType::class;


    /**
     * @var     array
     */
    protected array $_searchFields = [
        'brand',
        'identifier',
        'label',
        'model',
    ];


    /**
     * @var     array
     */
    protected $listeners = [
        'printer-type-created' => 'render',
        'printer-type-edited'  => 'render',
        'printer-type-deleted' => 'render',
    ];


/* +++ CLASS MEMBERS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ OBJECT METHODS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     *
     * @return      LengthAwarePaginator<PrinterType>
     *
     * @version     1.0.0 / 2026-04-27
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    private function _getData(): LengthAwarePaginator
    {
        return IndexCollectionRepository::getPrinterTypes(
            ExtendQuery: $this->_getQuery(),
            orderBy: $this->_getOrderBy()
        );
    } // _getData()


    /**
     *
     * @return      DataGrid
     *
     * @version     1.0.0 / 2026-04-27
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    private function _getGrid(): DataGrid
    {
        $gridData = $this->_getData();

        return (new DataGrid('printer-type'))
            ->setActions([
                'edit-printer-type',
            ])
            ->setActionSvgIcons([
                'edit-printer-type' => svg_icon('globals.svg-icons.action-edit'),
            ])
            ->setActiveFilters($this->_hasActiveFilters())
            ->setColumnCallback(function ($Item, $property, $value) {
                switch ($property) {
                    case 'brand':
                        // ...
                        break;

                    case 'id':
                        // ...
                        break;

                    case 'label':
                        // ...
                        break;

                    case 'model':
                        // ...
                        break;
                }
                return $value;
            })
            ->setColumns($this->_gridColumns)
            ->setData($gridData)
            ->setLocaleFile($this->_gridLocaleFile)
            ->setSorting($this->sortColumns, $this->sortColumn, $this->sortDirection)
            ->useCaptions(true)
            ->useDefaultCreateButton(true)
            ->useDefaultSearch(true);

    } // _getGrid()


    /**
     *
     * @version     1.0.0 / 2026-04-27
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function render()
    {
        return view('globals::livewire.printer-type.index', [
            'grid' => $this->_getGrid(),
        ]);
    } // render()


/* +++ CLASS METHODS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


} // class Index extends Component {}
