"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _modules = require("../../modules");
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/**
 * ContainerSlot props
 *
 * @category Props
 */

function createReset(collection, currentList, setChildren) {
  return () => {
    currentList.forEach(c => {
      const index = collection.findIndex(p => p === c);
      collection.splice(index, 1);
    });
    setChildren?.([...collection]);
  };
}

/**
  @category Component
 */
const MSlot = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
  let {
    style,
    children
  } = props;
  const {
    setLChildren,
    leftSlotChildren,
    setRChildren,
    rightSlotChildren,
    setBChildren,
    bottomSlotChildren
  } = (0, _react.useContext)(_modules.ContainerSlotContext);
  children = Array.isArray(children) ? children : [children];
  const [cList, setClist] = (0, _react.useState)(children);
  (0, _react.useImperativeHandle)(ref, () => ({
    refresh: () => {
      console.log('refresh');
      setClist([...children]);
    }
  }));
  (0, _react.useEffect)(() => {
    let reset;
    if (style === 'left') {
      reset = createReset(leftSlotChildren, cList, setLChildren);
      leftSlotChildren.push(...cList);
      setLChildren?.([...leftSlotChildren]);
    } else if (style === 'right') {
      reset = createReset(rightSlotChildren, cList, setRChildren);
      rightSlotChildren.push(...cList);
      setRChildren?.([...rightSlotChildren]);
    } else if (style === 'bottom') {
      reset = createReset(bottomSlotChildren, cList, setBChildren);
      bottomSlotChildren.push(...cList);
      setBChildren?.([...bottomSlotChildren]);
    }
    return () => {
      reset?.();
    };
  }, [cList]);
  return typeof style === 'string' ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null) : /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: style
  }, cList);
});
var _default = exports.default = MSlot;
//# sourceMappingURL=MSlot.js.map