<!-- 用户编辑弹窗 -->
<template>
  <ele-modal
    :width="800"
    :visible="visible"
    v-if="data"
    :title="`${data.appName}`"
    :maxable="true"
    @update:visible="updateVisible"
    :footer="null"
  >
    <a-tabs type="card" v-model:activeKey="activeKey" tabPosition="top">
      <a-tab-pane key="0" tab="插件介绍">
        <Basic :data="data" :appId="data.appId" />
      </a-tab-pane>
      <a-tab-pane key="1" tab="菜单管理">
        <Menu :data="data" :menuType="0" />
      </a-tab-pane>
      <a-tab-pane key="2" tab="按钮管理">
        <Authority :data="data" :menuType="1" />
      </a-tab-pane>
      <a-tab-pane key="3" tab="插件设置">
        <Setting :data="data" :appId="data.appId" />
      </a-tab-pane>
    </a-tabs>
  </ele-modal>
</template>

<script lang="ts" setup>
  import { ref, watch } from 'vue';
  import type { App } from '@/api/dashboard/appstore/model';
  import Authority from './setting/authority.vue';
  import Menu from './setting/menu.vue';
  import Basic from './setting/basic.vue';
  import Setting from './setting/setting.vue';
  import { message } from 'ant-design-vue';

  const props = defineProps<{
    // 弹窗是否打开
    visible: boolean;
    // 修改回显的数据
    data?: App | null;
    showView?: boolean;
  }>();

  const emit = defineEmits<{
    (e: 'update:visible', visible: boolean): void;
  }>();

  const activeKey = ref('0');
  // 编辑器内容，双向绑定
  const content = ref<any>('');

  /* 更新visible */
  const updateVisible = (value: boolean) => {
    emit('update:visible', value);
  };

  // 保存设置
  const save = () => {
    message.warn('待开发...');
  };

  watch(
    () => props.visible,
    (visible) => {
      if (visible) {
        content.value = props.data?.content;
      }
    }
  );
</script>
<style lang="less">
  .tab-pane {
    min-height: 100px;
  }
  .card-head {
    display: flex;
    height: 40px;
    align-items: center;
    margin-bottom: 30px;
  }
</style>
