<script setup lang="ts">
import QRCode from "@/components/QRCode.vue";
import {computed} from "vue";
import Image from 'primevue/image'
import { type Organization, useOrganization } from '@/queries/organization'

const {
  layout, color,
  orgs,
  message1, message2,
  message3, message4,
} = defineProps([
  'layout', 'color',
  "orgs",
  'message1', 'message2',
  'message3', 'message4',
])
const layout1Class = computed(() => ({
  hidden: layout !== 'layout1',
  layout1: layout === 'layout1',
}))
const layout2Class = computed(() => ({
  hidden: layout !== 'layout2',
  layout2: layout === 'layout2',
}))
const layout3Class = computed(() => ({
  hidden: layout !== 'layout3',
  layout3: layout === 'layout3',
}))
const layout4Class = computed(() => ({
  hidden: layout !== 'layout4',
  layout4: layout === 'layout4',
}))

const color2 = computed(() => {
  return '#' + color;
})

const { state: allOrgs } = useOrganization();

const myOrgs = computed(() => {
  console.log(orgs)
  if (allOrgs.value.status !== 'success') {
    return [];
  }
  return allOrgs.value.data.filter((org: Organization) => {
    return orgs.includes(org.id);
  });
});
</script>
<template>
  <div class="sticker">
    <QRCode class="qr-code"></QRCode>
    <div class="content">
      <div class="orgs">
        <div v-for="org in myOrgs" :key="org.id">
          <img class="logo" :src="org.logo" alt="todo" />
        </div>
      </div>
      <div v-bind:class="layout1Class">
        <div class="message">{{ message1 }}</div>
      </div>
      <div v-bind:class="layout2Class">
        <div class="message">{{ message1 }}</div>
        <div class="message">{{ message2 }}</div>
      </div>
      <div v-bind:class="layout3Class">
        <div class="message">{{ message1 }}</div>
        <div class="message">{{ message2 }}</div>
        <div class="message">{{ message3 }}</div>
      </div>
      <div v-bind:class="layout4Class">
        <div class="message">{{ message1 }}</div>
        <div class="message">{{ message2 }}</div>
        <div class="message">{{ message3 }}</div>
        <div class="message">{{ message4 }}</div>
      </div>
    </div>
  </div>
</template>
<style scoped>
.message {
  color: white;
  font-weight: bold;
  overflow: hidden;
  white-space: nowrap;
}
.qr-code {
  height: 100%;
}
.sticker {
  width: 256px;
  aspect-ratio: 6 / 1;
  background-color: v-bind(color2);
  display: flex;
  overflow: clip;
  position: relative;
  .content {
    width: 100%;
    .layout1 {
      line-height: 140%;
      font-size: 200%;
      height: 100%;
      > div {
        height: 100%;
      }
    }
    .layout2 {
      display: flex;
      flex-direction: column;
      font-size: 70%;
      gap: 5px;
      height: 100%;
      > div {
        flex: auto 1 0;
      }
    }
    .layout3 {
      display: flex;
      gap: 5px;
      height: 100%;
      > div {
        width: 33%;
      }
    }
    .layout4 {
      /* TODO: overflow issue.  Turn on outline to see. */
      display: grid;
      font-size: 70%;
      grid-template-columns: 50% 50%;
      gap: 5px;
      height: 100%;
    }
    .message {
      /*outline: 1px solid #CCC3;*/
      padding-left: 4px;
      padding-right: 4px;
      text-shadow: #FFF 0px 0px 4px;
      z-index: 100;
    }
    .orgs {
      display: flex;
      flex-direction: row;
      justify-content: space-evenly;
      position: absolute;
      > div {
        flex-shrink: 0;
        .logo {
          height: 65px;
          width: 65px;
          margin-top: -10px;
          filter: grayscale(1) invert(1) brightness(4.0) opacity(0.2);
          transform: rotate(0deg);
        }
      }
    }
  }
}
</style>
