<vdr-action-bar>
    <vdr-ab-left>
        <input
            type="text"
            name="searchTerm"
            [formControl]="searchTerm"
            [placeholder]="'settings.search-country-by-name' | translate"
            class="clr-input search-input"
        />
    </vdr-ab-left>

    <vdr-ab-right>
        <vdr-action-bar-items locationId="country-list"></vdr-action-bar-items>
        <a class="btn btn-primary" [routerLink]="['./create']" *vdrIfPermissions="'CreateSettings'">
            <clr-icon shape="plus"></clr-icon>
            {{ 'settings.create-new-country' | translate }}
        </a>
    </vdr-ab-right>
</vdr-action-bar>

<vdr-data-table
    [items]="countriesWithZones$ | async"
>
    <vdr-dt-column>{{ 'common.code' | translate }}</vdr-dt-column>
    <vdr-dt-column [expand]="true">{{ 'common.name' | translate }}</vdr-dt-column>
    <vdr-dt-column>{{ 'settings.zone' | translate }}</vdr-dt-column>
    <vdr-dt-column>{{ 'common.enabled' | translate }}</vdr-dt-column>
    <vdr-dt-column></vdr-dt-column>
    <vdr-dt-column></vdr-dt-column>
    <ng-template let-country="item">
        <td class="left align-middle">{{ country.code }}</td>
        <td class="left align-middle">{{ country.name }}</td>
        <td class="left align-middle">
            <a [routerLink]="['/settings', 'zones', { contents: zone.id }]" *ngFor="let zone of country.zones">
            <vdr-chip [colorFrom]="zone.name">{{ zone.name }}</vdr-chip>
            </a>
        </td>
        <td class="left align-middle">
            <clr-icon
                [class.is-success]="country.enabled"
                [attr.shape]="country.enabled ? 'check' : 'times'"
            ></clr-icon>
        </td>
        <td class="right align-middle">
            <vdr-table-row-action
                iconShape="edit"
                [label]="'common.edit' | translate"
                [linkTo]="['./', country.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)="deleteCountry(country.id)"
                        vdrDropdownItem
                        [disabled]="!('DeleteSettings' | hasPermission)"
                    >
                        <clr-icon shape="trash" class="is-danger"></clr-icon>
                        {{ 'common.delete' | translate }}
                    </button>
                </vdr-dropdown-menu>
            </vdr-dropdown>
        </td>
    </ng-template>
</vdr-data-table>
