<template>
  <div class="svg-view-container">
    <h1 class="page-title">SVG Icon Viewer</h1>
    <div class="icon-grid">
      <div
        v-for="icon in svgIcons"
        :key="icon"
        class="icon-card"
        @click="copyToClipboard(icon)"
      >
        <SvgIcon :name="icon" class="svg-display" />
        <span class="icon-name">{{ icon }}</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import { ElMessage } from 'element-plus';
  // SvgIcon is globally registered

  defineOptions({
    name: 'SvgView',
  });

  const svgFileNames = [
    'icon-add',
    'icon-apply',
    'icon-assign',
    'icon-base',
    'icon-delete',
    'icon-error',
    'icon-file',
    'icon-home',
    'icon-import',
    'icon-logout',
    'icon-org',
    'icon-print',
    'icon-success',
    'icon-system',
    'icon-user',
  ];

  const svgIcons = ref(svgFileNames);

  const copyToClipboard = async (name: string) => {
    try {
      await navigator.clipboard.writeText(name);
      ElMessage.success(`Copied '${name}' to clipboard!`);
    } catch (err) {
      ElMessage.error('Failed to copy icon name.');
      console.error('Failed to copy: ', err);
    }
  };
</script>

<style scoped>
  .svg-view-container {
    padding: 20px;
    background-color: #fff; /* White background for the content page */
    border-radius: 8px; /* Rounded corners for the content container */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); /* Softer shadow for the container */
  }

  .page-title {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 24px;
    color: #343a40;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 12px;
  }

  .icon-grid {
    display: grid;
    grid-template-columns: repeat(
      auto-fill,
      minmax(120px, 1fr)
    ); /* Responsive grid */
    gap: 20px; /* Space between icon cards */
  }

  .icon-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px;
    border: 1px solid #e0e0e0; /* Lighter border for cards */
    border-radius: 8px;
    background-color: #f8f9fa; /* Light background for cards */
    cursor: pointer;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    min-height: 100px;
  }

  .icon-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
  }

  .svg-display {
    font-size: 36px; /* Larger icon display */
    margin-bottom: 10px;
  }

  .icon-name {
    font-size: 0.8rem;
    color: #495057;
    text-align: center;
    word-break: break-all; /* Prevent long names from breaking layout */
  }

  .copy-feedback {
    margin-top: 20px;
    font-size: 0.9rem;
    color: #28a745; /* Green color for success message */
    font-weight: 500;
    text-align: center;
  }
</style>
