Files
nuhodds_fi4/app/Filament/Pages/PlayerProps.php
T

235 lines
8.0 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Actions\LoadSofaScoreCategory;
use App\Actions\LoadStatisticFixturesLeaguesOptions;
use App\Actions\LoadStatisticFixturesMatchOptions;
use App\Filament\Widgets\PlayerPropsDrop;
use App\Filament\Widgets\PlayerPropsTable;
use App\Models\SofaScoreRosa;
use App\Models\SsLineupMemory;
use App\Models\StatisticFixtures;
use BackedEnum;
use Filament\Forms\Components\Select;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Pages\Page;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\On;
class PlayerProps extends Page implements HasForms
{
use InteractsWithForms;
protected string $view = 'filament.pages.player-props';
protected static string|BackedEnum|null $navigationIcon = 'icon-soccerplayer';
public function getHeading(): string
{
return '';
}
protected static ?string $title = 'Player Props';
protected static ?int $navigationSort = 2;
public ?array $filterData;
public array $lineUpOptinos;
public string $activeLineUp = '3313';
public array $players = [];
public array $clientLineUps = [];
public int $team_id;
public function mount(): void
{
// Initialisiert das Formular mit leeren Werten
$this->form->fill();
}
public function getWidgetData(): array
{
return [
'activeLineUp' => $this->activeLineUp,
];
}
public function form(Schema $schema): Schema
{
return $schema
->columns(5)
->components([
Select::make('cid')
->live()
->preload()
->searchable(false)
->prefixIconColor(fn(Get $get): string => $get('cid') ? 'success' : 'danger')
->prefixIcon('phosphor-globe-fill')
->hiddenLabel()
->options(fn() => LoadSofaScoreCategory::load())
->placeholder('Country')
->afterStateUpdated(function (callable $set, $state) {
$set('lid', null);
$set('mid', null);
$set('tid', null);
}),
Select::make('lid')
->live()
->preload()
->prefixIconColor(fn(Get $get): string => $get('lid') ? 'success' : 'danger')
->prefixIcon('phosphor-trophy-fill')
->hiddenLabel()
->options(fn(Get $get) => LoadStatisticFixturesLeaguesOptions::load($get('cid')))
->placeholder('League')
->afterStateUpdated(function (callable $set) {
$set('mid', null);
$set('tid', null);
}),
Select::make('mid')
->live()
->hiddenLabel()
->prefixIconColor(fn(Get $get): string => $get('mid') ? 'success' : 'danger')
->prefixIcon('phosphor-calendar-check-fill')
->options(function (Get $get) {
return LoadStatisticFixturesMatchOptions::load($get('lid'));
})
->afterStateUpdated(function (callable $set, $state) {
$this->dispatch('match-update', match_id: $state);
$set('tid', null);
})
->placeholder('Events'),
Select::make('tid')
->live()
->hiddenLabel()
->prefixIconColor(fn(Get $get): string => $get('tid') ? 'success' : 'danger')
->prefixIcon('phosphor-users-three-fill')
->options(function (Get $get) {
if ($get('mid')) {
$res = StatisticFixtures::where('id', $get('mid'))->first();
$arr = [];
if ($res) {
$arr[$res->home_id] = SofaScoreRosa::query()->where('ss_team_id', $res->home_id)->value('ss_team_name');
$arr[$res->away_id] = SofaScoreRosa::query()->where('ss_team_id', $res->away_id)->value('ss_team_name');
}
return $arr;
}
})
->placeholder('Team')->afterStateUpdated(function ($state) {
$this->dispatch('team-update', team_id: $state);
}),
Select::make('lineup')
->live()
->hiddenLabel()
->allowHtml()
->native(false)
->prefixIconColor('info')
->prefixIcon('icon-soccerfield-fill')
->options(function () {
$res = $this->lineUpOptinos();
$arr = [];
foreach ($res as $key => $value) {
if ($this->players && in_array($key, $this->clientLineUps))
$arr[$key] = $value . '<span class="text-blue-600"> has lineup</span>';
else
$arr[$key] = $value;
}
return $arr;
})
->placeholder('LineUp')
->searchable()
->default($this->activeLineUp)
->afterStateUpdated(function ($state) {
$this->dispatch('lineup-update', activeLineUp: $state);
}),
])->statePath('filterData');
}
#[On('team-update')]
public function syncData(int $team_id)
{
$this->team_id = $team_id;
$this->clientLineUps = SsLineupMemory::where('team_id', $team_id)->where('client_id', Auth::user()->client_id)->pluck('lineup')->toArray();
}
#[On('update-players')]
public function updatePlayers(array $players)
{
$this->players = $players;
}
protected function getFooterWidgets(): array
{
return [
PlayerPropsTable::make(['players' => $this->players]),
PlayerPropsDrop::make(['players' => $this->players]),
];
}
public function getFooterWidgetsColumns(): int|array
{
return 5;
}
private function lineUpOptinos(): array
{
return [
'3313' => '3313',
'3331' => '3331',
'3331-' => '3331-',
'3331+' => '3331+',
'3412-' => '3412-',
'3412+' => '3412+',
'3421-' => '3421-',
'3421+' => '3421+',
'343-' => '343-',
'343+' => '343+',
'3511' => '3511',
'3511-' => '3511-',
'3511+' => '3511+',
'352' => '352',
'352-' => '352-',
'352+' => '352+',
'4132' => '4132',
'4213-' => '4213-',
'4213+' => '4213+',
'4222' => '4222',
'4231' => '4231',
'424' => '424',
'4312' => '4312',
'4312-' => '4312-',
'4312+' => '4312+',
'4321' => '4321',
'4321-' => '4321-',
'4321+' => '4321+',
'433' => '433',
'433-' => '433-',
'433+' => '433+',
'4411-' => '4411-',
'4411+' => '4411+',
'442' => '442',
'442-' => '442-',
'442+' => '442+',
'451' => '451',
'451-' => '451-',
'451+' => '451+',
'523-' => '523-',
'523+' => '523+',
'5311' => '5311',
'5311-' => '5311-',
'5311+' => '5311+',
'532' => '532',
'532-' => '532-',
'532+' => '532+',
'541-' => '541-',
'541+' => '541+',
];
}
}