@extends('layouts.master')
@section('content')

<div class="content-wrapper">
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0">Team Member List</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Home</a></li>
                        <li class="breadcrumb-item active">Team Member List</li>
                    </ol>
                </div>
            </div>
        </div>
    </div>
    <div class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">
                    <!-- Default box -->
                    <div class="card">
                        <!-- <form action="" name="form"> -->
                        <form action="" name="form">
                            <div class="card-header">
                                <h3 class="card-title">Team Member List
                                    <!-- <button type="submit" class="btn btn-primary">
                                        Submit
                                    </button> -->
                                </h3>
                                <div class="card-tools">
                                    <button type="button" class="btn btn-tool" data-card-widget="collapse"
                                        title="Collapse">
                                        <i class="fas fa-minus"></i>
                                    </button>
                                    <!-- <button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
                                    <i class="fas fa-times"></i>
                                </button> -->
                                </div>
                            </div>
                            <div class="card-body">
                                {{ $dataTable->table() }}
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="assignEmailPopup" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">        
</div>

<div class="modal fade" id="isadmin-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="modal-title"></h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form method="post" action="{{ route('users.updateIsAdmin') }}">
                @csrf
                <div class="modal-body">
                    <input type="hidden" name="CustomerID" id="CustomerID">
                    <input type="hidden" name="isadminvalue" id="isadminvalue">
                    <input type="hidden" name="user_id" id="user_id">
                </div>
                <div class="modal-footer justify-content-between">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">OK</button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal" tabindex="-1" role="dialog" id="emailUpdateModel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Edit Email</h5>
      </div>
        <div class="modal-body">
            <div class="card-body">
                <form action="{{ route('edit-user-email') }}" id="email_update_form" method="post">
                @csrf
                <input type="hidden" name="user_id" id="edit_email_user_id">
                <div class="form-group">
                    <label class="form-label">Sender Name</label>
                    <input class="form-control col-lg-12" type="text" name="sender_name" id="sender_name">
                    <label class="form-label">Sender Email</label>
                    <input class="form-control col-lg-12" type="text" name="sender_email" id="sender_email">
                    <label class="form-label">CC Email</label>
                    <input class="form-control col-lg-12" type="text" name="cc_email" id="cc_email">
                    <label class="form-label">BCC Email</label>
                    <input class="form-control col-lg-12" type="text" name="bcc_email" id="bcc_email">
                </div>
            </div>
        </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-primary">Edit</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
      </div>
      </form>
    </div>
  </div>
</div>

@push('scripts')
{{ $dataTable->scripts() }}
@endpush
<script>

function updateIsAdmin(elm) {
    var CustomerID = $(elm).attr('data-CustomerID');
    var user_id = $(elm).attr('data-user_id');
    var isadminvalue = elm.value;
    if (isadminvalue != "true") {
        $("#modal-title").html("Are you sure? you want to make it admin?");
    } else {     
        $("#modal-title").html("Are you sure? you want to remove admin?");  
    }

    $("#CustomerID").val(CustomerID);
    $("#user_id").val(user_id);
    $("#isadminvalue").val(isadminvalue);
    $("#isadmin-modal").modal('show');
}
function emailupdate(elm) {
    $('#edit_email_user_id').val(elm.id);
    $('#sender_name').val($('#'+elm.id).attr('sender_name'));
    $('#sender_email').val($('#'+elm.id).attr('sender_email'));
    $('#cc_email').val($('#'+elm.id).attr('cc_email'));
    $('#bcc_email').val($('#'+elm.id).attr('bcc_email'));
    $('#emailUpdateModel').modal('show');
}

function assignEmail(elm) {
    $.ajax({
        type: "POST",
        url: "{{ url('user/popup-assign-email') }}" + '/' + elm.id,
        data: {
            "_token": "{{ csrf_token() }}"
        },
        success: function(data) {
            $('#assignEmailPopup').html(data.html);
            $('#assignEmailPopup').modal('show');
        }
    });
}
</script>

@endsection