<template>
  <div>
    <div
      v-if="showBanner"
      class="banner-overlay"
    >
      <div class="banner-container">
        <div class="banner-header">
          <div class="banner-title">
            <i class="fa fa-bell text-warning mr-10" />
            <span class="text-bold">
              {{ bannerTitle }}
            </span>
          </div>
          <Button
            type="error"
            size="small"
            class="close-banner-button"
            @click="closeBanner"
          >
            <i class="fa fa-times" />
          </Button>
        </div>
        <div class="banner-content">
          <div
            class="banner-image"
            @click="openExternalUrl(bannerUrl)"
          >
            <img
              :src="bannerImage"
              class="banner-img"
            >
          </div>

          <div class="banner-content-text mt-20 mb-20">
            <div
              v-if="bannerHtml"
              v-html="bannerHtml"
            />
            <div v-else>
              {{ bannerSubTitle }}
            </div>
          </div>

          <div class="cta-section">
            <Button
              type="primary"
              size="large"
              class="cta-button"
              @click="openExternalUrl(bannerUrl)"
            >
              {{ bannerButton }}
            </Button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { useStorage } from '@vueuse/core';
import { STORAGE_KEYS } from '@/constant/storage';

export default {
  name: 'BannerPopup',
  data() {
    return {
      bannerTitle: '',
      bannerSubTitle: '',
      bannerHtml: '',
      bannerButton: '',
      bannerUrl: '',
      bannerClosed: true,
    };
  },
  computed: {
    showBanner() {
      return !this.bannerClosed;
    },
  },
  methods: {
    closeBanner() {
      this.bannerClosed = true;
    },
    openExternalUrl(url) {
      window.open(url, '_blank');
    },
  },
  created() {
    const bannerPopup = this.getNotifyBanner;

    if (!(bannerPopup && bannerPopup.key && bannerPopup.show)) {
      return false;
    }

    this.bannerClosed = useStorage(STORAGE_KEYS.LOCAL_STORAGE.BANNER_POPUP(bannerPopup.key), false);
    this.bannerUrl = bannerPopup.url;
    this.bannerTitle = bannerPopup.title;
    this.bannerSubTitle = bannerPopup.sub_title || '';
    this.bannerHtml = bannerPopup.html_title || '';
    this.bannerImage = bannerPopup.image;
    this.bannerButton = bannerPopup.button || this.$t('BANNER_BUTTON_OPEN_TEXT');
  },
};
</script>

<style scoped>
.banner-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 15px;
}

.banner-container {
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border-radius: 20px;
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2);
  max-width: 650px;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: 95vh;
  animation: slideIn 0.5s ease-out;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Custom Scrollbar */
.banner-container::-webkit-scrollbar {
  width: 8px;
}

.banner-container::-webkit-scrollbar-track {
  background: transparent;
}

.banner-container::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.banner-container::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, 0.3);
}

@keyframes slideIn {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.banner-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.banner-title {
  color: #2c3e50;
  font-size: 16px;
  font-weight: 600;
}

.close-banner-button {
  background: transparent !important;
  border: none !important;
  color: #2c3e50 !important;
  border-radius: 50% !important;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.close-banner-button:hover {
  background: rgba(0, 0, 0, 0.1) !important;
  transform: scale(1.1);
}

.banner-content {
  padding: 15px;
  color: #34495e;
  text-align: center;
}

.banner-image {
  margin-bottom: 15px;
  overflow: hidden;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.banner-img {
  width: 100%;
  height: auto;
  border-radius: 12px;
  transition: transform 0.3s ease;
}

.banner-image:hover .banner-img {
  transform: scale(1.2);
}

.banner-image:hover {
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.banner-icon {
  font-size: 48px;
  margin-bottom: 20px;
  animation: bounce 2s infinite;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

.info-block {
  background: rgba(255, 255, 255, 0.8);
  border-radius: 15px;
  padding: 15px;
  margin-bottom: 20px;
}

.banner-main-title {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 8px;
  color: #16a085;
  text-shadow: none;
}

.banner-subtitle {
  font-size: 15px;
  color: #7f8c8d;
  margin-bottom: 15px;
}

.price-info {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

.old-price, .new-price {
  text-align: center;
}

.price-label {
  display: block;
  font-size: 14px;
  color: #95a5a6;
  margin-bottom: 5px;
}

.price-value {
  display: block;
  font-size: 18px;
  font-weight: bold;
}

.old-price .price-value {
  text-decoration: line-through;
  color: #95a5a6;
}

.new-price .price-value {
  color: #27ae60;
  text-shadow: none;
  font-weight: bold;
}

.platform-icons {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 25px;
  flex-wrap: wrap;
}

.platform-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 10px;
  border: 1px solid #e9ecef;
  min-width: 80px;
  transition: all 0.3s ease;
}

.platform-icon:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.platform-icon span {
  font-size: 12px;
  font-weight: bold;
  color: #495057;
  margin-top: 5px;
}

.platform-img {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.platform-icon i {
  font-size: 30px;
  margin-bottom: 5px;
}

.offer-section {
  background: rgba(255, 255, 255, 0.5);
  border-radius: 15px;
  padding: 15px;
  margin-bottom: 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.offer-title {
  font-size: 18px;
  margin-bottom: 10px;
  color: #2980b9;
}

.offer-list {
  text-align: left;
}

.offer-item {
  margin-bottom: 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  color: #34495e;
}

.cta-section {
  margin-bottom: 10px;
}

.cta-text {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 10px;
  color: #c0392b;
}

.cta-button {
  background: linear-gradient(45deg, #1abc9c, #16a085) !important;
  border: none !important;
  border-radius: 25px !important;
  padding: 10px 25px !important;
  font-weight: bold !important;
  font-size: 16px !important;
  text-transform: uppercase !important;
  letter-spacing: 1px !important;
  box-shadow: 0 5px 15px rgba(22, 160, 133, 0.4) !important;
  transition: all 0.3s ease !important;
  color: white !important;
}

.cta-button:hover {
  transform: translateY(-3px) !important;
  box-shadow: 0 8px 25px rgba(22, 160, 133, 0.5) !important;
}

.banner-footer {
  font-size: 13px;
  color: #7f8c8d;
  font-style: italic;
}

/* Responsive */
@media (max-width: 768px) {
  .banner-container {
    margin: 10px;
    max-width: none;
  }

  .banner-main-title {
    font-size: 22px;
  }

  .price-info {
    flex-direction: column;
    gap: 10px;
  }

  .banner-content {
    padding: 15px;
  }
}
</style>
