<template>
  <div class="graphic-child-menus">
    <div class="header">
      <ui-icon type="return" class="icon" ctrl @click="$emit('quit')" />
      <p>{{ title }}</p>
    </div>
    <div class="menu-list">
      <div
        v-for="menu in menus"
        :key="menu.key"
        class="menu"
        :class="{ active: uiType.current === menu.key }"
        @click="clickHandler(menu)"
      >
        <ui-icon :type="menu.icon" class="icon" />
        <p>{{ menu.text }}</p>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { MenusRaw, findMainMenuByAttr } from "@/views/graphic/menus";
import UiIcon from "@/components/base/components/icon/index.vue";
import { uiType } from "@/hook/useGraphic";
import { computed } from "vue";

const props = defineProps<{ menus: MenusRaw }>();
const title = computed(() => findMainMenuByAttr(props.menus)?.text);

const emit = defineEmits<{ (e: "quit") }>();
const clickHandler = (menu) => {
  uiType.change(menu.key as any);
  emit("quit");
};
</script>

<style lang="scss" scoped>
.graphic-child-menus {
  background-color: var(--editor-menu-back);
  position: absolute;
  top: calc(var(--editor-head-height) + var(--header-top));
  bottom: 0;
  left: calc(var(--editor-menu-left) + var(--editor-menu-width));
  padding: 16px;
  overflow-y: auto;

  .menu-list {
    display: grid;
    grid-template-columns: repeat(3, 80px);
    grid-gap: 16px;
  }
}

.menu {
  display: flex;
  flex-direction: column;
  cursor: pointer;
  height: 100px;
  pointer-events: none;
  transition: color 0.3s ease;

  //&:hover,
  &.active {
    color: var(--colors-primary-base);
  }

  &.active {
    background-color: rgba(255, 255, 255, 0.06);
  }

  .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    font-size: 40px;
    text-align: center;
    background: #383838;
  }
  p {
    padding: 4px;
    font-size: 12px;
    text-align: center;
  }
}

.header {
  margin-bottom: 10px;
  padding: 5px 0;
  text-align: center;
  font-size: 16px;
  position: relative;

  .icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
  }
}
</style>
