<script setup lang="ts">
import { ref } from 'vue'
import {
  ArrowRight,
  Close,
  Notification,
} from '@element-plus/icons-vue'

interface Props {
  title?: string
  message?: string
  moreText?: string
  backgroundColor?: string
  borderColor?: string
}

withDefaults(defineProps<Props>(), {
  title: '网站公告',
  message: '系统将于 2024年6月15日 0:00 - 2:00 进行维护升级，期间可能影响部分功能使用，请合理安排业务时间。',
  moreText: '查看更多',
  backgroundColor: 'linear-gradient(180deg, rgba(247, 251, 255, .96), rgba(238, 246, 255, .94))',
  borderColor: '#a9c9ff',
})

const visible = ref(true)
</script>

<template>
  <section
    v-if="visible"
    class="website-notice"
    :style="{ background: backgroundColor, borderColor }"
    aria-label="网站公告"
  >
    <div class="notice-heading">
      <el-icon :size="26" class="notice-icon" aria-hidden="true">
        <Notification />
      </el-icon>
      <strong class="notice-title">{{ title }}</strong>
    </div>

    <span class="notice-divider" aria-hidden="true"></span>

    <p class="notice-message">{{ message }}</p>

    <button class="notice-more" type="button">
      <span>{{ moreText }}</span>
      <el-icon :size="16" aria-hidden="true"><ArrowRight /></el-icon>
    </button>

    <button class="notice-close" type="button" aria-label="关闭公告" @click="visible = false">
      <el-icon :size="18"><Close /></el-icon>
    </button>
  </section>
</template>

<style scoped>
.website-notice {
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 22px 0 28px;
  border: 1px solid;
  border-radius: 7px;
  box-shadow: 0 10px 28px rgba(68, 126, 224, .10);
}

.notice-heading {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #1267e8;
}

.notice-icon {
  color: #1267e8;
}

.notice-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.notice-divider {
  width: 1px;
  height: 22px;
  flex: 0 0 auto;
  background: #b7c3d6;
}

.notice-message {
  min-width: 0;
  flex: 1 1 auto;
  margin: 0;
  overflow: hidden;
  color: #111827;
  font-size: 16px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notice-more,
.notice-close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.notice-more {
  gap: 6px;
  padding: 0;
  color: #1267e8;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.notice-close {
  width: 26px;
  height: 26px;
  color: #9aa4b2;
}

.notice-close:hover,
.notice-more:hover {
  opacity: .82;
}

@media (max-width: 992px) {
  .website-notice {
    min-height: auto;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
  }

  .notice-message {
    white-space: normal;
  }

  .notice-divider {
    display: none;
  }
}

@media (max-width: 768px) {
  .website-notice {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .notice-heading,
  .notice-message,
  .notice-more {
    grid-column: 1 / -1;
  }

  .notice-title {
    font-size: 18px;
  }

  .notice-message {
    font-size: 14px;
  }

  .notice-more {
    justify-self: start;
  }

  .notice-close {
    position: absolute;
    right: 12px;
    top: 12px;
  }
}
</style>
