<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<title>Панель Администратора</title>
</head>
<body>
<h1>Панель Администратора</h1>
<form action="{{ route('logout') }}" method="POST">
@csrf
<button type="submit">Выйти</button>
</form>
<hr>
@if(session('errorMessage') || $errors->any())
<p style="color: red;"><b>Ошибка:</b> {{ session('errorMessage') ?? $errors->first() }}</p>
@endif
@if(session('successMessage'))
<p style="color: green;"><b>Успешно:</b> {{ session('successMessage') }}</p>
@endif
<h3>Добавить пользователя</h3>
<form action="{{ route('admin.users.store') }}" method="POST">
@csrf
<p>
<label>ФИО:</label><br>
<input type="text" name="name" required>
</p>
<p>
<label>Логин:</label><br>
<input type="text" name="login" required>
</p>
<p>
<label>Пароль:</label><br>
<input type="password" name="password" required minlength="6">
</p>
<p>
<label>Роль:</label><br>
<select name="role">
<option value="Пользователь">Пользователь</option>
<option value="Администратор">Администратор</option>
</select>
</p>
<button type="submit">Добавить</button>
</form>
<hr>
<h3>Список пользователей</h3>
<table border="1" cellpadding="5" cellspacing="0">
<thead>
<tr>
<th>Логин</th>
<th>ФИО</th>
<th>Роль</th>
<th>Заблокирован</th>
<th>Действие</th>
</tr>
</thead>
<tbody>
@foreach($users as $userItem)
<tr>
<form action="{{ route('admin.users.update', $userItem->id) }}" method="POST">
@csrf
@method('PUT')
<td>{{ $userItem->login }}</td>
<td>
<input type="text" name="name" value="{{ $userItem->name }}" required>
</td>
<td>
<select name="role">
<option value="Пользователь" @selected($userItem->role === 'Пользователь')>Пользователь</option>
<option value="Администратор" @selected($userItem->role === 'Администратор')>Администратор</option>
</select>
</td>
<td align="center">
<input type="checkbox" name="is_blocked" value="1" @checked($userItem->is_blocked)>
</td>
<td>
<button type="submit">Сохранить</button>
</td>
</form>
</tr>
@endforeach
</tbody>
</table>
</body>
</html>