<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-gray-800"><%= project.title %></h1>

</div>

<div class="row">
    <div class="col-xl-4 col-md-6">
        <div class="card mb-4">
            <div class="card-body">
                <!-- Pills navs -->
                <ul class="nav nav-pills mb-3" id="ex1" role="tablist">
                    <li class="nav-item" role="presentation">
                        <a
                            class="nav-link active"
                            id="ex1-tab-1"
                            data-toggle="pill"
                            href="#ex1-pills-1"
                            role="tab"
                            aria-controls="ex1-pills-1"
                            aria-selected="true"
                            >Details</a
                        >
                    </li>
                    <li class="nav-item" role="presentation">
                        <a
                            class="nav-link"
                            id="ex1-tab-2"
                            data-toggle="pill"
                            href="#ex1-pills-2"
                            role="tab"
                            aria-controls="ex1-pills-2"
                            aria-selected="false"
                            ><i class="fas fa-user"></i> Members</a
                        >
                    </li>
                </ul>
                <!-- Pills navs -->

                <!-- Pills content -->
                <div class="tab-content" id="ex1-content">
                    <div
                        class="tab-pane fade show active"
                        id="ex1-pills-1"
                        role="tabpanel"
                        aria-labelledby="ex1-tab-1"
                        >
                        <h5 class="card-title text-dark">Description</h5>
                        <p class="text-dark"><%- project.description %><p/>
                                <hr>Created <%= moment(project.createdAt).fromNow() %> by <b><a href="/users/<%= project.user._id %>"><%= project.user.username %></a></b>
                                <% if (project.createdAt.toString() != project.updatedAt.toString()) { %>
                                    <br>(Edited <%= moment(project.updatedAt).fromNow() %>)
                                <% } %>
                                <br><br>
                                <% if (project.user._id.toString() == user._id) { %>
                                    <form action="/projects/<%= project._id %>" method="POST">
                                        <input type="hidden" name="_method" value="DELETE">
                                        <a href="/projects/edit/<%= project._id %>" class="btn btn-sm btn-primary"><i class="fas fa-edit"></i></a>

                                        <a class="btn btn-sm btn-danger ml-2" href="#" data-toggle="modal" data-target="#deleteProjectModal"><i class="fa fa-trash"></i></a>

                                        <div class="modal fade" id="deleteProjectModal" tabindex="-1" role="dialog" aria-labelledby="deleteProjectModalLabel"
                                            aria-hidden="true">
                                            <div class="modal-dialog" role="document">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <h5 class="modal-title" id="deleteProjectModalLabel">Delete this project?</h5>
                                                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                                            <span aria-hidden="true">×</span>
                                                        </button>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                                                        <button type="submit" class="btn btn-primary">Delete</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                    </form>
                                <% } %>
                    </div>
                    <div class="tab-pane fade" id="ex1-pills-2" role="tabpanel" aria-labelledby="ex1-tab-2">
                        <% if (project.user._id.toString() == user._id) { %>
                            <a href="/projectmembers/<%= project._id %>/new/1" class="btn btn-primary btn-sm btn-round mb-4"><i class="fas fa-plus"></i></a>
                        <% } %>
                        <div class="table-responsive">
                            <table class="table" id="dataTableMember" width="100%" cellspacing="0">
                                <thead>
                                    <tr>
                                        <th>Users</th>
                                    </tr>
                                </thead>
                                <tfoot>
                                    <tr>
                                        <th>Users</th>
                                    </tr>
                                </tfoot>
                                <tbody>
                                    <% for (let i = 0; i < project.members.length; i++) { %>
                                        <tr>
                                            <td>
                                                <img class="img-profile rounded-circle" style="width: 50px;" src="<%= project.members[i].image %>">
                                                <br>
                                                <a href="/users/<%= project.members[i]._id %>"><%= project.members[i].username %></a>

                                                <% if (project.user._id.toString() == user._id) { %>
                                                    <form method="POST" action="/projectmembers/<%= project._id %>/delete">
                                                        <input type="hidden" name="_method" value="PUT">
                                                        <input type="hidden" name="user" value="<%= project.members[i]._id %>">

                                                        <% if (user.id != project.members[i]._id) { %>

                                                        <a class="btn btn-sm btn-danger btn-round mt-3" href="#" data-toggle="modal" data-target="#deleteMember<%= i %>Modal"><i class="fa fa-trash"></i></a>
                                                    <% } %>
                                                        <div class="modal fade" id="deleteMember<%= i %>Modal" tabindex="-1" role="dialog" aria-labelledby="deleteMember<%= i %>ModalLabel"
                                                            aria-hidden="true">
                                                            <div class="modal-dialog" role="document">
                                                                <div class="modal-content">
                                                                    <div class="modal-header">
                                                                        <h5 class="modal-title" id="deleteMember<%= i %>ModalLabel">Delete this member?</h5>
                                                                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                                                            <span aria-hidden="true">×</span>
                                                                        </button>
                                                                    </div>
                                                                    <div class="modal-footer">
                                                                        <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                                                                        <button type="submit" class="btn btn-primary">Delete</button>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </form>
                                                <% } %>

                                            </td>
                                        </tr>
                                    <% } %>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <!-- Pills content -->
            </div>
        </div>
    </div>

    <div class="col-xl-4 col-md-6 mb-4">
        <div class="card">
            <div class="card-body">
                <div class="card-title text-dark">Attachments</div>
                <% if (project.user._id.toString() == user._id) { %>
                    <form method="POST" action="/fileattachments/<%= project._id %>" enctype="multipart/form-data">
                        <div class="form-outline mb-2">
                            <label class="form-label" for="customFile">Upload attachments</label>
                            <input type="file" name="file" class="form-control" id="customFile" required/>
                        </div>
                        <button type="submit" class="btn btn-sm btn-success mb-2">Upload</button>
                    </form>
                <% } %>
                <div class="row no-gutters align-items-center">
                    <% if (fileAttachments.length > 0) { %>
                        <table class="table">
                            <thead>
                                <tr>
                                    <th scope="col">File</th>
                                    <th scope="col">Options</th>
                                </tr>
                            </thead>
                            <tbody>
                                <% for (let i = 0; i < fileAttachments.length; i++) { %>
                                    <tr>
                                        <td><a href="/fileattachments/<%= project._id %>?file=<%= fileAttachments[i].file %>"> File <%= i + 1 %></td>

                                        <% if (fileAttachments[i].user._id.toString() == user._id) { %>
                                            <td>

                                                <form action="/fileattachments/<%= fileAttachments[i]._id %>" method="POST">
                                                    <input type="hidden" name="_method" value="DELETE">
                                                    <a class="btn btn-sm btn-danger ml-2" href="#" data-toggle="modal" data-target="#deleteFileModal"><i class="fa fa-trash"></i></a>

                                                    <div class="modal fade" id="deleteFileModal" tabindex="-1" role="dialog" aria-labelledby="deleteFileModalLabel"
                                                        aria-hidden="true">
                                                        <div class="modal-dialog" role="document">
                                                            <div class="modal-content">
                                                                <div class="modal-header">
                                                                    <h5 class="modal-title" id="deleteFileModalLabel">Delete this file?</h5>
                                                                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                                                        <span aria-hidden="true">×</span>
                                                                    </button>
                                                                </div>
                                                                <div class="modal-footer">
                                                                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                                                                    <button type="submit" class="btn btn-primary">Delete</button>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>

                                                </form>

                                            </td>
                                        <% } %>
                                    </tr>
                                <% } %>
                            </tbody>
                        </table>
                    <% } else { %>
                        Empty!
                    <% } %>
                </div>
            </div>
        </div>
    </div>
