<script setup lang="ts">
import { ref } from 'vue'
import RadarLogo from '@/components/RadarLogo.vue'
import SystemStatus from '../components/SystemStatus.vue'
import FilterSort from '../components/FilterSort.vue'
import Pagination from '@/components/Pagination.vue'

import { useSystemStore } from '@/stores/system'
import { useDomainsStore } from '@/stores/domains'
import OperationStatus from '@/components/OperationStatus.vue'
const ds = useDomainsStore()
const sys = useSystemStore()

const hoverOp = ref<undefined | 'loading' | 'resolution' | 'analysis'>(undefined)
const showHover = ref(false)
function hoverTrigger(op: undefined | 'loading' | 'resolution' | 'analysis') {
  hoverOp.value = op
  showHover.value = true
}
</script>

<template>
  <aside class="control-panel" @mouseleave="showHover = false">
    <div class="drs-controls">
      <RadarLogo class="logo" />
      <div class="controller">
        <HButton hollow borderless class="drs-button"
          @click="sys.load"
          @mouseenter="hoverTrigger('loading')"
          @mouseleave="showHover = false"
          :disabled="sys.anyRunning"
        >
          <Icon name="load" />
        </HButton>
        <HButton hollow borderless class="drs-button"
          @click="sys.resolve"
          @mouseenter="hoverTrigger('resolution')"
          @mouseleave="showHover = false"
          :disabled="sys.anyRunning"
        >
          <Icon name="resolver" />
        </HButton>
        <HButton hollow borderless class="drs-button"
          @click="sys.analyze"
          @mouseenter="hoverTrigger('analysis')"
          @mouseleave="showHover = false"
          :disabled="sys.anyRunning"
        >
          <Icon name="analyze" />
        </HButton>
      </div>
    </div>
    <SystemStatus />
    <FilterSort />
    <Pagination class="bottom-fixed" />
    <transition name="popup">
      <OperationStatus :operation="hoverOp" :show="showHover" />
    </transition>
  </aside>
</template>

<style>
  .control-panel {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .logo {
    height: 2em;
  }

  .drs-controls {
    position: relative;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1em;
  }
  .controller {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .control-heading {
    margin-block: 0;
    margin-inline-start: 0.5em;
  }

  .holo-button.drs-button {
    font-size: 1.25em;
    padding: 0.25em 0.35em;
  }

  .bottom-fixed {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
  }

  .popup-enter-active {
    transition: 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .popup-leave-active {
    transition: 0.3s 0.2s cubic-bezier(0.5, 0, 0.75, 0);
  }

  .popup-enter-from,
  .popup-leave-to {
    opacity: 0;
    transform: scale(.8) translateY(-2em);
  }
</style>