|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Native\Laravel; |
| 4 | + |
| 5 | +use Illuminate\Support\Traits\Conditionable; |
| 6 | +use Illuminate\Support\Traits\Macroable; |
| 7 | +use Native\Laravel\Client\Client; |
| 8 | +use Native\Laravel\Facades\Window; |
| 9 | + |
| 10 | +class Alert |
| 11 | +{ |
| 12 | + protected ?string $type; |
| 13 | + protected ?string $title; |
| 14 | + protected ?string $detail; |
| 15 | + protected ?array $buttons; |
| 16 | + protected ?int $defaultId; |
| 17 | + protected ?int $cancelId; |
| 18 | + |
| 19 | + final public function __construct(protected Client $client) |
| 20 | + { |
| 21 | + } |
| 22 | + |
| 23 | + public static function new() |
| 24 | + { |
| 25 | + return new static(new Client); |
| 26 | + } |
| 27 | + |
| 28 | + public function type(string $type): self |
| 29 | + { |
| 30 | + $this->type = $type; |
| 31 | + |
| 32 | + return $this; |
| 33 | + } |
| 34 | + |
| 35 | + public function title(string $title): self |
| 36 | + { |
| 37 | + $this->title = $title; |
| 38 | + |
| 39 | + return $this; |
| 40 | + } |
| 41 | + |
| 42 | + public function detail(string $detail): self |
| 43 | + { |
| 44 | + $this->detail = $detail; |
| 45 | + |
| 46 | + return $this; |
| 47 | + } |
| 48 | + |
| 49 | + public function buttons(array $buttons): self |
| 50 | + { |
| 51 | + $this->buttons = $buttons; |
| 52 | + |
| 53 | + return $this; |
| 54 | + } |
| 55 | + |
| 56 | + public function defaultId(int $defaultId): self |
| 57 | + { |
| 58 | + $this->defaultId = $defaultId; |
| 59 | + |
| 60 | + return $this; |
| 61 | + } |
| 62 | + |
| 63 | + public function cancelId(int $cancelId): self |
| 64 | + { |
| 65 | + $this->cancelId = $cancelId; |
| 66 | + |
| 67 | + return $this; |
| 68 | + } |
| 69 | + |
| 70 | + public function show(string $message): int |
| 71 | + { |
| 72 | + $response = $this->client->post('alert/message', [ |
| 73 | + 'message' => $message, |
| 74 | + 'type' => $this->type, |
| 75 | + 'title' => $this->title, |
| 76 | + 'detail' => $this->detail, |
| 77 | + 'buttons' => $this->buttons, |
| 78 | + 'defaultId' => $this->defaultId, |
| 79 | + 'cancelId' => $this->cancelId |
| 80 | + ]); |
| 81 | + |
| 82 | + return (int) $response->json('result'); |
| 83 | + } |
| 84 | + |
| 85 | + public function error(string $title, string $message): bool |
| 86 | + { |
| 87 | + $response = $this->client->post('alert/error', [ |
| 88 | + 'title' => $title, |
| 89 | + 'message' => $message, |
| 90 | + ]); |
| 91 | + |
| 92 | + return (bool) $response->json('result'); |
| 93 | + } |
| 94 | +} |
0 commit comments