<template>
  <div class="zoom-page">
    <div class="zoom-shell">
      <div class="zoom-hero-card">
        <div class="zoom-section-kicker">Pautan Mesyuarat</div>
        <h3 class="zoom-title">Selamat Datang</h3>
        <p class="zoom-subtitle">{{ zoomSubtitle }}</p>
      </div>

      <div class="zoom-main-card">
        <div class="zoom-meeting-badge">{{ zoomMeetingLabel }}</div>

        <h4 class="zoom-content-title">Pautan Mesyuarat Rasmi</h4>
        <p class="zoom-content-text">
          Pastikan anda telah mendaftar kehadiran dan bersedia dengan sambungan internet yang stabil sebelum menyertai mesyuarat.
        </p>

        <div class="zoom-action-panel">
          <button class="btn-interactive" @click="navigateToURL" type="button">
            <i class="fa fa-video-camera"></i> Buka pautan mesyuarat
          </button>
          <button class="btn-secondary" @click="copyMeetingUrl" type="button">
            <i class="fa fa-clipboard"></i> Salin pautan
          </button>

          <div class="zoom-link-preview" v-if="meetingUrl">
            <span class="zoom-link-preview__label">Pautan:</span>
            <span class="zoom-link-preview__value">{{ meetingUrl }}</span>
          </div>

          <div class="zoom-link-note">
            Pautan akan dibuka terus ke sesi mesyuarat rasmi.
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      meetingUrl: 'https://meet.google.com/paa-tpck-ssq',
      portalSettings: null,
    };
  },

  computed: {
    zoomMeetingLabel() {
      return (this.portalSettings && this.portalSettings.zoom_meeting_label)
        ? this.portalSettings.zoom_meeting_label
        : "KoPKB KALI KE-29/2025";
    },
    zoomSubtitle() {
      return (this.portalSettings && this.portalSettings.zoom_subtitle)
        ? this.portalSettings.zoom_subtitle
        : "Sertai Mesyuarat Agung Tahunan KoPKB kali ke-29/2025 melalui pautan rasmi di bawah.";
    }
  },

  mounted() {
    this.fetchPortalSettings();
  },

  methods: {
    async fetchPortalSettings() {
      try {
        this.util.setAuthorization();
        const res = await axios.get(config.API + "portal-settings");
        if (res && res.data && res.data.status === "success") {
          this.portalSettings = res.data.data || null;
          if (this.portalSettings.zoom_meeting_url) this.meetingUrl = this.portalSettings.zoom_meeting_url;
        }
      } catch (e) {
        // Non-critical — fall back to defaults.
      }
    },

    navigateToURL() {
      window.open(this.meetingUrl, '_blank');
    },

    async copyMeetingUrl() {
      const text = String(this.meetingUrl || "").trim();
      if (!text) return;
      try {
        if (navigator && navigator.clipboard && navigator.clipboard.writeText) {
          await navigator.clipboard.writeText(text);
          this.util.notify("Pautan disalin.", "success");
          return;
        }
      } catch (e) {
        // fall through
      }

      try {
        const el = document.createElement("textarea");
        el.value = text;
        el.setAttribute("readonly", "");
        el.style.position = "absolute";
        el.style.left = "-9999px";
        document.body.appendChild(el);
        el.select();
        document.execCommand("copy");
        document.body.removeChild(el);
        this.util.notify("Pautan disalin.", "success");
      } catch (e) {
        this.util.notify("Tidak dapat salin pautan.", "error");
      }
    }
  }
};
</script>


<style scoped>
.zoom-page {
  font-family: Arial, sans-serif;
  margin-top: 18px;
  margin-bottom: 36px;
}

.zoom-shell {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 12px;
}

.zoom-hero-card {
  margin-bottom: 22px;
  padding: 26px 28px;
  border-radius: 22px;
  background: linear-gradient(135deg, #ffffff 0%, #eef6ff 100%);
  border: 1px solid #e2ebf5;
  box-shadow: 0 16px 34px rgba(35, 64, 97, 0.08);
  text-align: center;
}

.zoom-section-kicker {
  margin-bottom: 8px;
  color: #2f80ed;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.zoom-title {
  margin: 0 0 10px;
  color: #17324d;
  font-size: 3rem;
  font-weight: 800;
  line-height: 1.3;
}

.zoom-subtitle {
  max-width: 720px;
  margin: 0 auto;
  color: #5f7388;
  font-size: 1.5rem;
  line-height: 1.6;
}

.zoom-main-card {
  padding: 26px 28px;
  border-radius: 22px;
  background: #fff;
  border: 1px solid #e2ebf5;
  box-shadow: 0 16px 34px rgba(35, 64, 97, 0.08);
}

.zoom-meeting-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  background: #e8f1ff;
  color: #215db8;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.zoom-content-title {
  margin: 0 0 10px;
  color: #17324d;
  font-size: 2.4rem;
  font-weight: 700;
}

.zoom-content-text {
  margin-bottom: 18px;
  color: #5f7388;
  font-size: 1.5rem;
  line-height: 1.7;
}

.zoom-action-panel {
  width: 100%;
  padding: 18px;
  border-radius: 18px;
  background: linear-gradient(180deg, #f8fbff 0%, #eef6ff 100%);
  border: 1px solid #d9e8fb;
  box-shadow: 0 12px 28px rgba(35, 64, 97, 0.07);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.btn-interactive {
  padding: 14px 26px;
  background: linear-gradient(135deg, #0d6efd, #2f80ed);
  color: white;
  border: none;
  border-radius: 999px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.2s ease;
  outline: none;
  box-shadow: 0 12px 24px rgba(13, 110, 253, 0.25);
  width: 100%;
}

.btn-interactive:hover {
  transform: scale(1.05);
  box-shadow: 0 16px 28px rgba(13, 110, 253, 0.3);
}

.btn-interactive:active {
  transform: scale(0.98);
}

.btn-interactive:focus {
  outline: none;
  box-shadow: 0 0 5px 2px rgba(0, 123, 255, 0.5);
}

.btn-secondary {
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.7);
  color: #17324d;
  border: 1px solid rgba(23, 50, 77, 0.16);
  border-radius: 999px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(35, 64, 97, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  white-space: nowrap;
}

.btn-secondary:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 26px rgba(35, 64, 97, 0.12);
}

.zoom-link-preview {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(33, 93, 184, 0.16);
}

.zoom-link-preview__label {
  flex-shrink: 0;
  font-weight: 900;
  color: #215db8;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 1.05rem;
}

.zoom-link-preview__value {
  color: #17324d;
  font-weight: 700;
  word-break: break-all;
}

.zoom-link-note {
  grid-column: 1 / -1;
  margin-top: 12px;
  color: #5f7388;
  font-size: 1.3rem;
}

@media (max-width: 991px) {
  .zoom-action-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 767px) {

  .zoom-hero-card,
  .zoom-main-card {
    padding: 18px;
    border-radius: 16px;
  }

  .zoom-title {
    font-size: 2.35rem;
  }

  .zoom-subtitle,
  .zoom-content-text {
    font-size: 1.35rem;
  }

  .zoom-content-title {
    font-size: 2rem;
  }

  .btn-interactive {
    width: 100%;
  }
}
</style>