"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const XEUtils = require("xe-utils");
const optionInfo = require("./option-info.js");
function isOption(option) {
  return option instanceof optionInfo.OptionInfo;
}
function createOption($xeSelect, _vm) {
  return isOption(_vm) ? _vm : new optionInfo.OptionInfo($xeSelect, _vm);
}
function watchOption(props, option) {
  Object.keys(props).forEach((name) => {
    vue.watch(() => props[name], (value) => {
      option.update(name, value);
    });
  });
}
function assembleOption($xeSelect, el, option, $xeOptgroup) {
  const { reactData } = $xeSelect;
  const { staticOptions } = reactData;
  const parentElem = el.parentNode;
  const parentOption = $xeOptgroup ? $xeOptgroup.optionConfig : null;
  const parentCols = parentOption ? parentOption.options : staticOptions;
  if (parentElem && parentCols) {
    parentCols.splice(XEUtils.arrayIndexOf(parentElem.children, el), 0, option);
    reactData.staticOptions = staticOptions.slice(0);
  }
}
function destroyOption($xeSelect, option) {
  const { reactData } = $xeSelect;
  const { staticOptions } = reactData;
  const matchObj = XEUtils.findTree(staticOptions, (item) => item.id === option.id, { children: "options" });
  if (matchObj) {
    matchObj.items.splice(matchObj.index, 1);
  }
  reactData.staticOptions = staticOptions.slice(0);
}
exports.assembleOption = assembleOption;
exports.createOption = createOption;
exports.destroyOption = destroyOption;
exports.isOption = isOption;
exports.watchOption = watchOption;
