<template>
  <transition name="slide">
    <div class="panel-index" v-if="WorkflowStore.panel.show">
      <div class="panel-header">
        <h3>{{ state.nodeData.title }}</h3>
        <div class="__hover" @click="WorkflowStore.nodePanelClose()">×</div>
      </div>
      <div class="panel-sub">
        <CzrFormColumn
          :span="24"
          label-width="0px"
          v-model:param="state.nodeData.subTitle"
          :transparent="true"
          placeholder="副标题..."
          :max-length="20"
          :clearable="false"
        />
      </div>
      <div class="panel-content">
        <template v-if="nodeDataCpt.type === NodeType.Root">
          <rootPanel :node="WorkflowStore.panel.node"/>
        </template>
        <template v-else-if="nodeDataCpt.type === NodeType.Test">
          <testPanel :node="WorkflowStore.panel.node"/>
        </template>
        <template v-else-if="nodeDataCpt.type === NodeType.Answer">
          <answerPanel :node="WorkflowStore.panel.node"/>
        </template>
        <template v-else-if="nodeDataCpt.type === NodeType.IfElse">
          <ifElsePanel :node="WorkflowStore.panel.node"/>
        </template>
      </div>
    </div>
  </transition>
</template>

<script setup lang="ts">
import {computed, getCurrentInstance, onMounted, reactive, ref, watch} from "vue";
import rootPanel from '../instance/root/panel/index.vue'
import answerPanel from '../instance/answer/panel/index.vue'
import ifElsePanel from '../instance/if-else/panel/index.vue'
import testPanel from '../instance/test/panel/index.vue'
import {useWorkflowStore} from "@/stores";
import {NodeType} from "@/views/workflow/types";

const WorkflowStore = useWorkflowStore()
const emits = defineEmits([])
const props = defineProps({
})
const {proxy}: any = getCurrentInstance()
const state: any = reactive({
  nodeData: {}
})
const nodeDataCpt = computed(() => WorkflowStore.panel.node?.data.workflowData || {})
watch(() => nodeDataCpt.value, (n) => {
  if (n) {
    state.nodeData = WorkflowStore.panel.node?.data.workflowData || {}
  }
})
</script>

<style lang="scss" scoped>
@use "@/views/workflow/instance/component/style";

.panel-index {
  width: 400px;
  height: 100%;
  background-color: white;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  border-radius: 10px 0 0 10px;
  .panel-header {
    padding: 16px 16px 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
  }
  .panel-sub {
    border-bottom: style.$borderStyle;
    padding: 6px;
  }
  .panel-content {
    padding: 0 16px 16px;
    flex: 1;
    overflow-y: auto;
  }
}

/* 过渡动画 */
.slide-enter-active,
.slide-leave-active {
  transition: transform 0.3s ease;
}
.slide-enter-from,
.slide-leave-to {
  transform: translateX(100%);
}
</style>