import { defineComponent, openBlock, createElementBlock, normalizeClass, createElementVNode, createBlock, createCommentVNode, toDisplayString, createVNode, render, ref, computed, watch, watchEffect, unref, mergeProps, toHandlers, withCtx, Fragment, renderList, nextTick } from "vue";
import { Field } from "vant";
import { S as Store } from "./index2.js";
import { _ as _sfc_main$4 } from "./index4.js";
import { _ as _sfc_main$3 } from "./index18.js";
import { _ as _sfc_main$2 } from "./index6.js";
import { r as removeEmptyField, g as getQueryVariable } from "./index5.js";
import { _ as _export_sfc } from "./plugin-vue_export-helper.js";
import "@wltech/svg";
const proxy_api = {
  dev_uat: "/uat_api",
  dev_stg: "/stg_api",
  dev_prd: "/prd_api",
  dev_cos_api: "/cos_api",
  dev_uat_xsf: "/xsf_api",
  dev: "/uat_api",
  uat: "",
  stg: "",
  prd: "",
  gray: "",
  production: "",
  uat_xsf: "https://test.xsfapi.weiling.cn",
  stg_xsf: "https://pre-xsfapi.weiling.cn",
  prd_xsf: "https://xsfapi.weiling.cn",
  gray_xsf: "https://xsfapi.weiling.cn"
};
const token_key = {
  dev_uat: "auth-token-mp-test",
  dev_stg: "auth-token-mp",
  dev_prd: "auth-token-mp",
  dev_uat_xsf: "auth-token-se-test",
  dev_stg_xsf: "auth-token-se",
  dev_gray_xsf: "auth-token-se",
  dev_prd_xsf: "auth-token-se",
  uat: "auth-token-mp-test",
  stg: "auth-token-mp",
  prd: "auth-token-mp",
  gray: "auth-token-mp",
  uat_xsf: "auth-token-se-test",
  stg_xsf: "auth-token-se",
  prd_xsf: "auth-token-se",
  gray_xsf: "auth-token-se"
};
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1$1 = { class: "icon" };
const _hoisted_2$1 = { class: "text" };
const __default__ = {
  name: "WlNotice"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    show_toast: { type: Boolean, default: true },
    message: { default: "" },
    type: { default: "success" },
    duration: { default: 1500 }
  },
  setup(__props) {
    return (_ctx, _cache) => {
      return __props.show_toast ? (openBlock(), createElementBlock("div", {
        key: 0,
        class: normalizeClass(`notice ${__props.type}`),
        "data-weiling-mobile-ui-wl-notice": ""
      }, [
        createElementVNode("div", _hoisted_1$1, [
          __props.type === "success" ? (openBlock(), createBlock(_sfc_main$2, {
            key: 0,
            type: "successFill",
            width: "24",
            height: "24",
            color: "#45ce03"
          })) : __props.type === "warning" ? (openBlock(), createBlock(_sfc_main$2, {
            key: 1,
            type: "warningFill",
            width: "24",
            height: "24",
            color: "#f3a401"
          })) : __props.type === "alert" ? (openBlock(), createBlock(_sfc_main$2, {
            key: 2,
            type: "tipsFill",
            width: "24",
            height: "24",
            color: "#1b9fff"
          })) : __props.type === "error" ? (openBlock(), createBlock(_sfc_main$2, {
            key: 3,
            type: "closeFill",
            width: "24",
            height: "24",
            color: "#ff2a2d"
          })) : createCommentVNode("", true)
        ]),
        createElementVNode("p", _hoisted_2$1, toDisplayString(__props.message), 1)
      ], 2)) : createCommentVNode("", true);
    };
  }
});
let mountNode = null;
var WlNotice = (options) => {
  const duration = options.duration | 2e3;
  if (mountNode) {
    document.body.removeChild(mountNode);
    mountNode = null;
  }
  const app = createVNode(_sfc_main$1, {
    ...options,
    duration,
    show_toast: true
  });
  const timer = setTimeout(() => {
    if (mountNode) {
      document.body.removeChild(mountNode);
      mountNode = null;
    }
    clearTimeout(timer);
  }, duration);
  mountNode = document.createElement("div");
  render(app, mountNode);
  document.body.appendChild(mountNode);
};
function obj2String(obj, arr = [], idx = 0) {
  for (const item in obj) {
    arr[idx++] = [item, obj[item]];
  }
  return new URLSearchParams(arr).toString();
}
function getOptions(options) {
  var _a;
  const { sid = "", corp_id = "", card_resource = "" } = (_a = Store) != null ? _a : {};
  const params = {
    sid,
    corp_id,
    card_resource,
    ...options
  };
  return obj2String(params);
}
const onHandleUrl = (url) => {
  const { node_env } = Store;
  const isPersonMiniApp = node_env.includes("xsf");
  if (isPersonMiniApp) {
    return setPersonMiniAppUrl(url);
  }
  return url;
};
const setPersonMiniAppUrl = (url) => {
  let filterUrl = url;
  if (filterUrl.includes("/api/user/share/path")) {
    filterUrl = filterUrl.replace(
      "/api/user/share/path",
      "/apise/material/share/path"
    );
  } else if (filterUrl.includes("/interact/")) {
    filterUrl = filterUrl.replace("/interact/", "/apise/");
  } else if (filterUrl.includes("/api/")) {
    filterUrl = filterUrl.replace("/api/", "/apise/");
  } else if (filterUrl.includes("/wx/track")) {
    filterUrl = filterUrl.replace("/wx/track", "/apise/track/wx/track");
  }
  return filterUrl;
};
function request(url, options, method = "GET") {
  const staticOption = {
    sid: Store.sid,
    corp_id: Store.corp_id,
    tab_change: 0
  };
  const data = {
    ...staticOption,
    ...options
  };
  const searchStr = getOptions(removeEmptyField(data));
  const staticSearchStr = getOptions(removeEmptyField(staticOption));
  let initObj = {};
  let params = "";
  if (method === "GET") {
    initObj = {
      method,
      credentials: "include",
      headers: new Headers({
        "access-auth-token": getQueryVariable("msid"),
        [token_key[Store.node_env]]: Store.token
      })
    };
    params = searchStr;
  } else if (method === "FormPOST") {
    initObj = {
      method: "POST",
      credentials: "include",
      headers: new Headers({
        [token_key[Store.node_env]]: Store.token
      }),
      body: options
    };
    params = staticSearchStr;
  } else {
    initObj = {
      method,
      credentials: "include",
      headers: new Headers({
        "access-auth-token": getQueryVariable("msid"),
        Accept: "application/json, text/plain, */*",
        "Content-Type": "application/json",
        [token_key[Store.node_env]]: Store.token
      }),
      body: JSON.stringify(data)
    };
    params = staticSearchStr;
  }
  const filterUrl = onHandleUrl(url) + "?" + params;
  return fetch(filterUrl, initObj).then((res) => {
    const isArea = url.includes("region.json");
    return res.json().then((result) => {
      var _a;
      if (result.code === 200 || isArea) {
        return result;
      } else {
        WlNotice({
          message: (_a = result.msg) != null ? _a : "\u670D\u52A1\u5668\u5185\u90E8\u9519\u8BEF",
          type: "error",
          duration: 3e3
        });
        throw Error(result);
      }
    });
  }).then((res) => {
    return res;
  });
}
const GET = (url, options) => {
  return request(url, options, "GET");
};
const getSearchCompany = (params) => {
  return GET(
    `${proxy_api[Store.node_env]}/interact/material/company/fuzzy_search`,
    params
  );
};
var index_vue_vue_type_style_index_0_scoped_true_lang = "";
const _hoisted_1 = { class: "company-search-field" };
const _hoisted_2 = { class: "uno-max-h-150 scroll-y uno-pt-10" };
const _hoisted_3 = ["onClick"];
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    value: { default: "" },
    item: { default: () => {
    } },
    hasBorder: { type: Boolean, default: false },
    placeholder: { default: "" },
    placement: { default: "bottom-start" }
  },
  emits: ["update:value"],
  setup(__props, { emit }) {
    const props = __props;
    const fieldValue = ref();
    const popoverVisible = ref(false);
    const inputClass = computed(() => {
      return props.hasBorder ? `border-1 border-solid border-border-color uno-radius-6` : "";
    });
    const inputPlacehoder = computed(() => {
      var _a;
      return props.placeholder ? props.placeholder : `\u8BF7\u8F93\u5165${(_a = props == null ? void 0 : props.item) == null ? void 0 : _a.label}`;
    });
    const companyList = ref([]);
    const onPopoverSelect = (item) => {
      fieldValue.value = item.companyName;
    };
    const onSearch = async (val) => {
      var _a, _b;
      const result = await getSearchCompany({
        corp_id: Store.corp_id,
        appid: Store.app_id,
        name: val,
        scene: 1
      });
      companyList.value = ((_b = (_a = result.data) == null ? void 0 : _a.list) != null ? _b : []).slice(0, 10).map((res) => {
        return {
          companyName: res.name,
          companyCreditCode: res.credit_code,
          companyPlatFormId: res.platform_id
        };
      });
      nextTick(() => {
        popoverVisible.value = true;
      });
    };
    watch(
      () => fieldValue.value,
      (val) => {
        emit("update:value", val);
      }
    );
    watchEffect(() => {
      fieldValue.value = props.value;
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createVNode(unref(Field), mergeProps({
          modelValue: fieldValue.value,
          "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => fieldValue.value = $event),
          label: __props.item.label
        }, __props.item, toHandlers(__props.item.on || {})), {
          input: withCtx(() => [
            createVNode(_sfc_main$3, {
              modelValue: popoverVisible.value,
              "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => popoverVisible.value = $event),
              placement: __props.placement
            }, {
              reference: withCtx(() => [
                createElementVNode("div", {
                  class: normalizeClass(`w-full box-border uno-px-10 ${unref(inputClass)}`)
                }, [
                  createVNode(_sfc_main$4, {
                    modelValue: fieldValue.value,
                    "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => fieldValue.value = $event),
                    placeholder: unref(inputPlacehoder),
                    "need-debounce": true,
                    onOnChange: onSearch
                  }, null, 8, ["modelValue", "placeholder"])
                ], 2)
              ]),
              default: withCtx(() => [
                createElementVNode("div", _hoisted_2, [
                  (openBlock(true), createElementBlock(Fragment, null, renderList(companyList.value, (item) => {
                    return openBlock(), createElementBlock("div", {
                      key: item.companyCreditCode,
                      class: "w-full uno-px-10 uno-pb-10",
                      onClick: ($event) => onPopoverSelect(item)
                    }, toDisplayString(item.companyName), 9, _hoisted_3);
                  }), 128))
                ])
              ]),
              _: 1
            }, 8, ["modelValue", "placement"])
          ]),
          _: 1
        }, 16, ["modelValue", "label"])
      ]);
    };
  }
});
var index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-22e60dde"]]);
export { index as default };
