"use strict";
function ChildrenMixin(parent, options = {}) {
  const indexKey = options.indexKey || "index";
  return {
    inject: {
      [parent]: {
        default: null
      }
    },
    data() {
      return {};
    },
    computed: {
      // 会造成循环引用
      // parent() {
      //   if (this.disableBindRelation) {
      //     return null;
      //   }
      //   return this[parent];
      // },
      [indexKey]() {
        const that = this;
        that.bindRelation();
        if (that[parent]) {
          return that[parent].children.indexOf(this);
        }
        return null;
      }
    },
    watch: {
      disableBindRelation(val) {
        const that = this;
        if (!val) {
          that.bindRelation();
        }
      }
    },
    created() {
      const that = this;
      that.bindRelation();
    },
    mounted() {
    },
    beforeUnmount() {
      const that = this;
      that.onBeforeMount();
    },
    methods: {
      bindRelation() {
        var _a, _b, _c;
        if (!this[parent] || this[parent].children && this[parent].children.indexOf(this) !== -1) {
          return;
        }
        const children = [...this[parent].children || [], this];
        this[parent].children = children;
        (_a = this.innerAfterLinked) == null ? void 0 : _a.call(this, this);
        (_c = (_b = this[parent]).innerAfterLinked) == null ? void 0 : _c.call(_b, this);
      },
      onBeforeMount() {
        var _a, _b, _c, _d;
        const that = this;
        if (that[parent]) {
          that[parent].children = that[parent].children.filter((item) => item !== that);
          (_b = (_a = this[parent]).innerAfterUnLinked) == null ? void 0 : _b.call(_a, this);
          (_c = this.innerAfterUnLinked) == null ? void 0 : _c.call(this, this);
          (_d = that == null ? void 0 : that.destroyCallback) == null ? void 0 : _d.call(that);
        }
      }
    }
  };
}
function ParentMixin(parent) {
  return {
    provide() {
      return {
        [parent]: this
      };
    },
    data() {
      return {
        // 会造成循环引用
        // children: [],
      };
    }
  };
}
exports.ChildrenMixin = ChildrenMixin;
exports.ParentMixin = ParentMixin;
//# sourceMappingURL=../../../../../../.sourcemap/mp-weixin/uni_modules/tdesign-uniapp/components/common/relation/relation.js.map
