<template>
  <strong
    style="
      display: inline-block;
      width: 100%;
      font-size: 10pt;
      margin-bottom: 10px;
      text-align: center;
    ">
    MİLLİ PİYANGO İDARESİ GENEL MÜDÜRLÜĞÜ
    <br />
    Bahisler ve Oyunlar Dairesi Başkanlığına
  </strong>
  <br />
  <strong style="font-size: 10pt; margin-bottom: 10px">
    PİYANGO ID: {{ piyangoStore.lotteryData.piyangoId }}
  </strong>
  <br />
  <table
    cellspacing="0"
    class="table-no-line"
    data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayoutNoLine'}">
    <tbody>
      <tr>
        <td colspan="2">
          <strong style="font-size: 10pt; margin-bottom: 10px">
            1- Piyangoyu Düzenleyenin:
          </strong>
        </td>
      </tr>
    </tbody>
  </table>
  <template v-if="loaded">
    <table
      cellspacing="0"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayout'}"
      style="margin-bottom: 10px; font-size: 10pt">
      <tbody>
        <template v-if="piyangoStore.duzenleyenData.basvuruTipId === 18">
          <tr>
            <td colspan="2">
              <strong>Adı/Soyadı:</strong>
              {{ piyangoStore.duzenleyenData.gercekAdi }}
              {{ piyangoStore.duzenleyenData.gercekSoyadi }}
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <strong>Ticari Ünvanı:</strong>
              {{ piyangoStore.duzenleyenData.gercekTicariUnvan }}
            </td>
          </tr>
        </template>
        <template v-if="piyangoStore.duzenleyenData.basvuruTipId === 21">
          <tr>
            <td colspan="2">
              <strong>Ünvanı:</strong>
              {{ piyangoStore.duzenleyenData.tuzelUnvan }}
            </td>
          </tr>
        </template>

        <template v-if="piyangoStore.duzenleyenData.basvuruTipId === 22">
          <tr>
            <td colspan="2">
              <strong>Ünvanı:</strong>
              {{ piyangoStore.duzenleyenData.dernekUnvan }}
            </td>
          </tr>
        </template>

        <template v-if="piyangoStore.duzenleyenData.basvuruTipId === 26">
          <tr>
            <td colspan="2">
              <strong>Ünvanı:</strong>
              {{ piyangoStore.duzenleyenData.kamuUnvan }}
            </td>
          </tr>
        </template>

        <tr>
          <td colspan="2">
            <strong>Adresi:</strong>
            {{ piyangoStore.duzenleyenData.adres }}
          </td>
        </tr>

        <template v-if="piyangoStore.duzenleyenData.basvuruTipId === 18">
          <tr>
            <td colspan="2">
              <strong>Bağlı Bulunduğu Oda Kayıt No/ Ticaret Sicil No:</strong>
              {{ piyangoStore.duzenleyenData.gercekOdaKayitNo }}
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <strong>Bağlı Bulunduğu Vergi Dairesi/Numarası:</strong>
              {{ piyangoStore.duzenleyenData.gercekVergiDairesi }} /
              {{ piyangoStore.duzenleyenData.gercekVergiNo }}
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <strong>TCKN:</strong>
              {{ piyangoStore.duzenleyenData.gercekTCKN }}
            </td>
          </tr>
        </template>

        <template v-if="piyangoStore.duzenleyenData.basvuruTipId === 21">
          <tr>
            <td colspan="2">
              <strong>Ticaret Sicil No:</strong>
              {{ piyangoStore.duzenleyenData.tuzelSicilNo }}
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <strong>Bağlı Bulunduğu Vergi Dairesi/Numarası:</strong>
              {{ piyangoStore.duzenleyenData.tuzelVergiDairesi }} /
              {{ piyangoStore.duzenleyenData.tuzelVergiNo }}
            </td>
          </tr>
        </template>

        <template v-if="piyangoStore.duzenleyenData.basvuruTipId === 22">
          <tr>
            <td colspan="2">
              <strong>Sicil No:</strong>
              {{ piyangoStore.duzenleyenData.dernekSicilNo }}
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <strong>Bağlı Bulunduğu Vergi Dairesi/Numarası:</strong>
              {{ piyangoStore.duzenleyenData.dernekVergiDairesi }} /
              {{ piyangoStore.duzenleyenData.dernekVergiNo }}
            </td>
          </tr>
        </template>
        <template v-if="piyangoStore.duzenleyenData.basvuruTipId === 26">
          <tr>
            <td colspan="2">
              <strong>Sicil No:</strong>
              {{ piyangoStore.duzenleyenData.kamuSicilNo }}
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <strong>Bağlı Bulunduğu Vergi Dairesi/Numarası:</strong>
              {{ piyangoStore.duzenleyenData.kamuVergiDairesi }} /
              {{ piyangoStore.duzenleyenData.kamuVergiNo }}
            </td>
          </tr>
        </template>
      </tbody>
    </table>

    <table
      cellspacing="0"
      class="table-no-line"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayoutNoLine'}"
      style="font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <strong class="title" style="font-size: 10pt; margin-bottom: 10px">
              2- Piyangonun Geçerli Olduğu Yerler:
            </strong>
          </td>
        </tr>
      </tbody>
    </table>
    <table
      cellspacing="0"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayout'}"
      style="margin-bottom: 10px; font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            {{
              piyangoStore.lotteryData.kampsamIlStrList.length ===
              globalDataStore.ilList.length
                ? 'Türkiye Geneli'
                : piyangoStore.lotterySelectedProvience
            }}
          </td>
        </tr>
      </tbody>
    </table>

    <table
      cellspacing="0"
      class="table-no-line"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayoutNoLine'}"
      style="font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <strong class="title" style="font-size: 10pt; margin-bottom: 10px">
              3- Basılacak Biletlerin:
            </strong>
          </td>
        </tr>
      </tbody>
    </table>

    <table
      data-pdfmake="{'widths': [ '31%', '23%' , '23%' , '23%' ],'layout':'pdfTableLayout'}"
      style="margin-bottom: 10px; font-size: 10pt">
      <thead>
        <tr>
          <th></th>
          <th>Başlangıç Numarası</th>
          <th>Bitiş Numarası</th>
          <th>Basılacak Adet</th>
        </tr>
      </thead>
      <tbody>
        <template v-for="(rakam, i) in piyangoYardimAmacliStore.yardimAmacliRakamlar">
          <tr
            v-if="
              piyangoYardimAmacliStore.piyangoYardimAmacliFormData[
                rakam.prefix + 'RakamBaslangic'
              ] !== null &&
              piyangoYardimAmacliStore.piyangoYardimAmacliFormData[
                rakam.prefix + 'RakamBitis'
              ] !== null &&
              piyangoYardimAmacliStore.piyangoYardimAmacliFormData[
                rakam.prefix + 'RakamAdet'
              ] !== null
            ">
            <td>{{ rakam.title }}</td>
            <td>
              {{
                globalStore.toTrLocale(
                  piyangoYardimAmacliStore.piyangoYardimAmacliFormData[
                    rakam.prefix + 'RakamBaslangic'
                  ]
                )
              }}
            </td>
            <td>
              {{
                globalStore.toTrLocale(
                  piyangoYardimAmacliStore.piyangoYardimAmacliFormData[
                    rakam.prefix + 'RakamBitis'
                  ]
                )
              }}
            </td>
            <td>
              {{
                globalStore.toTrLocale(
                  piyangoYardimAmacliStore.piyangoYardimAmacliFormData[
                    rakam.prefix + 'RakamAdet'
                  ]
                )
              }}
            </td>
          </tr>
        </template>
        <tr>
          <td colspan="3" style="text-align: right">
            <strong>Toplam Basılacak Bilet:</strong>
          </td>
          <td>{{ globalStore.toTrLocale(piyangoYardimAmacliStore.toplamBilet) }}</td>
        </tr>
        <tr>
          <td colspan="4">
            <strong>Bilet Satış Fiyatı:</strong>
            {{ piyangoYardimAmacliStore.piyangoYardimAmacliFormData.birimSatisFiyati }} ₺
          </td>
        </tr>
      </tbody>
    </table>

    <table
      cellspacing="0"
      class="table-no-line"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayoutNoLine'}"
      style="font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <strong class="title" style="font-size: 10pt; margin-bottom: 10px">
              4- Biletlerin Basımı
            </strong>
          </td>
        </tr>
      </tbody>
    </table>

    <table
      data-pdfmake="{'widths': [ '50%', '50%' ],'layout':'pdfTableLayout'}"
      style="margin-bottom: 10px; font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <strong>Basımevinin Adı:</strong>
            {{ piyangoYardimAmacliStore.piyangoYardimAmacliFormData.basimevi }}
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <strong>Basımevinin Adresi:</strong>
            {{ piyangoYardimAmacliStore.piyangoYardimAmacliFormData.basimeviAdresi }}
          </td>
        </tr>
      </tbody>
    </table>

    <table
      cellspacing="0"
      class="table-no-line"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayoutNoLine'}"
      style="font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <strong class="title" style="font-size: 10pt; margin-bottom: 10px">
              5- Çekiliş Tarih, Saati ve Adresi:
            </strong>
          </td>
        </tr>
      </tbody>
    </table>

    <table
      cellspacing="0"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayout'}"
      style="margin-bottom: 10px; font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <strong>Tarihi ve saati:</strong>
            {{
              dateStore.dateFormat({
                date: piyangoStore.lotteryData.cekilisTarihi,
                pattern: 'dd-mm-yy-t'
              })
            }}
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <strong>Açık adresi:</strong>
            {{
              piyangoStore.lotteryData.adres +
              ' ' +
              piyangoStore.lotteryData.il +
              ' ' +
              piyangoStore.lotteryData.ilce
            }}
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <strong>Ne şekilde yapılacağı:</strong>
            {{ piyangoStore.lotteryData.cekilisYontemi }}
            <div
              style="margin-top: 16px"
              v-if="piyangoStore.lotteryData.cekilisYontemiId === 1">
              <span v-for="txt in piyangoDataStore.fizikselYardimMessage">
                {{ txt }}
                <br />
              </span>
            </div>
          </td>
        </tr>
      </tbody>
    </table>

    <table
      cellspacing="0"
      class="table-no-line"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayoutNoLine'}"
      style="font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <strong class="title" style="font-size: 10pt; margin-bottom: 10px">
              6- İkramiye Kazananların İlanı:
            </strong>
          </td>
        </tr>
      </tbody>
    </table>

    <table
      cellspacing="0"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayout'}"
      style="margin-bottom: 10px; font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <strong>Adı:</strong>
            {{ piyangoStore.lotteryData.ilanEdilecekGazete }}
          </td>
        </tr>
        <tr>
          <td>
            <strong>Tarihi:</strong>
            {{
              dateStore.dateFormat({
                date: piyangoStore.lotteryData.ilantarihi,
                pattern: 'dd-mm-yy'
              })
            }}
          </td>
          <td>
            <strong>2. İlan Tarihi:</strong>
            {{
              dateStore.dateFormat({
                date: piyangoStore.lotteryData.ilantarihi2,
                pattern: 'dd-mm-yy'
              })
            }}
          </td>
        </tr>
        <tr v-if="piyangoMecraStore.piyangoAllMecraData.length > 0">
          <td colspan="2">
            Ayrıca, çekiliş sonuçları
            <strong>
              <template v-for="(mecra, i) in piyangoMecraStore.piyangoAllMecraData">
                {{ mecra.mecraAdi
                }}{{ i !== piyangoMecraStore.piyangoAllMecraData.length - 1 ? ', ' : '' }}
              </template>
            </strong>
            {{
              piyangoMecraStore.piyangoAllMecraData.length > 1
                ? 'mecralarında'
                : 'mecrasında'
            }}
            ilan edilecektir.
          </td>
        </tr>
      </tbody>
    </table>

    <table
      cellspacing="0"
      class="table-no-line"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayoutNoLine'}"
      style="font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <strong class="title" style="font-size: 10pt; margin-bottom: 10px">
              7- Talihlilerin Başvuru Tarihi:
            </strong>
          </td>
        </tr>
      </tbody>
    </table>

    <table
      cellspacing="0"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayout'}"
      style="margin-bottom: 10px; font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <strong>Talihlilerin son başvuru tarihi:</strong>
            {{
              dateStore.dateFormat({
                date: piyangoStore.lotteryData.asilSonBasvuruTarihi,
                pattern: 'dd-mm-yy'
              })
            }}
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <strong>İkramiyelerin son teslim tarihi:</strong>
            {{
              dateStore.dateFormat({
                date: piyangoStore.lotteryData.ikramiyeTeslimTarihi,
                pattern: 'dd-mm-yy'
              })
            }}
          </td>
        </tr>
      </tbody>
    </table>

    <table
      cellspacing="0"
      class="table-no-line"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayoutNoLine'}"
      style="font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <strong class="title" style="font-size: 10pt; margin-bottom: 10px">
              8- Diğer Hususlar:
            </strong>
          </td>
        </tr>
      </tbody>
    </table>

    <table
      cellspacing="0"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayout'}"
      style="margin-bottom: 10px; font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <div>
              <span v-for="txt in digerHususlar">
                {{ txt }}
                <br />
              </span>
            </div>
            <div style="margin-top: 16px">
              <span v-for="txt in piyangoDataStore.digerHusularYardimAmacliTexts">
                {{ txt }}
                <br />
              </span>
            </div>
          </td>
        </tr>
      </tbody>
    </table>

    <table
      cellspacing="0"
      class="table-no-line"
      data-pdfmake="{'widths': [ '50%', '50%'],'layout':'pdfTableLayoutNoLine'}"
      style="font-size: 10pt">
      <tbody>
        <tr>
          <td colspan="2">
            <strong class="title" style="font-size: 10pt; margin-bottom: 10px">
              9-Piyangoya Konu İkramiyeler:
            </strong>
          </td>
        </tr>
      </tbody>
    </table>

    <table
      cellspacing="0"
      data-pdfmake="{'widths': ['10%', '45%', '15%', '15%', '15%'],'layout': 'pdfTableLayout'}"
      style="margin-bottom: 10px; font-size: 10pt"
      v-if="piyangoIkramiyeStore.piyangoAllIkramiyeData.length > 0">
      <thead>
        <tr>
          <th><strong>Sıra No</strong></th>
          <th><strong>Cinsi, Markası, Modeli</strong></th>
          <th><strong>Birim Değeri (KDV+ÖTV Dahil)</strong></th>
          <th>
            <strong>Talihli Adedi</strong>
          </th>
          <th><strong>Toplam Değer</strong></th>
        </tr>
      </thead>
      <tbody>
        <template v-for="(item, i) in piyangoIkramiyeStore.piyangoAllIkramiyeData">
          <tr>
            <td>{{ i + 1 }}</td>
            <td>{{ `${item.cinsi}, ${item.marka}, ${item.model}` }}</td>
            <td>
              {{
                item.paraBirimi !== null
                  ? `${globalStore.toTrLocale(item.birimFiyat)} ${
                      item.paraBirimi.paraBirimiSembol
                    }`
                  : globalStore.toTrLocale(item.birimFiyat)
              }}
            </td>
            <td>{{ item.asilTalihliAdedi }}</td>
            <td>
              {{
                item.paraBirimi !== null
                  ? `${globalStore.toTrLocale(item.toplamDeger)} ${
                      item.paraBirimi.paraBirimiSembol
                    }`
                  : globalStore.toTrLocale(item.toplamDeger)
              }}
            </td>
          </tr>
        </template>
        <tr>
          <td colspan="3" style="text-align: right"><strong>TOPLAM:</strong></td>
          <td>{{ piyangoIkramiyeStore.piyangoAllIkramiyeTotals.asilTalihliAdedi }}</td>
          <td>
            {{
              `${globalStore.toTrLocale(
                piyangoIkramiyeStore.piyangoAllIkramiyeTotals.toplamDeger
              )} ${piyangoIkramiyeStore.piyangoAllIkramiyeParaBirimi}`
            }}
          </td>
        </tr>
      </tbody>
    </table>
  </template>
