"use strict";
const common_vendor = require("../../../../common/vendor.js");
require("../../../adapter-vue.js");
const TUIKit_components_TUISearch_searchTypeList = require("../search-type-list.js");
const TUIKit_components_TUISearch_searchTimeList = require("../search-time-list.js");
const common_assets = require("../../../../common/assets.js");
const TUIKit_utils_env = require("../../../utils/env.js");
if (!Math) {
  (Icon + DatePicker)();
}
const Icon = () => "../../common/Icon.js";
const DatePicker = () => "../../common/DatePicker/index.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  props: {
    popupPosition: {
      type: String,
      // "bottom" / "aside"
      default: "bottom"
    },
    searchType: {
      type: String,
      default: "global",
      // "global" / "conversation"
      validator(value) {
        return ["global", "conversation"].includes(value);
      }
    }
  },
  emits: ["searchConfigChange", "closeInConversationSearch"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const searchTypeList = common_vendor.computed(
      () => (props == null ? void 0 : props.searchType) === "conversation" ? TUIKit_components_TUISearch_searchTypeList.conversationSearchTypeList : TUIKit_components_TUISearch_searchTypeList.globalSearchTypeList
    );
    const currentSearchMessageType = common_vendor.ref(TUIKit_components_TUISearch_searchTypeList.searchMessageTypeDefault[props == null ? void 0 : props.searchType]);
    const currentSearchMessageTime = common_vendor.ref(TUIKit_components_TUISearch_searchTimeList.searchMessageTimeDefault);
    const isTimeTabsShow = common_vendor.computed(() => {
      return currentSearchMessageType.value.key !== "contact" && currentSearchMessageType.value.key !== "group";
    });
    const datePickerRangeDisplayType = common_vendor.computed(
      () => TUIKit_utils_env.isPC && props.searchType === "global" && !TUIKit_utils_env.isUniFrameWork ? "two" : "one"
    );
    const isDatePickerShow = common_vendor.ref(false);
    function onCurrentSearchMessageTypeChange(typeObject) {
      if ((typeObject == null ? void 0 : typeObject.searchType) === (props == null ? void 0 : props.searchType)) {
        currentSearchMessageType.value = (typeObject == null ? void 0 : typeObject.value) || TUIKit_components_TUISearch_searchTypeList.searchMessageTypeDefault[props == null ? void 0 : props.searchType];
      }
    }
    function onCurrentSearchMessageTimeChange(timeObject) {
      if ((timeObject == null ? void 0 : timeObject.searchType) === (props == null ? void 0 : props.searchType)) {
        currentSearchMessageTime.value = (timeObject == null ? void 0 : timeObject.value) || TUIKit_components_TUISearch_searchTimeList.searchMessageTimeDefault;
      }
    }
    common_vendor.onMounted(() => {
      common_vendor.Jt.watch(common_vendor.o.SEARCH, {
        currentSearchMessageType: onCurrentSearchMessageTypeChange,
        currentSearchMessageTime: onCurrentSearchMessageTimeChange
      });
    });
    common_vendor.onUnmounted(() => {
      common_vendor.Jt.unwatch(common_vendor.o.SEARCH, {
        currentSearchMessageType: onCurrentSearchMessageTypeChange,
        currentSearchMessageTime: onCurrentSearchMessageTimeChange
      });
    });
    const selectSearchType = (item) => {
      common_vendor.Jt.update(common_vendor.o.SEARCH, "currentSearchMessageType", {
        value: item,
        searchType: props.searchType
      });
    };
    const selectSearchTime = (item) => {
      if (isDatePickerShow.value && item.key === "all") {
        isDatePickerShow.value = false;
      } else {
        isDatePickerShow.value = false;
        common_vendor.Jt.update(common_vendor.o.SEARCH, "currentSearchMessageTime", {
          value: item,
          searchType: props.searchType
        });
      }
    };
    const handleSelectAllTimeClicked = () => {
      var _a;
      if (((_a = currentSearchMessageTime.value) == null ? void 0 : _a.key) !== "all") {
        common_vendor.Jt.update(common_vendor.o.SEARCH, "currentSearchMessageTime", {
          value: TUIKit_components_TUISearch_searchTimeList.searchMessageTimeDefault,
          searchType: props.searchType
        });
      } else {
        isDatePickerShow.value = true;
      }
    };
    const pickTimePeriod = (time) => {
      var _a, _b, _c;
      if (((_a = currentSearchMessageTime.value) == null ? void 0 : _a.key) === "all") {
        const { startDate, endDate } = time;
        const timePosition = Number((((_b = endDate == null ? void 0 : endDate.toDate()) == null ? void 0 : _b.getTime()) / 1e3).toFixed(0));
        const timePeriod = timePosition - Number((((_c = startDate == null ? void 0 : startDate.toDate()) == null ? void 0 : _c.getTime()) / 1e3).toFixed(0));
        const newSearchMessageTime = {
          key: currentSearchMessageTime.value.key,
          label: currentSearchMessageTime.value.label,
          value: {
            timePosition,
            timePeriod
          }
        };
        common_vendor.Jt.update(common_vendor.o.SEARCH, "currentSearchMessageTime", {
          value: newSearchMessageTime,
          searchType: props.searchType
        });
      }
    };
    const clearTimePicker = () => {
      var _a;
      isDatePickerShow.value = false;
      if (((_a = currentSearchMessageTime.value) == null ? void 0 : _a.key) === "all") {
        common_vendor.Jt.update(common_vendor.o.SEARCH, "currentSearchMessageTime", {
          value: TUIKit_components_TUISearch_searchTimeList.searchMessageTimeDefault,
          searchType: props.searchType
        });
      }
    };
    const closeSearchContainer = () => {
      emits("closeInConversationSearch");
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: props.searchType === "conversation" && !common_vendor.unref(TUIKit_utils_env.isUniFrameWork)
      }, props.searchType === "conversation" && !common_vendor.unref(TUIKit_utils_env.isUniFrameWork) ? {
        b: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUISearch.搜索会话内容")),
        c: common_vendor.p({
          file: common_vendor.unref(common_assets.closeIcon$1),
          width: "14px",
          height: "14px"
        }),
        d: common_vendor.o$1(closeSearchContainer)
      } : {}, {
        e: common_vendor.f(common_vendor.unref(searchTypeList), (tabItem, tabKey, i0) => {
          return {
            a: common_vendor.t(common_vendor.unref(common_vendor.Wt).t(`TUISearch.${tabItem.label}`)),
            b: tabKey,
            c: common_vendor.n(common_vendor.unref(currentSearchMessageType).key === tabItem.key && "tui-search-tabs-item-selected"),
            d: common_vendor.o$1(($event) => selectSearchType(tabItem), tabKey)
          };
        }),
        f: common_vendor.unref(isTimeTabsShow)
      }, common_vendor.unref(isTimeTabsShow) ? {
        g: common_vendor.f(common_vendor.unref(TUIKit_components_TUISearch_searchTimeList.searchMessageTimeList), (tabItem, tabKey, i0) => {
          return common_vendor.e({
            a: tabItem.key === "all"
          }, tabItem.key === "all" ? common_vendor.e({
            b: !common_vendor.unref(isDatePickerShow)
          }, !common_vendor.unref(isDatePickerShow) ? {
            c: common_vendor.t(common_vendor.unref(common_vendor.Wt).t(`TUISearch.选择时间`) + ":  " + common_vendor.unref(common_vendor.Wt).t(`TUISearch.全部`)),
            d: "0764f731-1-" + i0,
            e: common_vendor.p({
              file: common_vendor.unref(common_assets.downSVG),
              width: "14px",
              height: "14px"
            }),
            f: common_vendor.o$1(handleSelectAllTimeClicked, tabKey)
          } : {}, {
            g: common_vendor.unref(isDatePickerShow)
          }, common_vendor.unref(isDatePickerShow) ? {
            h: common_vendor.o$1(pickTimePeriod, tabKey),
            i: "0764f731-2-" + i0,
            j: common_vendor.p({
              type: "range",
              rangeTableType: common_vendor.unref(datePickerRangeDisplayType)
            })
          } : {}, {
            k: common_vendor.o$1(() => {
            }, tabKey),
            l: common_vendor.unref(isDatePickerShow)
          }, common_vendor.unref(isDatePickerShow) ? {
            m: "0764f731-3-" + i0,
            n: common_vendor.p({
              file: common_vendor.unref(common_assets.closeIcon),
              width: "14px",
              height: "14px"
            }),
            o: common_vendor.o$1(clearTimePicker, tabKey)
          } : {}) : {
            p: common_vendor.t(common_vendor.unref(common_vendor.Wt).t(`TUISearch.${tabItem.label}`))
          }, {
            q: tabKey,
            r: common_vendor.n(common_vendor.unref(currentSearchMessageTime).key === tabItem.key && "tui-search-time-item-selected"),
            s: common_vendor.o$1(($event) => selectSearchTime(tabItem), tabKey)
          });
        })
      } : {}, {
        h: common_vendor.n(common_vendor.unref(TUIKit_utils_env.isPC) && `tui-search-container-${props.popupPosition}`),
        i: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-search-container-h5-main"),
        j: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-search-container-h5"),
        k: common_vendor.n(common_vendor.unref(TUIKit_utils_env.isPC) && `container-${props.popupPosition}`),
        l: common_vendor.n(`container-${props.searchType}`)
      });
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-0764f731"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUISearch/search-container/index.js.map
