import '../../../utils/index.mjs';
import { has, isNull, isEqual } from 'lodash-es';
import { hasValue } from '../../../utils/data.mjs';
import { buildProps, definePropType } from '../../../utils/props/runtime.mjs';

"use strict";
const ALL_VALUE = "_ALL";
const initValue = (columns, values) => {
  const copyValues = {};
  if (columns.length) {
    columns.forEach((column) => {
      let value = has(values, column.key) ? values[column.key] : null;
      if (has(column, "options") && !column.unUseDefaultOption) {
        if (column.type === "checkbox-group" || has(column, "mode")) {
          value = !hasValue(value) || Array.isArray(value) && value.length === 0 ? [ALL_VALUE] : value;
        } else {
          value = !hasValue(value) ? ALL_VALUE : value;
        }
      }
      copyValues[column.key] = value;
    });
  }
  return copyValues;
};
const filterAllValue = (values, column) => {
  let value = null;
  if (Array.isArray(values)) {
    value = values.filter((item) => item !== ALL_VALUE || !hasValue(values));
    if (column && column.type === "number-range") {
      value = values ? values.every((e) => !isNull(e)) ? values : null : null;
    }
  } else {
    value = values === ALL_VALUE || !hasValue(values) ? null : values;
  }
  return value;
};
const treeDataFormat = (arr = [], fieldNames) => {
  let options = [];
  if (!arr) return [];
  options = arr.map((e) => {
    const obj = {};
    obj.label = e[fieldNames.label];
    obj.value = e[fieldNames.value];
    if (e[fieldNames.children] && e[fieldNames.children].length) {
      obj.children = treeDataFormat(e[fieldNames.children], fieldNames);
    }
    return obj;
  });
  return options;
};
const findLabelByValue = (tree, value) => {
  function _findLabel(nodes) {
    const labels = [];
    if (!nodes) return [];
    for (const node of nodes) {
      if (isEqual(node.value, value)) {
        labels.push(node.label);
      }
      if (node.children && node.children.length > 0) {
        const childLabels = _findLabel(node.children);
        if (childLabels) {
          labels.push(...childLabels);
        }
      }
    }
    return labels.length > 0 ? labels : [];
  }
  return _findLabel(tree).join(",");
};
const advancedFilteringProps = buildProps({
  filterColumns: {
    type: definePropType(Array),
    default: () => []
  },
  value: {
    type: Object,
    default: () => ({})
  },
  formOptions: {
    type: definePropType(Object),
    default: () => ({ layout: "vertical" })
  },
  overlayStyle: {
    type: definePropType(Object),
    default: () => ({
      width: "500px"
    })
  }
});
const advancedFilteringParamsProps = buildProps({
  filterColumns: {
    type: definePropType(Array),
    default: () => []
  },
  value: {
    type: Object,
    default: () => ({})
  },
  formOptions: {
    type: definePropType(Object),
    default: () => ({ layout: "vertical" })
  },
  showFooter: {
    type: Boolean,
    default: false
  }
});
const advancedFilteringEmits = {
  change: (value) => !!value,
  "update:value": (value) => !!value
};
const advancedFilteringParamsEmits = {
  close: () => true,
  confirm: () => true,
  changeValue: (value) => !!value,
  "update:value": (value) => !!value
};
const advancedFilteringTagsEmits = {
  change: (value) => !!value,
  "update:value": (value) => !!value
};

export { ALL_VALUE, advancedFilteringEmits, advancedFilteringParamsEmits, advancedFilteringParamsProps, advancedFilteringProps, advancedFilteringTagsEmits, filterAllValue, findLabelByValue, initValue, treeDataFormat };
//# sourceMappingURL=advanced-filtering.mjs.map
