import { defineComponent, ref, computed, watchEffect, onMounted, nextTick, openBlock, createElementBlock, withModifiers, createVNode, unref, isRef, toDisplayString, createCommentVNode } from "vue";
import { G as GET, q as proxy_api, S as Store, _ as _sfc_main$1 } from "./index2.js";
import { t as typeDetection } from "./utils.js";
import "vant";
import "@wltech/svg";
import "dayjs";
import "qs";
import "vuedraggable";
import "vue-router";
var Api = {
  getBusinessDetail(params) {
    return GET(
      `${proxy_api[Store.node_env]}/crm_v2/web/business_opp/detail`,
      params
    );
  }
};
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1 = {
  key: 0,
  class: "uno-ml-6"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    data: { default: () => {
      return {};
    } },
    listItem: { default: () => {
      return {
        isEdit: false
      };
    } },
    fieldConfig: { default: () => {
      return {};
    } },
    tenantConfig: { default: () => {
      return {};
    } }
  },
  emits: ["onClickItem", "onFail", "onSuccess"],
  setup(__props, { emit }) {
    const props = __props;
    let stageValue = ref();
    const dataIsArray = computed(() => {
      return typeDetection(props.data) === "array";
    });
    watchEffect(() => {
      var _a;
      if (props.data) {
        if (dataIsArray.value) {
          stageValue.value = { key: (_a = props.data[0]) == null ? void 0 : _a.stage.toString() };
          return;
        }
        stageValue.value = { key: props.data.toString() };
      }
    });
    const stageList = computed(() => {
      return props.tenantConfig["business_stage"];
    });
    const stageFailList = computed(() => {
      return props.tenantConfig["business_fail_reason"];
    });
    const businessOppDetail = ref({});
    const onClickItem = async (params) => {
      var _a, _b;
      if (!params.stage.type) {
        emit("onClickItem", params);
        (_a = props.listItem.on) == null ? void 0 : _a.onClickItem(params);
      } else if (params.stage.type == "success") {
        const { data } = await Api.getBusinessDetail({
          business_id: (_b = props.listItem) == null ? void 0 : _b.businessId
        });
        businessOppDetail.value = data;
      }
    };
    const onFail = (params) => {
      var _a;
      emit("onFail", params);
      (_a = props.listItem.on) == null ? void 0 : _a.onFail(params);
    };
    const onSuccess = (params) => {
      var _a;
      emit("onSuccess", params);
      (_a = props.listItem.on) == null ? void 0 : _a.onSuccess(params);
    };
    const stageRef = ref(null);
    const maxWidth = ref();
    onMounted(() => {
      nextTick(() => {
        maxWidth.value = stageRef.value.scrollWidth;
      });
    });
    return (_ctx, _cache) => {
      var _a;
      return openBlock(), createElementBlock("div", {
        class: "bo-stage-popup a-row",
        ref_key: "stageRef",
        ref: stageRef,
        onClick: _cache[1] || (_cache[1] = withModifiers(() => {
        }, ["stop"]))
      }, [
        createVNode(_sfc_main$1, {
          modelValue: unref(stageValue),
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(stageValue) ? stageValue.value = $event : stageValue = $event),
          isEdit: ((_a = __props.listItem) == null ? void 0 : _a.isEdit) || false,
          stageList: unref(stageList),
          stageFailList: unref(stageFailList),
          businessOppDetail: businessOppDetail.value,
          maxWidth: maxWidth.value,
          onOnClickItem: onClickItem,
          onOnFail: onFail,
          onOnSuccess: onSuccess
        }, null, 8, ["modelValue", "isEdit", "stageList", "stageFailList", "businessOppDetail", "maxWidth"]),
        unref(dataIsArray) && __props.data.length > 1 ? (openBlock(), createElementBlock("span", _hoisted_1, toDisplayString(`\u5171${__props.data.length}\u4E2A`), 1)) : createCommentVNode("", true)
      ], 512);
    };
  }
});
export { _sfc_main as default };
