import { __exports as pattern } from '../../../../../../../_virtual/pattern.mjs';
import path__default from 'node:path';
import { globParent as globParent$1 } from '../../../../../glob-parent@5.1.2/node_modules/glob-parent/index.mjs';
import { micromatch_1 } from '../../../../../micromatch@4.0.5/node_modules/micromatch/index.mjs';

Object.defineProperty(pattern, "__esModule", {
  value: true
});
pattern.matchAny = pattern.convertPatternsToRe = pattern.makeRe = pattern.getPatternParts = pattern.expandBraceExpansion = pattern.expandPatternsWithBraceExpansion = pattern.isAffectDepthOfReadingPattern = pattern.endsWithSlashGlobStar = pattern.hasGlobStar = pattern.getBaseDirectory = pattern.isPatternRelatedToParentDirectory = pattern.getPatternsOutsideCurrentDirectory = pattern.getPatternsInsideCurrentDirectory = pattern.getPositivePatterns = pattern.getNegativePatterns = pattern.isPositivePattern = pattern.isNegativePattern = pattern.convertToNegativePattern = pattern.convertToPositivePattern = pattern.isDynamicPattern = pattern.isStaticPattern = void 0;
const path = path__default;
const globParent = globParent$1;
const micromatch = micromatch_1;
const GLOBSTAR = '**';
const ESCAPE_SYMBOL = '\\';
const COMMON_GLOB_SYMBOLS_RE = /[*?]|^!/;
const REGEX_CHARACTER_CLASS_SYMBOLS_RE = /\[[^[]*]/;
const REGEX_GROUP_SYMBOLS_RE = /(?:^|[^!*+?@])\([^(]*\|[^|]*\)/;
const GLOB_EXTENSION_SYMBOLS_RE = /[!*+?@]\([^(]*\)/;
const BRACE_EXPANSION_SEPARATORS_RE = /,|\.\./;
function isStaticPattern(pattern, options = {}) {
  return !isDynamicPattern(pattern, options);
}
pattern.isStaticPattern = isStaticPattern;
function isDynamicPattern(pattern, options = {}) {
  /**
   * A special case with an empty string is necessary for matching patterns that start with a forward slash.
   * An empty string cannot be a dynamic pattern.
   * For example, the pattern `/lib/*` will be spread into parts: '', 'lib', '*'.
   */
  if (pattern === '') {
    return false;
  }
  /**
   * When the `caseSensitiveMatch` option is disabled, all patterns must be marked as dynamic, because we cannot check
   * filepath directly (without read directory).
   */
  if (options.caseSensitiveMatch === false || pattern.includes(ESCAPE_SYMBOL)) {
    return true;
  }
  if (COMMON_GLOB_SYMBOLS_RE.test(pattern) || REGEX_CHARACTER_CLASS_SYMBOLS_RE.test(pattern) || REGEX_GROUP_SYMBOLS_RE.test(pattern)) {
    return true;
  }
  if (options.extglob !== false && GLOB_EXTENSION_SYMBOLS_RE.test(pattern)) {
    return true;
  }
  if (options.braceExpansion !== false && hasBraceExpansion(pattern)) {
    return true;
  }
  return false;
}
pattern.isDynamicPattern = isDynamicPattern;
function hasBraceExpansion(pattern) {
  const openingBraceIndex = pattern.indexOf('{');
  if (openingBraceIndex === -1) {
    return false;
  }
  const closingBraceIndex = pattern.indexOf('}', openingBraceIndex + 1);
  if (closingBraceIndex === -1) {
    return false;
  }
  const braceContent = pattern.slice(openingBraceIndex, closingBraceIndex);
  return BRACE_EXPANSION_SEPARATORS_RE.test(braceContent);
}
function convertToPositivePattern(pattern) {
  return isNegativePattern(pattern) ? pattern.slice(1) : pattern;
}
pattern.convertToPositivePattern = convertToPositivePattern;
function convertToNegativePattern(pattern) {
  return '!' + pattern;
}
pattern.convertToNegativePattern = convertToNegativePattern;
function isNegativePattern(pattern) {
  return pattern.startsWith('!') && pattern[1] !== '(';
}
pattern.isNegativePattern = isNegativePattern;
function isPositivePattern(pattern) {
  return !isNegativePattern(pattern);
}
pattern.isPositivePattern = isPositivePattern;
function getNegativePatterns(patterns) {
  return patterns.filter(isNegativePattern);
}
pattern.getNegativePatterns = getNegativePatterns;
function getPositivePatterns(patterns) {
  return patterns.filter(isPositivePattern);
}
pattern.getPositivePatterns = getPositivePatterns;
/**
 * Returns patterns that can be applied inside the current directory.
 *
 * @example
 * // ['./*', '*', 'a/*']
 * getPatternsInsideCurrentDirectory(['./*', '*', 'a/*', '../*', './../*'])
 */
function getPatternsInsideCurrentDirectory(patterns) {
  return patterns.filter(pattern => !isPatternRelatedToParentDirectory(pattern));
}
pattern.getPatternsInsideCurrentDirectory = getPatternsInsideCurrentDirectory;
/**
 * Returns patterns to be expanded relative to (outside) the current directory.
 *
 * @example
 * // ['../*', './../*']
 * getPatternsInsideCurrentDirectory(['./*', '*', 'a/*', '../*', './../*'])
 */
function getPatternsOutsideCurrentDirectory(patterns) {
  return patterns.filter(isPatternRelatedToParentDirectory);
}
pattern.getPatternsOutsideCurrentDirectory = getPatternsOutsideCurrentDirectory;
function isPatternRelatedToParentDirectory(pattern) {
  return pattern.startsWith('..') || pattern.startsWith('./..');
}
pattern.isPatternRelatedToParentDirectory = isPatternRelatedToParentDirectory;
function getBaseDirectory(pattern) {
  return globParent(pattern, {
    flipBackslashes: false
  });
}
pattern.getBaseDirectory = getBaseDirectory;
function hasGlobStar(pattern) {
  return pattern.includes(GLOBSTAR);
}
pattern.hasGlobStar = hasGlobStar;
function endsWithSlashGlobStar(pattern) {
  return pattern.endsWith('/' + GLOBSTAR);
}
pattern.endsWithSlashGlobStar = endsWithSlashGlobStar;
function isAffectDepthOfReadingPattern(pattern) {
  const basename = path.basename(pattern);
  return endsWithSlashGlobStar(pattern) || isStaticPattern(basename);
}
pattern.isAffectDepthOfReadingPattern = isAffectDepthOfReadingPattern;
function expandPatternsWithBraceExpansion(patterns) {
  return patterns.reduce((collection, pattern) => {
    return collection.concat(expandBraceExpansion(pattern));
  }, []);
}
pattern.expandPatternsWithBraceExpansion = expandPatternsWithBraceExpansion;
function expandBraceExpansion(pattern) {
  return micromatch.braces(pattern, {
    expand: true,
    nodupes: true
  });
}
pattern.expandBraceExpansion = expandBraceExpansion;
function getPatternParts(pattern, options) {
  let {
    parts
  } = micromatch.scan(pattern, Object.assign(Object.assign({}, options), {
    parts: true
  }));
  /**
   * The scan method returns an empty array in some cases.
   * See micromatch/picomatch#58 for more details.
   */
  if (parts.length === 0) {
    parts = [pattern];
  }
  /**
   * The scan method does not return an empty part for the pattern with a forward slash.
   * This is another part of micromatch/picomatch#58.
   */
  if (parts[0].startsWith('/')) {
    parts[0] = parts[0].slice(1);
    parts.unshift('');
  }
  return parts;
}
pattern.getPatternParts = getPatternParts;
function makeRe(pattern, options) {
  return micromatch.makeRe(pattern, options);
}
pattern.makeRe = makeRe;
function convertPatternsToRe(patterns, options) {
  return patterns.map(pattern => makeRe(pattern, options));
}
pattern.convertPatternsToRe = convertPatternsToRe;
function matchAny(entry, patternsRe) {
  return patternsRe.some(patternRe => patternRe.test(entry));
}
pattern.matchAny = matchAny;

export { pattern as default };
