"use strict";
const uni_modules_tdesignUniapp_components_common_src_instantiationDecorator = require("../common/src/instantiationDecorator.js");
const uni_modules_tdesignUniapp_components_sticky_props = require("./props.js");
const uni_modules_tdesignUniapp_components_common_config = require("../common/config.js");
const uni_modules_tdesignUniapp_components_mixins_pageScroll = require("../mixins/page-scroll.js");
const uni_modules_tdesignUniapp_components_common_utils = require("../common/utils.js");
const uni_modules_tdesignUniapp_components_common_utils_wxs = require("../common/utils.wxs.js");
const common_vendor = require("../../../../common/vendor.js");
const name = `${uni_modules_tdesignUniapp_components_common_config.prefix}-sticky`;
const ContainerClass = `.${name}`;
const _sfc_main = uni_modules_tdesignUniapp_components_common_src_instantiationDecorator.uniComponent({
  name,
  options: {
    styleIsolation: "shared"
  },
  externalClasses: [
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class`,
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class-content`
  ],
  mixins: [uni_modules_tdesignUniapp_components_mixins_pageScroll.pageScrollMixin()],
  props: {
    ...uni_modules_tdesignUniapp_components_sticky_props.props
  },
  data() {
    return {
      prefix: uni_modules_tdesignUniapp_components_common_config.prefix,
      classPrefix: name,
      containerStyle: "",
      contentStyle: "",
      tools: uni_modules_tdesignUniapp_components_common_utils_wxs.tools
    };
  },
  watch: {
    offsetTop: "onScroll",
    disabled: "onScroll",
    container: "onScroll"
  },
  mounted() {
    this.onScroll();
  },
  methods: {
    onScroll(event) {
      const { scrollTop } = event || {};
      const { container, offsetTop, disabled } = this;
      if (disabled) {
        this.setDataAfterDiff({
          isFixed: false,
          transform: 0
        });
        return;
      }
      this.scrollTop = scrollTop || this.scrollTop;
      if (typeof container === "function") {
        Promise.all([uni_modules_tdesignUniapp_components_common_utils.getRect(this, ContainerClass), this.getContainerRect()]).then(([root, container2]) => {
          if (!root || !container2)
            return;
          if (offsetTop + root.height > container2.height + container2.top) {
            this.setDataAfterDiff({
              isFixed: false,
              transform: container2.height - root.height
            });
          } else if (offsetTop >= root.top) {
            this.setDataAfterDiff({
              isFixed: true,
              height: root.height,
              transform: 0
            });
          } else {
            this.setDataAfterDiff({ isFixed: false, transform: 0 });
          }
        });
        return;
      }
      uni_modules_tdesignUniapp_components_common_utils.getRect(this, ContainerClass).then((root) => {
        if (!root)
          return;
        if (offsetTop >= root.top) {
          this.setDataAfterDiff({ isFixed: true, height: root.height });
          this.transform = 0;
        } else {
          this.setDataAfterDiff({ isFixed: false });
        }
      });
    },
    setDataAfterDiff(data) {
      const { offsetTop } = this;
      const { containerStyle: prevContainerStyle, contentStyle: prevContentStyle } = this;
      const { isFixed, height, transform } = data;
      uni_modules_tdesignUniapp_components_common_utils.nextTick().then(() => {
        let containerStyle = "";
        let contentStyle = "";
        if (isFixed) {
          containerStyle += `height:${height}px;`;
          contentStyle += `position:fixed;top:${offsetTop}px;left:0;right:0;`;
        }
        if (transform) {
          const translate = `translate3d(0, ${transform}px, 0)`;
          contentStyle += `-webkit-transform:${translate};transform:${translate};`;
        }
        if (prevContainerStyle !== containerStyle || prevContentStyle !== contentStyle) {
          this.containerStyle = containerStyle;
          this.contentStyle = contentStyle;
        }
        this.$emit("scroll", {
          scrollTop: this.scrollTop,
          isFixed
        });
      });
    },
    getContainerRect() {
      const nodesRef = this.container();
      return new Promise((resolve) => nodesRef.boundingClientRect(resolve).exec());
    }
  }
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.n(_ctx.classPrefix + "__content " + _ctx.tClassContent),
    b: common_vendor.s(_ctx.tools._style(["z-index:" + _ctx.zIndex, _ctx.contentStyle])),
    c: common_vendor.n(_ctx.classPrefix + " " + _ctx.tClass),
    d: common_vendor.s(_ctx.tools._style(["z-index:" + _ctx.zIndex, _ctx.containerStyle, _ctx.customStyle]))
  };
}
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-1e0bcf5d"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/sticky.js.map
