$title = 'SubAdmin'
  @include('admin.include.header')

      <!-- Main Content -->
      <div class="main-content">
        <section class="section">
          <div class="section-body">
            <div class="row">
              <div class="col-12 col-md-6 col-lg-6">
                <div class="card">
                  <form id="subadmin">
                    @csrf
                    <div class="card-header">
                      <h4>Add Sub-Admin</h4>
                    </div>
                    <div class="card-body">
                      <div class="form-group">
                        <label>Name</label>
                        <input type="text" id="name" name="name" class="form-control" required="">
                      </div>
                      <div class="form-group">
                        <label>Email</label>
                        <input type="email" id="email" name="email" class="form-control" required="">
                      </div>
                      <div class="form-group">
                        <label>Mobile</label>
                        <input type="text" id="mobile" name="mobile" class="form-control">
                      </div>
                      <div class="form-group">
                        <label>Password</label>
                        <input type="password" id="password" minlength="6" name="password" class="form-control" required="">
                      </div>
                      <div class="form-group">
                        <label>Permission</label><Br>
                        <label>Write</label><Br>
                        @foreach (json_decode($pages->value)->page as $per)
                            <input type="checkbox" id="permission[]" name="permission[write][]"  value="{{$per}}">{{$per}}
                        @endforeach
                        <br>

                        <label>Read</label><Br>
                        @foreach (json_decode($pages->value)->page as $per)
                            <input type="checkbox" id="permission[]" name="permission[read][]"  value="{{$per}}">{{$per}}
                        @endforeach
                      </div>
                    </div>
                    <p id="message"></p>
                    <div class="card-footer text-right">
                      <button type="submit" class="btn btn-primary">Submit</button>
                    </div>
                  </form>
                </div>

              </div>

            </div>
          </div>
        </section>
      </div>

    </div>
  </div>

  @include('admin.include.footer')
  <script>
    $(document).ready(function() {
      $('#subadmin').on('submit', function(e) {
        e.preventDefault();
        axios.post('http://localhost/ecommerce/admin/create_subadmin', new FormData(this))
          .then((res) => {
            if (res.data){
              document.getElementById("subadmin").reset();
              show_Toaster('SubAdmin Created Successfully','success');
              setTimeout(() => {
                    window.location.href = `${url}/admin/subadmin`;
                }, 500);
            }
            else {
              show_Toaster('Operation failed','fail');
            }
          });
      });
    });
  </script>
