"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const Swipe = require("../swipe/Swipe.js");
const index_esm = require("../../../@vant/use/dist/index.esm.js");
const useExpose = require("../composables/use-expose.js");
const create = require("../utils/create.js");
const [name, bem] = create.createNamespace("swipe-item");
var stdin_default = Vue.defineComponent({
  name,
  setup(props, {
    slots
  }) {
    let rendered;
    const state = Vue.reactive({
      offset: 0,
      inited: false,
      mounted: false
    });
    const {
      parent,
      index
    } = index_esm.useParent(Swipe.SWIPE_KEY);
    if (!parent) {
      return;
    }
    const style = Vue.computed(() => {
      const style2 = {};
      const {
        vertical
      } = parent.props;
      if (parent.size.value) {
        style2[vertical ? "height" : "width"] = `${parent.size.value}px`;
      }
      if (state.offset) {
        style2.transform = `translate${vertical ? "Y" : "X"}(${state.offset}px)`;
      }
      return style2;
    });
    const shouldRender = Vue.computed(() => {
      const {
        loop,
        lazyRender
      } = parent.props;
      if (!lazyRender || rendered) {
        return true;
      }
      if (!state.mounted) {
        return false;
      }
      const active = parent.activeIndicator.value;
      const maxActive = parent.count.value - 1;
      const prevActive = active === 0 && loop ? maxActive : active - 1;
      const nextActive = active === maxActive && loop ? 0 : active + 1;
      rendered = index.value === active || index.value === prevActive || index.value === nextActive;
      return rendered;
    });
    const setOffset = (offset) => {
      state.offset = offset;
    };
    Vue.onMounted(() => {
      Vue.nextTick(() => {
        state.mounted = true;
      });
    });
    useExpose.useExpose({
      setOffset
    });
    return () => {
      var _a;
      return Vue.createVNode("div", {
        "class": bem(),
        "style": style.value
      }, [shouldRender.value ? (_a = slots.default) == null ? void 0 : _a.call(slots) : null]);
    };
  }
});
exports.default = stdin_default;
