<!--
~ Copyright (C) 2023 StApps
~ This program is free software: you can redistribute it and/or modify it
~ under the terms of the GNU General Public License as published by the Free
~ Software Foundation, version 3.
~
~ 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 General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along with
~ this program. If not, see <https://www.gnu.org/licenses/>.
-->

<ion-card>
  <ion-card-header>{{ 'data.detail.offers.TITLE' | translate | titlecase }}</ion-card-header>
  <ion-card-content>
    @for (offer of offers; track offer) {
      <div>
        <ion-grid>
          <ion-row>
            @if (offer.inPlace) {
              <ion-col>
                <ion-icon name="pin_drop"></ion-icon>
                <a [routerLink]="['/data-detail', offer.inPlace.uid]">
                  {{ 'name' | thingTranslate: offer.inPlace }}
                </a>
              </ion-col>
            }
            @if (offer.availabilityRange) {
              <ion-col>
                @if (offer.availabilityRange.gt ? offer.availabilityRange.gt : offer.availabilityRange.gte) {
                  <span>
                    {{
                      (offer.availabilityRange.gt ? offer.availabilityRange.gt : offer.availabilityRange.gte)
                        | amDateFormat: 'll'
                    }}
                  </span>
                }
              </ion-col>
            }
          </ion-row>
        </ion-grid>
        @if (offer.prices && offer.availability !== 'out of stock') {
          <ion-grid>
            @for (group of $any(offer.prices) | keyvalue; track group) {
              <ion-row>
                @if (group.key !== 'default') {
                  <ion-col>{{ 'data.detail.offers.' + group.key | translate }} </ion-col>
                  <ion-col width-20 text-right>
                    <p>{{ $any(group.value) | currency: 'EUR' : 'symbol' : undefined : 'de' }}</p>
                  </ion-col>
                }
              </ion-row>
            }
          </ion-grid>
        }
        @if (offer.availability === 'out of stock') {
          <ion-grid>
            <ion-row>
              <ion-col></ion-col>
              <ion-col width-20 text-right>
                <ion-text color="danger">
                  <p>{{ 'data.detail.offers.sold_out' | translate }}</p>
                </ion-text>
              </ion-col>
            </ion-row>
          </ion-grid>
        }
      </div>
    }
  </ion-card-content>
</ion-card>
