<?php #CodeGenerator V3 Δ b5cadca84db841c69c12dc5670fc3f6e Δ DYNAMICALLY GENERATED FILE - Do not modify this line! Remove it completely to protect the file from changes.
/**
 * Livewire Component
 *
 * @version     3.0.$Revision:$
 * @version     SVN: $Id:$
 * @version     STUB: 5.0.0
 * @generated   2026-06-09 01:44:17
 * @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\UserRecord;


use BplanBase\Globals\DataGrid\DataGrid;
use BplanBase\Globals\Models\UserRecord;
use BplanBase\Globals\Repositories\IndexCollectionRepository;
use BplanBase\Globals\Traits\WithDataGrid;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
use Livewire\Component;
use Livewire\WithPagination;


/**
 * Livewire Component
 *
 * @version     1.0.0 / 2026-06-09
 * @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 = [
        'created_at' => 'datetime',
        'deleted_at' => 'datetime',
        'updated_at' => 'datetime',
    ];


    /**
     * Specifies the columns to use and their order
     *
     * @var     array
     */
    protected array $_gridColumns = [
        'id',
        'email',
        'first_name',
        'last_name',
    ];


    /**
     * @var     string
     */
    protected string $_gridLocaleFile = 'globals::user-records';


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


    /**
     * @var     array
     */
    protected array $_searchFields = [
        'email',
        'first_name',
        'last_name',
    ];


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


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


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


    /**
     *
     * @return      array|Collection|LengthAwarePaginator<UserRecord>
     *
     * @version     1.0.0 / 2026-06-09
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    private function _getData(): array|Collection|LengthAwarePaginator
    {
        return IndexCollectionRepository::getUserRecords(
            ExtendQuery: $this->_getQuery(),
            orderBy: $this->_getOrderBy()
        );
    } // _getData()


    /**
     *
     * @return      DataGrid
     *
     * @version     1.0.0 / 2026-06-09
     * @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('user-record'))
            ->setActions([
                'edit-user-record',
            ])
            ->setActionSvgIcons([
                'edit-user-record' => svg_icon('globals.svg-icons.action-edit'),
            ])
            ->setActiveFilters($this->_hasActiveFilters())
            ->setColumnCallback(function ($Item, $property, $value) {
                switch ($property) {
                    case 'email':
                        // ...
                        break;

                    case 'first_name':
                        // ...
                        break;

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

                    case 'last_name':
                        // ...
                        break;
                }
                return $value;
            })
            ->setColumns($this->_gridColumns)
            ->setData($gridData)
            ->setLocaleFile($this->_gridLocaleFile)
            ->setSorting($this->sortColumns, $this->sortColumn, $this->sortDirection)
            ->useCaptions(true)
            ->useDefaultCreateButton(auth()->user()->can('user-record.create'))
            ->useDefaultSearch(false);

    } // _getGrid()


    /**
     *
     * @version     1.0.0 / 2026-06-09
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function mount(): void
    {
        $this->authorize('user-record.read');

    } // mount()


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


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


} // class Index extends Component {}
