<?php

namespace App\Livewire;

use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Columns\ButtonGroupColumn;
use Rappasoft\LaravelLivewireTables\Views\Columns\LinkColumn;
use App\Models\User;
use Carbon\Carbon;

class UsersTable extends DataTableComponent
{
    protected $model = User::class;

    public function configure(): void
    {
        $this->setPrimaryKey('id')
		->setPaginationMethod('simple');
    }

    public function columns(): array
    {
        return [
            Column::make("Id", "id")
                ->sortable(),
            Column::make("Name", "name")
                ->sortable()
				->searchable(),
            Column::make("Id#", "idNumber")
                ->sortable()
				->searchable(),
            Column::make("Phone#", "phoneNumber")
                ->sortable()
				->searchable(),
            Column::make("Organization", "organization")
                ->sortable(),
            Column::make("KRA PIN", "kraPin")
                ->sortable()
				->hideIf(true),
            Column::make("Email", "email")
                ->sortable()
				->hideIf(true),
            Column::make("UserId", "userId")
                ->sortable()
				->hideIf(true),
            Column::make("Status", "status")
                ->sortable(),
            Column::make("Created at", "created_at")
                ->sortable()
				->format(fn($row) => Carbon::parse($row)->format('M d, Y, h:i A')),
            Column::make("Updated at", "updated_at")
                ->sortable()
				->format(fn($row) => Carbon::parse($row)->format('M d, Y, h:i A'))
				->hideIf(true),
			Column::make('Actions')
			->label(
				function ($row, Column $column) {
					$edit = '<button class="btn btn-round btn-primary btn-sm mx-1" wire:click="edit('.$row->id.')">Edit</button>';
					$delete = '<button class="btn btn-round btn-danger btn-sm mx-1" wire:click="delete('.$row->id.')">Trash</button>';
					return $edit.$delete;
				}
			)->html(),
				
        ];
    }
}
