/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

import { _ as _defineProperty } from '../_chunks/dep-eb20e23f.mjs';
import { c as cloneDeep_1 } from '../_chunks/dep-44417261.mjs';
import { i as isUndefined_1 } from '../_chunks/dep-30451c48.mjs';
import { i as isArray_1 } from '../_chunks/dep-e3b14d70.mjs';
export { emitEvent } from '../utils/event.mjs';
import '../_chunks/dep-b4041200.mjs';
import '../_chunks/dep-a0b4a044.mjs';
import '../_chunks/dep-bf74f1c2.mjs';
import '../_chunks/dep-79821ff2.mjs';
import '../_chunks/dep-0bfbf721.mjs';
import '../_chunks/dep-39cc276d.mjs';
import '../_chunks/dep-6b22dd27.mjs';
import '../_chunks/dep-c959a6fb.mjs';
import '../_chunks/dep-0f0c89ff.mjs';
import '../_chunks/dep-8f777748.mjs';
import '../_chunks/dep-ae357f26.mjs';
import '../_chunks/dep-352691c2.mjs';
import '../_chunks/dep-2cfd5b3a.mjs';
import '../_chunks/dep-05fa17c9.mjs';
import '../_chunks/dep-c31e1d9e.mjs';
import '../_chunks/dep-66d6733b.mjs';
import '../_chunks/dep-a9c8a5d5.mjs';
import '../_chunks/dep-10085c61.mjs';
import '../_chunks/dep-1b058de3.mjs';
import '../_chunks/dep-c852a61a.mjs';
import '../_chunks/dep-92e7085e.mjs';
import '../_chunks/dep-44f056cd.mjs';
import '../_chunks/dep-23a0f453.mjs';
import '../_chunks/dep-1cf2b129.mjs';
import '../utils/helper.mjs';
import '../_chunks/dep-b6a73f93.mjs';
import '../_chunks/dep-55846619.mjs';
import '../_chunks/dep-cfcedf47.mjs';
import '../_chunks/dep-f6649a46.mjs';
import '../_chunks/dep-37ba476d.mjs';
import '../_chunks/dep-be27d184.mjs';
import '../_chunks/dep-1fe0ad42.mjs';
import '../_chunks/dep-d54f2690.mjs';
import '../_chunks/dep-59c8420d.mjs';
import '../_chunks/dep-74848b92.mjs';
import '../_chunks/dep-6f89b77e.mjs';
import '../_chunks/dep-6eea369f.mjs';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var TRANSFER_NAME = "TTransfer";
function findTopNode(vm) {
  if (vm.$options.name === "t-transfer") return vm;
  if (vm.$parent) return findTopNode(vm.$parent);
  return vm;
}
function getTransferListOption(prop) {
  if (isArray_1(prop)) {
    return {
      source: prop[0],
      target: prop[1]
    };
  }
  return {
    source: prop,
    target: prop
  };
}
function getDataValues(data, filterValues) {
  var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
    _ref$isTreeMode = _ref.isTreeMode,
    isTreeMode = _ref$isTreeMode === void 0 ? false : _ref$isTreeMode,
    _ref$include = _ref.include,
    include = _ref$include === void 0 ? true : _ref$include;
  if (isTreeMode) {
    var result = [];
    if (data) {
      for (var i = 0; i < data.length; i++) {
        var item = data[i];
        var isInclude = filterValues.includes(item.value);
        if (!include && isInclude) continue;
        if (item.children && item.children.length > 0) {
          var childResult = getDataValues(item.children, filterValues, {
            isTreeMode: isTreeMode,
            include: include
          });
          result = result.concat(childResult);
        } else if (include && isInclude || !include && !isInclude) {
          result.push(item.value);
        }
      }
    }
    return result;
  }
  return data.filter(function (item) {
    if (!item) return false;
    var isInclude = filterValues.includes(item.value);
    return (include && isInclude || !include && !isInclude) && !item.disabled;
  }).map(function (item) {
    return item.value;
  });
}
function getTransferData(data, keys) {
  var isTreeMode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  var list = data.map(function (transferDataItem, index) {
    var _transferDataItem$dis;
    var labelKey = (keys === null || keys === void 0 ? void 0 : keys.label) || "label";
    var valueKey = (keys === null || keys === void 0 ? void 0 : keys.value) || "value";
    if (isUndefined_1(transferDataItem[labelKey])) throw new Error("".concat(labelKey, " is not in DataOption ").concat(JSON.stringify(transferDataItem)));
    if (isUndefined_1(transferDataItem[valueKey])) throw new Error("".concat(valueKey, " is not in DataOption ").concat(JSON.stringify(transferDataItem)));
    var result = {
      label: transferDataItem[labelKey],
      value: transferDataItem[valueKey],
      key: "key__value_".concat(transferDataItem[valueKey], "_index_").concat(index),
      disabled: (_transferDataItem$dis = transferDataItem.disabled) !== null && _transferDataItem$dis !== void 0 ? _transferDataItem$dis : false,
      data: transferDataItem
    };
    if (isTreeMode && transferDataItem.children) result.children = getTransferData(transferDataItem.children, keys, true);
    return result;
  });
  return list;
}
function isAllNodeValid(data, filterValues, needMatch) {
  if (filterValues.includes(data.value)) return needMatch;
  return false;
}
function isTreeNodeValid(data, filterValues, needMatch) {
  var _data$children;
  if (!data) return !needMatch;
  if (filterValues.includes(data.value)) return needMatch;
  if ((_data$children = data.children) !== null && _data$children !== void 0 && _data$children.length) return data.children.some(function (item) {
    return isTreeNodeValid(item, filterValues, needMatch);
  });
  return !needMatch;
}
function cloneTreeWithFilter(sourceTree, targetTree, filterValues, needMatch) {
  sourceTree.forEach(function (item) {
    var newNode;
    if (isAllNodeValid(item, filterValues, needMatch)) {
      newNode = cloneDeep_1(item);
      targetTree.push(newNode);
    } else if (isTreeNodeValid(item, filterValues, needMatch)) {
      newNode = _objectSpread({}, item);
      delete newNode.children;
      targetTree.push(newNode);
      if (item.children) {
        newNode.children = [];
        cloneTreeWithFilter(item.children, newNode.children, filterValues, needMatch);
        if (newNode.children.length === 0) delete newNode.children;
      }
    }
  });
}
function filterTransferData(data, filterValues) {
  var needMatch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  var isTreeMode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  if (!isTreeMode) {
    if (needMatch) {
      return filterValues.map(function (value) {
        return data.find(function (item) {
          return item.value === value;
        });
      }).filter(function (item) {
        return !!item;
      });
    }
    return data.filter(function (item) {
      var isMatch = filterValues.includes(item.value);
      return !isMatch;
    });
  }
  var result = [];
  cloneTreeWithFilter(data, result, filterValues, needMatch);
  return result;
}
function getLefCount(nodes) {
  var total = 0;
  nodes.forEach(function (child) {
    if (child.children && child.children.length > 0) total += getLefCount(child.children);else total += 1;
  });
  return total;
}

export { TRANSFER_NAME, cloneTreeWithFilter, filterTransferData, findTopNode, getDataValues, getLefCount, getTransferData, getTransferListOption };
//# sourceMappingURL=utils.mjs.map
