import '../../utils/types/array.js';
import 'crypto';
import { isEqualToOrPrototypeOf } from '../../utils/inheritance.js';
import 'bs58';
import 'multiformats/bases/base58';
import 'varint';
import '../../utils/encoding/ss-58.js';
import TypedEnum from './typed-enum.js';
import TypedStruct from './typed-struct.js';
import '../../utils/types/object.js';
import '../../utils/types/iterable.js';
import '../../utils/types/set.js';
import 'blake2b';
import '../../utils/types/bytes.js';
import '../../utils/interfaces.js';
import '../../utils/assert.js';
import '../../utils/error.js';
import '../../utils/types/string.js';
import './with-base.js';
import './with-catch-null.js';
import './with-eq.js';
import './any-of.js';
import './with-from.js';
import './with-from-json-bytes.js';
import './typed-null.js';
import './create-placeholder.js';

/**
 * Extends supplied class which must be a successor of `TypedStruct`/`TypedEnum` by removing
 * its property.
 *
 * @template C
 * @template K
 * @param {C} klass
 * @param {string} prop
 * @param {K} PropClass
 * @param {function(*, string, K): *} handleNested
 * @returns {C}
 */
function withoutProp(klass, prop, handleNested = withoutProp) {
  const name = `withoutProp(${klass.name}, ${prop})`;
  const isStruct = isEqualToOrPrototypeOf(TypedStruct, klass);
  const isEnum = isEqualToOrPrototypeOf(TypedEnum, klass);
  if (!isStruct && !isEnum) {
    throw new Error(`Unexpected class provided: \`${klass}\``);
  }

  if (isStruct) {
    const { [prop]: _, ...classes } = klass.Classes;

    const obj = {
      [name]: class extends klass {
        static Classes = classes;
      },
    };

    return obj[name];
  } else {
    let classWithProp = klass.Class;
    let variants = klass.Variants;
    if (classWithProp != null) {
      classWithProp = handleNested(klass.Class, prop);
    } else {
      variants = variants.map((variant) => handleNested(variant, prop));
    }

    const obj = {
      [name]: class extends klass {
        static Class = classWithProp;

        static Variants = variants;
      },
    };

    return obj[name];
  }
}

export { withoutProp as default };
//# sourceMappingURL=without-prop.js.map
