<template>
  <BasicModal
    v-bind="$attrs"
    @register="registerModal"
    :title="t('点击事件配置')"
    @ok="handleSubmit"
    width="70%"
  >
    <div class="config-box">
      <div style="max-width: 500px">
        <div class="box-top">
          <NodeHead :nodeName="t('自定义脚本')" />
        </div>
        <div style="height: calc(100% - 51px)">
          <CodeEditor v-model:value="definedScript" language="js" />
        </div>
      </div>
    </div>
  </BasicModal>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { CodeEditor } from '/@/components/CodeEditor';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { NodeHead } from '/@/components/ModalPanel/index';
  const { t } = useI18n();
  const definedScript = ref(``);
  const emit = defineEmits(['success', 'register']);

  const [registerModal, { closeModal, setModalProps }] = useModalInner(async (data) => {
    //如果已经设置过当前事件代码  则显示已经设置的值 反之  显示默认值
    definedScript.value = data.content;
    setModalProps({
      fixedHeight: true,
    });
  });
  const handleSubmit = () => {
    emit('success', definedScript.value);
    closeModal();
  };
</script>

<style lang="less" scoped>
  .config-box {
    display: flex;
    height: 100%;

    div:nth-child(1) {
      flex: 1;
    }

    div {
      flex: 2;
    }

    .box-top {
      display: flex;
      justify-content: space-between;
      height: 30px;
      border-bottom: 1px solid #f0f0f0;
      padding: 25px 20px;
    }

    .script-name {
      cursor: pointer;
      padding: 10px 0 10px 15px;

      &:hover {
        background: #eef4ff;
      }
    }

    .active-name {
      background: #eef4ff;
    }
  }

  :deep(.ant-drawer-title),
  .title {
    font-size: 16px;
    height: 20px;
    line-height: 18px;
    padding-left: 6px;
    border-left: 6px solid #5e95ff;
  }

  :deep(.ant-tag) {
    padding: 8px;
    font-size: 13px;
    margin-bottom: 7px;
    cursor: move;
  }
</style>
