import { defineComponent, computed, openBlock, createElementBlock, normalizeClass, createElementVNode, withModifiers, toDisplayString, unref } from "vue";
import { t as typeDetection, f as formatDate } from "./utils.js";
import { _ as _export_sfc } from "./index2.js";
import "dayjs";
var index_vue_vue_type_style_index_0_scoped_true_lang = "";
const _hoisted_1 = ["onClick"];
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    data: { default: () => {
      return {};
    } },
    listItem: { default: () => {
      return {
        aRow: false
      };
    } },
    allData: { default: () => {
      return {};
    } },
    fieldConfig: { default: () => {
      return {};
    } },
    tenantConfig: { default: () => {
      return {};
    } }
  },
  emits: ["onItem"],
  setup(__props, { emit }) {
    const props = __props;
    const handleData = computed(() => {
      var _a, _b, _c, _d, _e, _f;
      let value = "";
      switch ((_a = props.listItem) == null ? void 0 : _a.handleType) {
        case "PHONE":
          value = handlePhone(props.data);
          break;
        case "CHANNEL":
          value = getChannelName(props.data);
          break;
        case "COMPANY":
          value = handleCompany(
            Array.isArray(props.data) ? props.data : [props.data]
          );
          break;
        case "DATE":
          value = handleDate(props.data, (_b = props.listItem) == null ? void 0 : _b.format);
          break;
        case "SELECT":
          value = handleSelect(props.data, (_c = props.listItem) == null ? void 0 : _c.enum_name);
          break;
        case "MULTI_SELECT":
          value = handleMultiSelect(props.data, (_d = props.listItem) == null ? void 0 : _d.enum_name);
          break;
        case "REGION":
          value = (_e = props.data) == null ? void 0 : _e.name;
          break;
        case "FLOAT_NUMBER":
          value = ((_f = props.listItem) == null ? void 0 : _f.format) == "%" ? `${props.data}%` : props.data;
          break;
      }
      return value;
    });
    const getters_tenant_config_by_key = computed(
      () => (name, key) => {
        var _a;
        const info = (_a = props.tenantConfig) == null ? void 0 : _a[name];
        return (info == null ? void 0 : info.find((res) => res.key == key)) || {};
      }
    );
    const handlePhone = (phone) => {
      var _a;
      const type = typeDetection(phone);
      if (type === "string") {
        const phoneList = phone.split(",");
        return (phoneList == null ? void 0 : phoneList.length) > 1 ? `${phoneList[0]} \u5171${phoneList.length}\u4E2A` : phone;
      } else if (type === "array") {
        return (phone == null ? void 0 : phone.length) > 1 ? `${(_a = phone[0]) == null ? void 0 : _a.mobile} \u5171${phone.length}\u4E2A` : phone == null ? void 0 : phone[0].mobile;
      }
    };
    const getChannelName = (id) => {
      var _a;
      return (_a = getters_tenant_config_by_key.value("clue_from_channel", id)) == null ? void 0 : _a.full_name;
    };
    const handleCompany = (val) => {
      var _a, _b;
      return (val == null ? void 0 : val.length) > 1 ? `${(_a = val[0]) == null ? void 0 : _a.company_name} \u5171${val.length}\u4E2A` : (_b = val == null ? void 0 : val[0]) == null ? void 0 : _b.company_name;
    };
    const handleDate = (val, format) => {
      return formatDate(val, format || "YYYY-MM-DD");
    };
    const handleSelect = (val, enum_name) => {
      var _a, _b, _c, _d;
      const tenantConfig = getters_tenant_config_by_key.value;
      if (enum_name === "business_fail_reason") {
        return val == 99 ? `[${(_a = tenantConfig(enum_name, val)) == null ? void 0 : _a.value}] ${(_b = props.allData) == null ? void 0 : _b.fail_reason_desc}` : (_c = tenantConfig(enum_name, val)) == null ? void 0 : _c.value;
      }
      return ((_d = tenantConfig(enum_name, val)) == null ? void 0 : _d.value) || "";
    };
    const handleMultiSelect = (val, enum_name) => {
      var _a, _b;
      const tenantConfig = props.tenantConfig[enum_name] || [];
      return (_b = (_a = tenantConfig == null ? void 0 : tenantConfig.filter((e) => val.includes(e.key) || val.includes(+e.key))) == null ? void 0 : _a.map((res) => res.value)) == null ? void 0 : _b.join("\u3001");
    };
    const onItem = () => {
      var _a;
      if (!((_a = props.listItem) == null ? void 0 : _a.allowClick))
        return;
      emit("onItem", {
        data: props.data,
        listItem: props.listItem
      });
    };
    return (_ctx, _cache) => {
      var _a, _b;
      return openBlock(), createElementBlock("span", {
        class: normalizeClass(["handle-text", { "a-row": __props.listItem.aRow }])
      }, [
        createElementVNode("span", {
          style: { "word-break": "break-word" },
          class: normalizeClass({
            "a-row": __props.listItem.aRow,
            "handle-text--clickable": ((_a = props.listItem) == null ? void 0 : _a.allowClick) && ((_b = props.listItem) == null ? void 0 : _b.viewType)
          }),
          onClick: withModifiers(onItem, ["stop"])
        }, toDisplayString(unref(handleData)), 11, _hoisted_1)
      ], 2);
    };
  }
});
var index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-2088e6fc"]]);
export { index as default };
