import { c as MapToComponentField, V as VegaSlimmer } from './global-slimmer-registry-17c4efd4.js';

var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
/**
 * Filters dropped/selected files based on the accepted file types specified in the host component's `accept` property.
 *
 * The host component is expected to expose a string `accept` property using the same syntax as the standard
 * HTML `<input type="file">` `accept` attribute (file extensions like `.png`, MIME types like `image/png`,
 * MIME wildcards like `image/*`, or the universal wildcards `*` / `*\/*` / `/*`).
 *
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept
 */
class DropFileAcceptFilterSlimmer extends VegaSlimmer {
  /**
   * Filters the files based on accepted file types if specified.
   *
   * @param {FileList|null} fileList - FileList is a FileList object
   * @returns {File[]} An array of `File` objects after filtering based on the accepted file types specified in the `accept` property
   */
  process(fileList) {
    const files = Array.from(fileList || []);
    if (fileList && this.accept && this.accept !== '*' && this.accept !== '/*' && this.accept !== '*/*') {
      const acceptFileTypes = this.accept.split(',');
      return files.filter((file) => this.validateFileType(file, acceptFileTypes));
    }
    return files;
  }
  /**
   * Checks if a given file matches any of the accepted file types based on file name, MIME type, or base type.
   *
   * @param {File} file - File object
   * @param {string[]} acceptTypes - An array of strings that represent the file types that are accepted.
   * @returns {boolean} A boolean value, indicating whether the provided file matches any of the accepted file types specified in the `acceptTypes` array.
   */
  validateFileType(file, acceptTypes) {
    const fileName = file.name;
    const fileType = (file.type || '').toLowerCase();
    const fileBaseType = fileType.replace(/\/.*$/, '');
    return acceptTypes.some((acceptFileType) => {
      acceptFileType = acceptFileType.trim().toLowerCase();
      if (acceptFileType.startsWith('.')) {
        return fileName.toLowerCase().endsWith(acceptFileType);
      }
      else if (acceptFileType.endsWith('/*')) {
        return fileBaseType === acceptFileType.replace(/\/.*$/, '');
      }
      else {
        return fileType === acceptFileType;
      }
    });
  }
}
__decorate([
  MapToComponentField()
], DropFileAcceptFilterSlimmer.prototype, "accept", void 0);

export { DropFileAcceptFilterSlimmer as D };
