import { d as defineComponent, c as createVNode, u as useTraceStore, w as watch, s as shallowRef, r as reactive, t as transformTraceTree } from "./trace-explore-apm-entry-B_OOskGz.js";
import { spanDetail } from "monitor-api/modules/apm_trace";
import { S as SpanDetails } from "./span-details-CP-_ioeu.js";
const exploreSpanSlider = /* @__PURE__ */ defineComponent({
  name: "ExploreSpanSlider",
  props: {
    /* 是否显示组件 */
    isShow: {
      type: Boolean,
      required: true
    },
    /** 当前选中的应用 ID */
    appName: {
      type: String
    },
    /** 当前选中的 spanID */
    spanId: {
      type: String
    }
  },
  emits: {
    sliderClose: () => true
  },
  setup(props, {
    emit
  }) {
    const store = useTraceStore();
    const spanDetails = reactive({});
    const spanDetailLoading = shallowRef(false);
    watch(() => props.isShow, (val) => {
      if (val && props.spanId) {
        getSpanDetails();
      }
    }, {
      immediate: true
    });
    async function getSpanDetails() {
      const params = {
        app_name: props.appName,
        span_id: props.spanId
      };
      spanDetailLoading.value = true;
      await spanDetail(params).then((result) => {
        store.setSpanDetailData(result);
        result.trace_tree.traceID = result?.trace_tree?.spans?.[0]?.traceID;
        Object.assign(spanDetails, transformTraceTree(result.trace_tree)?.spans?.[0]);
      }).catch(() => {
      }).finally(() => {
        spanDetailLoading.value = false;
      });
    }
    function handleSliderShowChange(isShow) {
      if (isShow) {
        return;
      }
      emit("sliderClose");
    }
    return {
      spanDetails,
      spanDetailLoading,
      handleSliderShowChange
    };
  },
  render() {
    const {
      isShow,
      spanDetails,
      spanDetailLoading,
      handleSliderShowChange
    } = this;
    return createVNode(SpanDetails, {
      "isPageLoading": spanDetailLoading,
      "show": isShow,
      "spanDetails": spanDetails,
      "onShow": handleSliderShowChange
    }, null);
  }
});
export {
  exploreSpanSlider as default
};