</template>
<script setup lang="ts">
  import { ref, onBeforeMount, computed } from 'vue'
  import { useGlobalStore } from '@/stores/globalStore'
  const globalStore = useGlobalStore()
  import { useDataStore } from '@/stores/dataStore'
  const dataStore = useDataStore()
  import { useGlobalDataStore } from '@/stores/globalDataStore'
  const globalDataStore = useGlobalDataStore()
  import { useDateStore } from '@/stores/dateStore'
  const dateStore = useDateStore()
  import { usePiyangoStore } from '../../stores/piyangoStore'
  const piyangoStore = usePiyangoStore()
  import { usePiyangoMecraStore } from '../../stores/piyangoMecraStore'
  const piyangoMecraStore = usePiyangoMecraStore()
  import { usePiyangoMecraService } from '../../service/piyangoMecraService'
  const piyangoMecraService = usePiyangoMecraService()
  import { usePiyangoIkramiyeStore } from '../../stores/piyangoIkramiyeStore'
  const piyangoIkramiyeStore = usePiyangoIkramiyeStore()
  import { usePiyangoIkramiyeService } from '../../service/piyangoIkramiyeService'
  const piyangoIkramiyeService = usePiyangoIkramiyeService()
  import { useCustomerIrtibatService } from '@/module/uyeler/service/customerIrtibatService'
  const customerIrtibatService = useCustomerIrtibatService()
  import { usePiyangoDataStore } from '../../stores/piyangoDataStore'
  const piyangoDataStore = usePiyangoDataStore()
  import { usePiyangoYardimAmacliStore } from '../../stores/piyangoYardimAmacliStore'
  const piyangoYardimAmacliStore = usePiyangoYardimAmacliStore()

  const loaded = ref(false)

  const digerHususlar = computed<string[]>(() => {
    return piyangoStore.lotteryData.digerHususlar.split('\n')
  })

  onBeforeMount(async () => {
    await piyangoMecraService.GetAllMecralar()
    await customerIrtibatService.GetIrtibat(piyangoStore.duzenleyenData.id)
    await piyangoIkramiyeService.GetAllIkramiyeler()

    await dataStore.GetIlList()

    loaded.value = true
  })
</script>
