function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
function _classPrivateGetter(s, r, a) { return a(_assertClassBrand(s, r)); }
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import pick from '/file/resource/deps/lodash/pick.js';
import uniq from '/file/resource/deps/lodash/uniq.js';
import { CelDataViewerElement, Config } from '/file/resources/celDynJS/celData/cel-data-viewer.mjs?version=20250901';
var tagName = 'collection-viewer';
export class CollectionFilter {
  constructor() {
    _defineProperty(this, "searchTerm", void 0);
    _defineProperty(this, "fromDate", void 0);
    _defineProperty(this, "toDate", void 0);
    _defineProperty(this, "category", void 0);
    _defineProperty(this, "eventStartDateTime", void 0);
    _defineProperty(this, "eventEndDateTime", void 0);
    _defineProperty(this, "eventTimeType", void 0);
    _defineProperty(this, "eventForm", []);
    _defineProperty(this, "eventGenre", []);
    _defineProperty(this, "targetGroup", []);
  }
}
export class CollectionParams extends CollectionFilter {
  constructor() {
    super(...arguments);
    _defineProperty(this, "xpage", 'celements_ajax');
    _defineProperty(this, "ajax_mode", 'export/collections/v2');
    _defineProperty(this, "ajax", 1);
    _defineProperty(this, "showFields", []);
    _defineProperty(this, "start", void 0);
    _defineProperty(this, "nb", void 0);
    _defineProperty(this, "sortFields", []);
    _defineProperty(this, "maxImageHeight", void 0);
    _defineProperty(this, "maxImageWidth", void 0);
    _defineProperty(this, "debug", void 0);
  }
}
class CollectionConfig extends Config {
  constructor() {
    super(...arguments);
    _defineProperty(this, "tagName", tagName);
    _defineProperty(this, "ParamsClass", CollectionParams);
  }
  processParams(params) {
    params.start = params.offset;
    params.nb = params.limit;
    params.showFields = uniq(['searchInfo',
    // needed for hitCount
    ...params.showFields, ...params.fields]);
    return params;
  }
  extractResults(data) {
    return data.results;
  }
  extractCount(data) {
    var _data$searchInfo;
    return (_data$searchInfo = data.searchInfo) === null || _data$searchInfo === void 0 || (_data$searchInfo = _data$searchInfo.hitCount) === null || _data$searchInfo === void 0 ? void 0 : _data$searchInfo.countTotal;
  }
  extractHasMore(data) {
    var _data$searchInfo$hitC, _data$searchInfo2;
    return ((_data$searchInfo$hitC = (_data$searchInfo2 = data.searchInfo) === null || _data$searchInfo2 === void 0 || (_data$searchInfo2 = _data$searchInfo2.hitCount) === null || _data$searchInfo2 === void 0 ? void 0 : _data$searchInfo2.countAfter) !== null && _data$searchInfo$hitC !== void 0 ? _data$searchInfo$hitC : 1) > 0;
  }
}
var _CollectionViewerElement_brand = /*#__PURE__*/new WeakSet();
class CollectionViewerElement extends CelDataViewerElement {
  constructor() {
    super(new CollectionConfig());
    _classPrivateMethodInitSpec(this, _CollectionViewerElement_brand);
  }
  get method() {
    var _super$method;
    return (_super$method = super.method) !== null && _super$method !== void 0 ? _super$method : 'POST';
  }
  get path() {
    var _super$path;
    return (_super$path = super.path) !== null && _super$path !== void 0 ? _super$path : _classPrivateGetter(_CollectionViewerElement_brand, this, _get_path);
  }
  get collection() {
    return this.getAttribute('collection') || undefined;
  }
  set collection(value) {
    this.setAttribute('collection', value);
  }
  get viewer() {
    return this.loader;
  }
  get sortFields() {
    var _this$getAttribute;
    return ((_this$getAttribute = this.getAttribute('sort-fields')) !== null && _this$getAttribute !== void 0 ? _this$getAttribute : "").split(',').filter(Boolean);
  }
  get params() {
    return Object.assign(super.params, this.filter, {
      sortFields: this.sortFields
    });
  }
  get filter() {
    var ret = new CollectionFilter();
    var json = this.getAttribute('filter') || '{}';
    try {
      Object.assign(ret, JSON.parse(json));
    } catch (error) {
      console.warn("failed parsing filter", json, error);
    }
    return ret;
  }
  set filter(value) {
    var _this$config$createPa;
    var filter = new CollectionFilter();
    var params = (_this$config$createPa = this.config.createParams(value)) !== null && _this$config$createPa !== void 0 ? _this$config$createPa : value;
    Object.assign(filter, pick(params, Object.keys(filter)));
    this.setAttribute('filter', JSON.stringify(filter));
  }
  setFilter(key, value) {
    this.filter = _objectSpread(_objectSpread({}, this.filter), {}, {
      [key]: value
    });
  }
  static get initAttributes() {
    return uniq([...super.initAttributes, 'collection']);
  }
  static get observedAttributes() {
    return uniq([...super.observedAttributes, 'filter', 'sort-fields']);
  }
}
function _get_path(_this) {
  if (!_this.collection) throw new Error('attribute collection missing');
  return "/".concat(_this.collection.split('.').join('/'));
}
if (!customElements.get(tagName)) {
  customElements.define(tagName, CollectionViewerElement);
}