import { D as DataModel } from './data-model-88af49fc.js';
import { T as TableConfig, d as decodeFields, S as Space } from './table-config-d73a72ab.js';
import { c as capitalize } from './string-3065a411.js';
import { U as User } from './User-72c4643a.js';

class MembershipConfig extends TableConfig {
  static decode(json) {
    const model = Object.assign(Object.create(MembershipConfig.prototype), json);
    model.fields = decodeFields(model.fields);
    model.space = Space.decode(model.space);
    return model;
  }
  roleNameCapital() {
    return capitalize(this.roleName);
  }
  ;
}

const isMembershipActive = (membership) => membership.status === 'active';
const doesMembershipNeedAgreementConsent = (membership) => {
  const agreements = membership.config.agreements || [];
  const consents = membership.consents || [];
  return agreements.filter(agreement => !consents.some(consent => consent.agreement._id === agreement._id)).length > 0;
};
const doesMembershipNeedDataCompletion = (membership) => {
  if (!membership.config.enforceRequiredInfo) {
    return false;
  }
  const fields = membership.config.fields || [];
  for (let i = 0; i < fields.length; i++) {
    const field = fields[i];
    if (field.required && !membership[field.id]) {
      return true;
    }
  }
  return false;
};
class Membership extends DataModel {
  static decode(json) {
    const model = Object.assign(Object.create(Membership.prototype), json);
    model.config = MembershipConfig.decode(model.config);
    model.user = model.user ? User.decode(model.user) : model.user;
    return model;
  }
  requireDataCompletion() {
    if (!this.config.enforceRequiredInfo) {
      return false;
    }
    const fields = this.config.fields || [];
    for (let i = 0; i < fields.length; i++) {
      const field = fields[i];
      if (field.required && !this[field.id]) {
        return true;
      }
    }
    return false;
  }
}

export { Membership as M, doesMembershipNeedDataCompletion as a, MembershipConfig as b, doesMembershipNeedAgreementConsent as d, isMembershipActive as i };
