46 lines
974 B
PHP
46 lines
974 B
PHP
<?php
|
|
|
|
namespace App\Livewire\Rewards\Modals;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class Purchase extends ModalComponent
|
|
{
|
|
public array $item = [];
|
|
public int $balance = 0;
|
|
public bool $confirming = false;
|
|
public bool $purchased = false;
|
|
|
|
public function mount(array $item = [], int $balance = 0): void
|
|
{
|
|
$this->item = $item;
|
|
$this->balance = $balance;
|
|
}
|
|
|
|
public function confirm(): void
|
|
{
|
|
$this->confirming = true;
|
|
}
|
|
|
|
public function purchase(): void
|
|
{
|
|
if (($this->item['price'] ?? 0) > $this->balance) {
|
|
return;
|
|
}
|
|
$this->balance -= (int) $this->item['price'];
|
|
$this->purchased = true;
|
|
$this->confirming = false;
|
|
}
|
|
|
|
public static function modalMaxWidth(): string
|
|
{
|
|
return 'md';
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.rewards.modals.purchase');
|
|
}
|
|
}
|