</div>
<a href="/issues/<%= project._id %>/new" class="btn btn-primary btn-icon-split mb-4">
    <span class="icon text-white-40">
        <i class="fas fa-plus"></i>
    </span>
    <span class="text">
        New Issue
    </span>
</a>

<!-- DataTales Example -->
<div class="card shadow mb-4">
    <div class="card-header py-3">
        <h6 class="m-0 font-weight-bold text-primary">Issues</h6>
    </div>
    <div class="card-body">
        <% if (issues.length > 0) { %>
            <div class="table-responsive">
                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Issues</th>
                            <th>Priority</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>Issues</th>
                            <th>Priority</th>
                            <th>Status</th>
                        </tr>
                    </tfoot>
                    <tbody>
                        <% for (let i = 0; i < issues.length; i++) { %>
                            <tr>
                                <td>
                                    <a href="/issues/<%= project._id %>/details/<%= issues[i]._id %>/1" class="text-dark"> <%= issues[i].title %>
                                    <% if (issues[i].type == 'Bug') { %>
                                        <button class="btn btn-sm btn-danger btn-round"><%= issues[i].type %></button>
                                    <% } if (issues[i].type == 'Feature') { %>
                                        <button class="btn btn-sm btn-warning btn-round"><%= issues[i].type %></button>

                                    <% } if (issues[i].type == 'Discussion') { %>
                                        <button class="btn btn-sm btn-info btn-round"><%= issues[i].type %></button>
                                    <% } %>
                                    </a>
                                    <p class="text-sm">Created <%= moment(issues[i].createdAt).fromNow() %> by <a href="/users/<%= issues[i].user._id %>"><%= issues[i].user.username %></a></p>
                                </td>
                                <td>
                                    <% if (issues[i].priority == 'None') { %>
                                        <button class="btn btn-sm btn-info btn-round"><%= issues[i].priority %></button>
                                    <% } if (issues[i].priority == 'Low') { %>
                                        <button class="btn btn-sm btn-success btn-round"><%= issues[i].priority %></button>
                                    <% } if (issues[i].priority == 'Medium') { %>
                                        <button class="btn btn-sm btn-warning btn-round"><%= issues[i].priority %></button>
                                    <% } if (issues[i].priority == 'High') { %>
                                        <button class="btn btn-sm btn-danger btn-round"><%= issues[i].priority %></button>
                                    <% } %>
                                </td>
                                <td>
                                    <% if (issues[i].status == 'Open') { %>
                                        <button class="btn btn-sm btn-success btn-icon-split">
                                            <span class="icon text-white-40">
                                                <i class="fa fa-fw fa-cog" aria-hidden="true"></i>
                                            </span>
                                            <span class="text">
                                                <%= issues[i].status %>
                                            </span>
                                        </button>
                                </td>
                            <% } if (issues[i].status == 'Closed') { %>
                                <button class="btn btn-sm btn-danger btn-icon-split">
                                    <span class="icon text-white-40">
                                        <i class="fa fa-check-circle" aria-hidden="true"></i>
                                    </span>
                                    <span class="text">
                                        <%= issues[i].status %>
                                    </span>
                                </button></td>
                        <% } %>
                            </tr>
                        <% } %>
                    </tbody>
                </table>
            </div>
        <% } else { %>
            This project have no issues!
        <% } %>
    </div>
</div>
