<vdr-action-bar>
    <vdr-ab-left>
        <input
            type="text"
            name="emailSearchTerm"
            [formControl]="searchTerm"
            [placeholder]="'customer.search-customers-by-email-last-name-postal-code' | translate"
            class="search-input"
        />
    </vdr-ab-left>
    <vdr-ab-right>
        <vdr-action-bar-items locationId="customer-list"></vdr-action-bar-items>
        <a class="btn btn-primary" [routerLink]="['./create']" *vdrIfPermissions="'CreateCustomer'">
            <clr-icon shape="plus"></clr-icon>
            {{ 'customer.create-new-customer' | translate }}
        </a>
    </vdr-ab-right>
</vdr-action-bar>

<vdr-data-table
    [items]="items$ | async"
    [itemsPerPage]="itemsPerPage$ | async"
    [totalItems]="totalItems$ | async"
    [currentPage]="currentPage$ | async"
    (pageChange)="setPageNumber($event)"
    (itemsPerPageChange)="setItemsPerPage($event)"
>
    <vdr-dt-column [expand]="true">{{ 'customer.name' | translate }}</vdr-dt-column>
    <vdr-dt-column [expand]="true">{{ 'customer.email-address' | translate }}</vdr-dt-column>
    <vdr-dt-column>{{ 'customer.customer-type' | translate }}</vdr-dt-column>
    <vdr-dt-column></vdr-dt-column>
    <vdr-dt-column></vdr-dt-column>
    <ng-template let-customer="item">
        <td class="left align-middle">
            {{ customer.title }} {{ customer.firstName }} {{ customer.lastName }}
        </td>
        <td class="left align-middle">{{ customer.emailAddress }}</td>
        <td class="left align-middle">
            <vdr-customer-status-label [customer]="customer"></vdr-customer-status-label>
        </td>
        <td class="right align-middle">
            <vdr-table-row-action
                iconShape="edit"
                [label]="'common.edit' | translate"
                [linkTo]="['./', customer.id]"
            ></vdr-table-row-action>
        </td>
        <td>
            <vdr-dropdown>
                <button type="button" class="btn btn-link btn-sm" vdrDropdownTrigger>
                    {{ 'common.actions' | translate }}
                    <clr-icon shape="caret down"></clr-icon>
                </button>
                <vdr-dropdown-menu vdrPosition="bottom-right">
                    <button
                        type="button"
                        class="delete-button"
                        (click)="deleteCustomer(customer)"
                        [disabled]="!('DeleteCustomer' | hasPermission)"
                        vdrDropdownItem
                    >
                        <clr-icon shape="trash" class="is-danger"></clr-icon>
                        {{ 'common.delete' | translate }}
                    </button>
                </vdr-dropdown-menu>
            </vdr-dropdown>
        </td>
    </ng-template>
</vdr-data-table>
