<! --
/**
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
* Copyright (C) 2021 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program.  If not, see http://www.gnu.org/licenses.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Supercharged by SuiteCRM".
*/
-->
<div class="d-flex align-items-center">
    <ng-container *ngIf="initModule">
        <div class="flex-grow-1 w-100 mr-1">
            <p-dropdown
                #tag
                [options]="options"
                [(ngModel)]="selectedValue"
                [optionLabel]="getRelateFieldName()"
                (onChange)="onAdd($event.value)"
                (onLazyLoad)="onFilter()"
                (onShow)="focusFilterInput()"
                (onHide)="resetFunction(tag.options)"
                [emptyMessage]="emptyFilterLabel"
                [emptyFilterMessage]="emptyFilterLabel"
                [placeholder]="placeholderLabel"
                [autoOptionFocus]="false"
                [autofocusFilter]="false"
                [focusOnHover] = "true"
                [filter]="true"
                [lazy]="true"
                [dataKey]="'id'"
                [filterBy]="getRelateFieldName()"
                [showClear]="true"
                (onClear)="onClear($event)"
                [styleClass]="'w-100 ' + getInvalidClass()"
            >
                <ng-template pTemplate="dropdownicon">
                    <scrm-image image="down_carret"></scrm-image>
                </ng-template>
                <ng-template pTemplate="filter" let-options="options">

                    <div class="p-dropdown-filter-container" (click)="$event.stopPropagation()">
                        <input #dropdownFilterInput
                               type="text"
                               pInputText
                               autocomplete="off"
                               class="p-dropdown-filter p-component"
                               [(ngModel)]="filterValue"
                               (keyup)="onFilterInput($event)"
                               tabindex="0">
                        <scrm-image image="search" class="p-element p-dropdown-filter-search-icon"></scrm-image>
                    </div>

                </ng-template>
            </p-dropdown>
        </div>
        <div>
            <scrm-button [config]="selectButton">
            </scrm-button>
        </div>
    </ng-container>
</div>

