<vdr-action-bar>
    <vdr-ab-right>
        <vdr-action-bar-items locationId="promotion-list"></vdr-action-bar-items>
        <a class="btn btn-primary"
           *vdrIfPermissions="'CreatePromotion'"
           [routerLink]="['./create']">
            <clr-icon shape="plus"></clr-icon>
            {{ 'marketing.create-new-promotion' | 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>{{ 'common.name' | translate }}</vdr-dt-column>
    <vdr-dt-column>{{ 'marketing.coupon-code' | translate }}</vdr-dt-column>
    <vdr-dt-column>{{ 'marketing.starts-at' | translate }}</vdr-dt-column>
    <vdr-dt-column>{{ 'marketing.ends-at' | translate }}</vdr-dt-column>
    <vdr-dt-column></vdr-dt-column>
    <vdr-dt-column></vdr-dt-column>
    <vdr-dt-column></vdr-dt-column>
    <ng-template let-promotion="item">
        <td class="left align-middle">{{ promotion.name }}</td>
        <td class="left align-middle">
            <vdr-chip *ngIf="promotion.couponCode">
                {{ promotion.couponCode }}
            </vdr-chip>
        </td>
        <td class="left align-middle">{{ promotion.startsAt | date: 'longDate' }}</td>
        <td class="left align-middle">{{ promotion.endsAt | date: 'longDate' }}</td>
        <td class="align-middle">
            <vdr-chip *ngIf="!promotion.enabled">{{ 'common.disabled' | translate }}</vdr-chip>
        </td>
        <td class="right align-middle">
            <vdr-table-row-action
                iconShape="edit"
                [label]="'common.edit' | translate"
                [linkTo]="['./', promotion.id]"
            ></vdr-table-row-action>
        </td>
        <td class="right align-middle">
            <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)="deletePromotion(promotion.id)"
                        [disabled]="!('DeletePromotion' | 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>
