@extends('layouts.app')
@section('content')
<!-- Content Header (Page header) -->
<div class="content-header">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-6">
        <h1 class="m-0 text-dark">Staff List</h1>
      </div>
      <div class="col-sm-6">
        <ol class="breadcrumb float-sm-right">
          <li class="breadcrumb-item"><a href="{{ route('home') }}">Home</a></li>
          <li class="breadcrumb-item active">Staff List</li>
        </ol>
      </div>
    </div>
  </div>
</div>

<div class="card">
  <div class="card-header">
    <h3 class="card-title">Staff List</h3>
    <button class="btn btn-danger btn-sm float-right" data-toggle="modal" data-target="#modal-default">Add New</button>
  </div>

  <div class="card-body">
    <table id="example1" class="table table-bordered table-striped">
      <thead>
        <tr>
          <th>Staff Image</th>
          <th>Staff Name</th>
          <th>Designation</th>
          <th>Type</th>
          <th>Action</th>
        </tr>
      </thead>
      <tbody>
        @foreach($ads as $row)
        <tr>
          <td><img src="{{ asset($row->ads) }}" style="height: 100px; width: 100px;"></td>
          <td>{{ $row->link }}</td>
          <td>{{ $row->desigination }}</td>
          <td>{{ $row->type == 2 ? 'Management' : 'Staff' }}</td>
          <td>
            <a href="javascript:void(0)" class="btn btn-sm btn-info" data-toggle="modal" data-target="#editStaffModal{{ $row->id }}">
              <i class="fa fa-edit"></i>
            </a>
            <a href="{{ route('delete.ads', $row->id) }}" class="btn btn-danger" id="delete">
              <i class="fa fa-trash"></i>
            </a>
          </td>
        </tr>

        <!-- Edit Staff Modal (inside foreach loop!) -->
        <div class="modal fade" id="editStaffModal{{ $row->id }}">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <h4 class="modal-title">Edit Staff</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <div class="modal-body">
                <form action="{{ route('update.ads', $row->id) }}" method="POST" enctype="multipart/form-data">
                  @csrf
                  <div class="form-group">
                    <label>Staff Name</label>
                    <input type="text" name="link" class="form-control" value="{{ $row->link }}" required>
                  </div>
                  <div class="form-group">
                    <label>Designation</label>
                    <input type="text" name="desigination" class="form-control" value="{{ $row->desigination }}" required>
                  </div>
                  <div class="form-group">
                    <label>Current Image</label><br>
                    <img src="{{ asset($row->ads) }}" width="100" height="70" class="mb-2">
                    <input type="file" name="ads" class="form-control">
                    <small class="form-text text-muted">Leave blank to keep current image.</small>
                  </div>
                  <div class="form-group">
                    <label>Type</label>
                    <select name="type" class="form-control" required>
                      <option value="2" {{ $row->type == 2 ? 'selected' : '' }}>Management</option>
                      <option value="3" {{ $row->type == 3 ? 'selected' : '' }}>Staff</option>
                    </select>
                  </div>
                  <button type="submit" class="btn btn-primary btn-block">Update</button>
                </form>
              </div>
            </div>
          </div>
        </div>
        @endforeach
      </tbody>
      <tfoot>
        <tr>
          <th>Staff Image</th>
          <th>Staff Name</th>
          <th>Designation</th>
          <th>Type</th>
          <th>Action</th>
        </tr>
      </tfoot>
    </table>
  </div>
</div>

<!-- Add New Staff Modal -->
<div class="modal fade" id="modal-default">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Insert new Staff</h4>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>

      <div class="modal-body">
        <form action="{{ route('store.ads') }}" method="POST" enctype="multipart/form-data">
          @csrf
          <div class="form-group">
            <label>Staff Name</label>
            <input type="text" class="form-control @error('link') is-invalid @enderror" name="link" required>
            @error('link')
            <span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
            @enderror
          </div>
          <div class="form-group">
            <label>Designation</label>
            <input type="text" class="form-control @error('desigination') is-invalid @enderror" name="desigination" required>
            @error('desigination')
            <span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
            @enderror
          </div>
          <div class="form-group">
            <label>Staff Image</label>
            <input type="file" class="form-control" name="ads" required>
          </div>
          <div class="form-group">
            <label>Type</label>
            <select class="form-control" name="type" required>
              <option value="2">Management</option>
              <option value="3">Staff</option>
            </select>
          </div>
          <button type="submit" class="btn btn-success btn-block">Submit</button>
        </form>
      </div>
    </div>
  </div>
</div>
@endsection
