<div id="faqQuestions">
    <div id="content">
        <div class="menubar fixed">
            <div class="sidebar-toggler visible-xs">
                <i class="ion-navicon"></i>
            </div>

            <div class="page-title">FAQ Questions</div>
            <form class="search">
                <!--<input class="gwt-TextBox" placeholder="Search questions (question, answer)..." type="text">-->
                <input #inputstring (keyup.enter)="filterBySearch(inputstring.value)" placeholder="Search questions (question, answer)..." type="text"/>
                <input class="btn" type="submit">
            </form>
            <a (click)="showModal()" class="btn btn-success pull-right"><i></i> New Question </a>
        </div>

        <div class="content-wrapper" id="contentWrapper">
            <div>
                <div class="contentPanel">
                    <div [hidden]="!errorMessage" class="alert alert-danger" aria-hidden="true">
                        {{errorMessage}}
                    </div>
                    <div [hidden]="!successMessage" class="alert alert-success"  aria-hidden="true">
                        {{successMessage}}
                    </div>
                    <div class="alert" style="display: none;" aria-hidden="true"><span></span><span></span><span></span></div>
                    <div class="row page-controls">
                        <div class="col-md-12 filters marginBottom20">
                            <div class="links form-group form-inline">
                                <div class="gwt-Label filterLabel">Filter by topic:</div>
                                <select class="input-xxlarge form-control" (change)="filterByTopic($event)">
                                    <option value="">-- none selected --</option>
                                    <option *ngFor="let topic of topics" value="{{topic._id}}">{{topic.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-12 filters">
                            <div class="links">
                                <div class="gwt-Label filterLabel">Filter questions:</div>
                                    <a [ngClass]="{'active' : filters.active==null}" (click)="displayAllQuestions()">
                                        All Questions ({{counter.all}})
                                    </a>
                                    <a [ngClass]="{'active' : filters.active==true}" (click)="displayActiveQuestions()">
                                        Active ({{counter.active}})
                                    </a>
                                    <a [ngClass]="{'active' : filters.active==false}" (click)="displayInactiveQuestions()">
                                        Inactive ({{counter.inactive}})
                                    </a>
                                </div>
                            <div class="show-options">
                                <div class="btn-group"><a href="javascript:;" class="btn dropdown-toggle"
                                                          data-toggle="dropdown"><i></i> Bulk Actions <span
                                        class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a (click)="toggleQuestion(true,getSelectedQuestions())"><i></i> Activate </a></li>
                                        <li><a (click)="toggleQuestion(false,getSelectedQuestions())"><i></i> Deactivate </a></li>
                                        <li><a (click)="confirmDeleteSelectedQuestions()"><i></i> Delete </a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div>
                        <div class="gwt-HTML">
                            <div class="row users-list">
                                <div class="col-md-12">
                                    <div class="row headers">
                                        <div class="col-sm-1 header select-users"><input id="allQuestionsCheckbox" [checked]="checkboxAll" type="checkbox" (change)="toggleCheckBoxes($event)">
                                        </div>
                                        <div class="col-sm-1 header hidden-xs"><label><a href="#">Date</a></label></div>
                                        <div class="col-sm-2 header hidden-xs"><label><a href="#">Question</a></label></div>
                                        <div class="col-sm-3 header hidden-xs"><label><a href="#">Answer</a></label></div>
                                        <div class="col-sm-1 header hidden-xs"><label><a href="#">Topics</a></label></div>
                                        <div class="col-sm-1 header hidden-xs"><label><a href="#">Weight</a></label></div>
                                        <div class="col-sm-1 header hidden-xs"><label><a href="#">Hit Count</a></label></div>
                                        <div class="col-sm-1 header hidden-xs"><label><a href="#">Active</a></label></div>
                                        <div class="col-sm-1 header hidden-xs"><label><a href="#">Actions</a></label></div>
                                    </div>

                                    <ng-template [ngIf]="questionsCheckboxes && questionsCheckboxes.length>0">
                                        <div *ngFor="let check of questionsCheckboxes; let i=index" class="row user">
                                            <div class="col-sm-1 avatar"><input id="{{check.question._id}}" class="checkBox" type="checkbox"
                                                                                name="questionscb[]" value="{{check.question._id}}" [(ngModel)]="check.checked">
                                            </div>
                                            <div class="col-sm-1">
                                                <div class="date" href="#">{{check.question.date | date:'yyyy-MM-dd'}}</div>
                                            </div>
                                            <div class="col-sm-2">
                                                <div class="name" href="#">{{check.question.question}}</div>
                                            </div>
                                            <div class="col-sm-3">
                                                <div class="description" href="#">{{check.question.answer}}
                                                </div>
                                            </div>
                                            <div class="col-sm-1">
                                                {{getNames(check.question).join(', ')}}
                                                <!--<div class="topics" href="#">{{check.question.topics}}</div>-->
                                                <!--<span *ngFor="let topic of check.question.topics" class="label label-primary">{{topic.name}}</span>-->
                                            </div>
                                            <div class="col-sm-1">
                                                <div class="weight" href="#">{{check.question.weight}}</div>
                                            </div>
                                            <div class="col-sm-1">
                                                <div class="hitCount" href="#">{{check.question.hitCount}}</div>
                                            </div>
                                            <div class="col-sm-1">
                                                <div *ngIf="check.question.isActive" class="activated" >
                                                    <input (click)="toggleQuestion(false,[check.question._id])" class="deactivate" src="imgs/check-icon.png" title="Deactivate" width="20" type="image" height="20">
                                                </div>
                                                <div *ngIf="!check.question.isActive" class="activated" >
                                                    <input (click)="toggleQuestion(true,[check.question._id])" class="deactivate" src="imgs/x-icon.png" title="Activate" width="20" type="image" height="20">
                                                </div>
                                            </div>
                                            <!--<div class="col-sm-1">-->
                                                <!--<bSwitch [switch-on-text]="'A'" [switch-off-text]="'I'"-->
                                                         <!--[switch-label-text]="''" [(ngModel)]="check.question.isActive"-->
                                                         <!--[switch-on-color]="'mySuccess'" [switch-off-color]="'default'"-->
                                                         <!--[switch-size]="'small'"  [switch-handle-width]="22"-->
                                                         <!--(onChangeState)="toggleQuestion($event.currentValue,[check.question._id])"></bSwitch>-->
                                            <!--</div>-->
                                            <div class="col-sm-1">
                                                <div class="actions" href="#">
                                                    <input title="Edit" src="imgs/icn_edit.png" class="edit" type="image" (click)="editQuestion(i)">
                                                    <input title="Delete" src="imgs/icn_trash.png" class="delete" type="image" (click)="confirmDeleteQuestion(check.question._id)">
                                                </div>
                                            </div>
                                        </div>
                                    </ng-template>
                                    <div *ngIf="questionsCheckboxes.length==0" class="col-md-12">
                                        <div class="alert alert-warning">No questions found</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<modal-form #saveModal [saveText]="'Save'" [titleText]="'Add a new Question'" [formGroup]="formGroup" [type]="'question'"
            [isModalShown]="isModalShown" (emmitObject)="questionSavedSuccessfully($event)" (emmitError)="handleError($event)">
    <questions-form [group]="formGroup" [availableTopics]="topics"></questions-form>
</modal-form>

<modal-form #updateModal [saveText]="'Update'" [titleText]="'Update Question'" [formGroup]="formGroup" [type]="'question'"
            [isModalShown]="isModalShown" (emmitObject)="questionUpdatedSuccessfully($event)" (emmitError)="handleError($event)">
    <questions-form [group]="formGroup" [availableTopics]="topics"></questions-form>
</modal-form>

<delete-confirmation-dialog #deleteConfirmationModal [isModalShown]="isModalShown" (emmitObject)="confirmedDeleteQuestions($event)">
    Are you sure you want to delete the selected question(s)?
</delete-confirmation-dialog>
