<div class="app-sidebar card" id="rightMenu">
    <!-- Details View of Contact -->
    <div *ngIf='selectedContact!=null && !editable'>
        <img src="assets/images/background/profile-bg.jpg" class="card-img" />
        <div class="card-img-overlay">
            <div class="d-flex justify-content-end">
                <a href="javascript:void(0)" class="btn bg-white text-info py-1 px-2 link" placement="bottom"
                    ngbTooltip="Edit Contact" (click)='editContact()'>
                    <i-feather name="edit-2" class="feather-sm"></i-feather>
                </a>
                <a href="javascript:void(0)" class="btn bg-white text-danger py-1 px-2 link ml-3"
                    (click)="closeRightMenu()">
                    <i-feather name="x" class="feather-sm"></i-feather>
                </a>
            </div>
        </div>
        <div class="text-center">
            <img [src]='selectedContact.Imagepath' class="rounded-circle mt-n5 shadow" alt="Cinque Terre" height="100px"
                width="100px">
            <h4 class="text-dark mt-2 mb-0">{{selectedContact.Name}}</h4>
            <span class="badge badge-info badge-pill font-medium px-2">{{selectedContact.Tags}}</span>
        </div>
        <div class="position-relative" [perfectScrollbar]="config2" style="height: 350px;">

            <div class="d-flex align-items-center py-2 px-3 border-bottom"
                *ngIf='selectedContact.Jobtitle !=undefined && selectedContact.Company!=undefined'>
                <button class="btn btn-success btn-circle mr-2 d-flex align-items-center btn-sm justify-content-center">
                    <i-feather name="Briefcase" class="feather-sm"></i-feather>
                </button>
                <div class="text-dark font-medium">{{selectedContact.Jobtitle}} , {{selectedContact.Company}}</div>
            </div>

            <div class="d-flex align-items-center py-2 px-3 border-bottom" *ngIf='selectedContact.Email !=undefined'>
                <button class="btn btn-danger btn-circle mr-2 d-flex align-items-center btn-sm justify-content-center">
                    <i-feather name="Mail" class="feather-sm"></i-feather>
                </button>
                <div class="text-dark font-medium">{{selectedContact.Email}}</div>
            </div>

            <div class="d-flex align-items-center py-2 px-3 border-bottom"
                *ngIf='selectedContact.Phonenumber !=undefined'>
                <button class="btn btn-warning btn-circle mr-2 d-flex align-items-center btn-sm justify-content-center">
                    <i-feather name="Phone" class="feather-sm"></i-feather>
                </button>
                <div class="text-dark font-medium">{{selectedContact.Phonenumber}}</div>
            </div>
            <div class="d-flex align-items-center py-2 px-3 border-bottom" *ngIf='selectedContact.Address !=undefined'>
                <button class="btn btn-primary btn-circle mr-2 d-flex align-items-center btn-sm justify-content-center">
                    <i-feather name="Map" class="feather-sm"></i-feather>
                </button>
                <div class="text-dark font-medium">{{selectedContact.Address}}</div>
            </div>
            <div class="d-flex align-items-center py-2 px-3 border-bottom" *ngIf='selectedContact.DOB !=undefined'>
                <button class="btn btn-dark btn-circle mr-2 d-flex align-items-center btn-sm justify-content-center">
                    <i-feather name="Gift" class="feather-sm"></i-feather>
                </button>
                <div class="text-dark font-medium">{{selectedContact.DOB | date}}</div>
            </div>
            <div class="d-flex align-items-start py-2 px-3 border-bottom"
                *ngIf='selectedContact.Description !=undefined'>
                <button class="btn btn-info btn-circle mr-2 d-flex align-items-center btn-sm justify-content-center">
                    <i-feather name="file-text" class="feather-sm"></i-feather>
                </button>
                <div class="text-dark font-medium">{{selectedContact.Description}}</div>
            </div>

        </div>
    </div>
    <!-- Edit View of Contact -->
    <div *ngIf='selectedContact!=null && editable'>
        <img src="assets/images/background/profile-bg.jpg" class="card-img" />
        <div class="card-img-overlay" style="height: 95px;">
            <div class="d-flex justify-content-end">

                <a href="javascript:void(0)" class="btn bg-white text-success py-1 px-2 link" placement="bottom"
                    ngbTooltip="Save Contact" (click)='saveClick(selectedContact.Id)'>
                    <i-feather name="save" class="feather-sm"></i-feather>
                </a>
                <a href="javascript:void(0)" class="btn bg-white text-danger py-1 px-2 link ml-3" placement="bottom"
                    ngbTooltip="Delete Contact" (click)='deleteClick(selectedContact.Id)'>
                    <i-feather name="trash-2" class="feather-sm"></i-feather>
                </a>
                <a href="javascript:void(0)" class="btn bg-white text-danger py-1 px-2 link ml-3"
                    (click)='cancelClick()'>
                    <i-feather name="x" class="feather-sm"></i-feather>
                </a>
            </div>
        </div>
        <!-- Editable Form here -->
        <div>
            <form>
                <div class="form-group mt-n5 text-center">
                    <input type="file" style="display: none;" (change)='preview(filevar.files)' #filevar>
                    <img [src]='selectedContactCopy.Imagepath' class="rounded-circle image" alt="" height="100px"
                        width="100px" (click)='filevar.click()'>
                    <div class="text-center">
                        <span class="font-weight-normal">Change Image</span>
                    </div>
                </div>
                <div class="p-3 position-relative" [perfectScrollbar]="config" style="height: 350px;">
                    <div class="row">
                        <div class="col-12 form-group">
                            <label class="mb-0 text-dark">Name</label>
                            <input type="text" name="name" [(ngModel)]="selectedContactCopy.Name" class="form-control">
                        </div>
                        <div class="col-12 form-group">
                            <label class="mb-0 text-dark">Job Title</label>
                            <input type="text" name="Jobtitle" [(ngModel)]="selectedContactCopy.Jobtitle"
                                class="form-control">
                        </div>
                        <div class="col-12 form-group">
                            <label class="mb-0 text-dark">Company name</label>
                            <input type="text" name="company" [(ngModel)]="selectedContactCopy.Company"
                                class="form-control">
                        </div>
                        <div class="col-12 form-group">
                            <label class="mb-0 text-dark">Email</label>
                            <input type="text" name="email" [(ngModel)]="selectedContactCopy.Email"
                                class="form-control">
                        </div>
                        <div class="col-12 form-group">
                            <label class="mb-0 text-dark">Phone Number</label>
                            <input type="text" name="phone" [(ngModel)]="selectedContactCopy.Phonenumber"
                                class="form-control">
                        </div>
                        <div class="col-12 form-group">
                            <label class="mb-0 text-dark">Location</label>
                            <input name="address" type="text" [(ngModel)]="selectedContactCopy.Address"
                                class="form-control">
                        </div>
                        <div class="col-12 form-group">
                            <label class="mb-0 text-dark">Birthdate</label>
                            <input name="dob" type="date" [(ngModel)]="selectedContactCopy.DOB" class="form-control">
                        </div>
                        <div class="col-12 form-group">
                            <label class="mb-0 text-dark">Description</label>
                            <textarea name="description" type="text" [(ngModel)]="selectedContactCopy.Description"
                                class="form-control"></textarea>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <!-- end editable form here -->
    </div>

</div>

<!-- -------------------------------------------------------------------- -->
<!-- Contact Listing -->
<!-- -------------------------------------------------------------------- -->
<div class="d-md-flex align-items-center bg-white p-3">
    <h3 class="mb-0">Contact List</h3>
    <div class="ml-auto mt-3 mt-md-0">
        <!-- Add Contact -->
        <button type="button" class="btn btn-cyan rounded-pill py-2" (click)='addContact()'><i
                class="fas fa-plus  font-14 mr-1 text-white"></i>
            <span class="ml-1 text-white font-weight-bold">Add Contact</span>
        </button>
    </div>
</div>
<div class="d-md-flex align-items-center border-top bg-white p-3">
    <div>
        <input type="text" placeholder="Search by Name" class="form-control rounded-pill" [(ngModel)]='searchTerm'>
    </div>

    <div class="ml-auto mt-3 mt-md-0">
        <!-- No. of  Contacts-->
        <a href="javascript:void(0)" class="d-flex align-items-center p-2 rounded-pill bg-light">

            <h5 class="mb-0 mr-1 text-dark font-weight-bold font-14"> Total Contacts
            </h5>
            <span *ngIf='contactFilter'
                class="badge badge-danger badge-pill px-3 font-weight-bold font-14">{{contactFilter.length}}</span>
        </a>
    </div>
</div>


<div class="table-responsive">
    <table class="table bg-white table-hover align-middle mb-0 no-wrap">
        <thead>
            <tr>
                <th>Name</th>
                <th scope="col">Email</th>
                <th scope="col">Phone Number</th>
                <th scope="col">Job title & company</th>
                <th scope="col">Action</th>
            </tr>
        </thead>
        <tbody>
            <tr *ngFor="let co of contactFilter|slice: (page-1) * pageSize : (page-1) * pageSize + pageSize">
                <td>

                    <img [src]='co.Imagepath' class="rounded-circle mr-2" alt="" height="45" width="45">
                    <span class="text-dark font-medium font-16">{{ co.Name }}</span>
                </td>
                <td class="align-middle">
                    <span>
                        <span class="badge badge-light text-dark rounded-pill font-16 mr-1">
                            <i-feather name="Mail" class="feather-sm"></i-feather>
                        </span>
                        {{ co.Email }}
                    </span>
                </td>
                <td class="align-middle">
                    <span>
                        <span class="badge badge-light text-dark rounded-pill font-16 mr-1">
                            <i-feather name="phone" class="feather-sm"></i-feather>
                        </span>
                        {{ co.Phonenumber }}
                    </span>
                </td>
                <td class="align-middle position-relative">
                    <span>
                        <span class="badge badge-light text-dark rounded-pill font-16 mr-1">
                            <i-feather name="Briefcase" class="feather-sm"></i-feather>
                        </span>
                        {{ co.Jobtitle}} , {{co.Company}}
                    </span>
                </td>
                <td class="align-middle">
                    <a href="javascript:void(0)" class="link font-16 mr-2 font-medium" (click)='tableRowClicked(co)'>
                        <i-feather name="edit-3" class="feather-sm"></i-feather>
                    </a>
                    <a href="javascript:void(0)" class="link font-16 mr-2 font-weight-bold" (click)='viewClicked(co)'>
                        <i-feather name="eye" class="feather-sm"></i-feather>
                    </a>
                    <a href="javascript:void(0)" class="link font-16 font-medium" (click)='deleteClick(co.Id)'>
                        <i-feather name="trash-2" class="feather-sm"></i-feather>
                    </a>

                </td>
            </tr>
        </tbody>
    </table>
</div>


<div class="d-flex justify-content-center p-2 pt-3 bg-white border-top">
    <ngb-pagination [collectionSize]="collectionSize" [(page)]="page" [pageSize]="pageSize">
    </ngb-pagination>
</div>