(function (_, kotlin_kotlin) {
  'use strict';
  //region block: imports
  var protoOf = kotlin_kotlin.$_$.wc;
  var objectMeta = kotlin_kotlin.$_$.vc;
  var setMetadataFor = kotlin_kotlin.$_$.xc;
  var classMeta = kotlin_kotlin.$_$.lb;
  var VOID = kotlin_kotlin.$_$.f;
  var LinkedHashMap_init_$Create$ = kotlin_kotlin.$_$.v;
  var Unit_instance = kotlin_kotlin.$_$.m5;
  var IllegalStateException_init_$Create$ = kotlin_kotlin.$_$.a2;
  var throwUninitializedPropertyAccessException = kotlin_kotlin.$_$.lj;
  var startsWith = kotlin_kotlin.$_$.ag;
  var last = kotlin_kotlin.$_$.h8;
  var removeLastOrNull = kotlin_kotlin.$_$.e9;
  var equals = kotlin_kotlin.$_$.ob;
  var indexOf = kotlin_kotlin.$_$.w7;
  var reverse = kotlin_kotlin.$_$.i9;
  var asList = kotlin_kotlin.$_$.pj;
  var emptyList = kotlin_kotlin.$_$.i7;
  var ArrayList_init_$Create$ = kotlin_kotlin.$_$.m;
  var Exception_init_$Create$ = kotlin_kotlin.$_$.n1;
  var contains = kotlin_kotlin.$_$.qe;
  var IndexOutOfBoundsException_init_$Create$ = kotlin_kotlin.$_$.d2;
  var interfaceMeta = kotlin_kotlin.$_$.xb;
  //endregion
  //region block: pre-declaration
  setMetadataFor(XmlPullParserConstants, 'XmlPullParserConstants', objectMeta);
  setMetadataFor(ParserEvent, 'ParserEvent', classMeta, VOID, VOID, ParserEvent);
  setMetadataFor(Companion, 'Companion', objectMeta);
  setMetadataFor(XmlPullParserFactory, 'XmlPullParserFactory', classMeta, VOID, VOID, XmlPullParserFactory);
  setMetadataFor(XmlPullParserJsImpl, 'XmlPullParserJsImpl', classMeta, VOID, VOID, XmlPullParserJsImpl);
  setMetadataFor(XmlSerializer, 'XmlSerializer', interfaceMeta);
  //endregion
  function XmlPullParserConstants() {
    this.d7c_1 = 0;
    this.e7c_1 = 1;
    this.f7c_1 = 2;
    this.g7c_1 = 3;
    this.h7c_1 = 4;
    this.i7c_1 = 5;
    this.j7c_1 = 10;
    this.k7c_1 = 6;
    this.l7c_1 = 'http://xmlpull.org/v1/doc/features.html#process-namespaces';
    this.m7c_1 = 'http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone';
    this.n7c_1 = 'http://xmlpull.org/v1/doc/properties.html#xmldecl-version';
  }
  var XmlPullParserConstants_instance;
  function XmlPullParserConstants_getInstance() {
    return XmlPullParserConstants_instance;
  }
  function ParserEvent() {
    this.o7c_1 = null;
    this.p7c_1 = -1;
    this.q7c_1 = -1;
  }
  function setInputString(_this__u8e3s4, xmlString) {
    return _this__u8e3s4.r7c(xmlString);
  }
  function Companion() {
    this.s7c_1 = 'http://xmlpull.org/v1/doc/features.html#validation';
    this.t7c_1 = 'http://xmlpull.org/v1/doc/features.html#process-namespaces';
  }
  protoOf(Companion).u7c = function () {
    return new XmlPullParserFactory();
  };
  var Companion_instance;
  function Companion_getInstance() {
    return Companion_instance;
  }
  function XmlPullParserFactory() {
    var tmp = this;
    // Inline function 'kotlin.collections.mutableMapOf' call
    tmp.v7c_1 = LinkedHashMap_init_$Create$();
  }
  protoOf(XmlPullParserFactory).w7c = function (name, state) {
    // Inline function 'kotlin.collections.set' call
    this.v7c_1.s(name, state);
  };
  protoOf(XmlPullParserFactory).x7c = function (awareness) {
    this.w7c('http://xmlpull.org/v1/doc/features.html#process-namespaces', awareness);
  };
  protoOf(XmlPullParserFactory).y7c = function () {
    var xpp = new XmlPullParserJsImpl();
    // Inline function 'kotlin.collections.forEach' call
    // Inline function 'kotlin.collections.iterator' call
    var tmp0_iterator = this.v7c_1.q2().w();
    while (tmp0_iterator.f()) {
      var element = tmp0_iterator.e();
      // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserFactory.newPullParser.<anonymous>' call
      xpp.w7c(element.s2(), element.t2());
    }
    return xpp;
  };
  protoOf(XmlPullParserFactory).i7d = function () {
    throw IllegalStateException_init_$Create$('Not available on Javascript yet');
  };
  function _get_treeWalker__49d1m1($this) {
    var tmp = $this.z7c_1;
    if (!(tmp == null))
      return tmp;
    else {
      throwUninitializedPropertyAccessException('treeWalker');
    }
  }
  function _get_document__ux3svk($this) {
    var tmp = $this.a7d_1;
    if (!(tmp == null))
      return tmp;
    else {
      throwUninitializedPropertyAccessException('document');
    }
  }
  function isProp($this, ns1, prop, ns2) {
    if (!startsWith(ns1, 'http://xmlpull.org/v1/doc/'))
      return false;
    var tmp;
    if (prop) {
      // Inline function 'kotlin.text.substring' call
      // Inline function 'kotlin.js.asDynamic' call
      tmp = ns1.substring(42) === ns2;
    } else {
      // Inline function 'kotlin.text.substring' call
      // Inline function 'kotlin.js.asDynamic' call
      tmp = ns1.substring(40) === ns2;
    }
    return tmp;
  }
  function logParserEvents($this) {
    $l$loop: while (!(XmlPullParserJsImpl$logParserEvents$lambda($this)() == null)) {
      var tmp0_safe_receiver = $this.d7d_1;
      var tmp1_safe_receiver = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.nodeType;
      if ((tmp1_safe_receiver == null ? null : tmp1_safe_receiver) === Node.TEXT_NODE) {
        // Inline function 'kotlin.apply' call
        var this_0 = new ParserEvent();
        // Inline function 'kotlin.contracts.contract' call
        // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserJsImpl.logParserEvents.<anonymous>' call
        this_0.o7c_1 = $this.d7d_1;
        var tmp = this_0;
        tmp.q7c_1 = 4;
        this_0.p7c_1 = $this.c7d_1.u() + 1 | 0;
        $this.b7d_1.i1(this_0);
      }
      // Inline function 'kotlin.apply' call
      var this_1 = new ParserEvent();
      // Inline function 'kotlin.contracts.contract' call
      // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserJsImpl.logParserEvents.<anonymous>' call
      this_1.o7c_1 = $this.d7d_1;
      var tmp_0 = this_1;
      tmp_0.q7c_1 = 2;
      this_1.p7c_1 = $this.c7d_1.u() + 1 | 0;
      $this.b7d_1.i1(this_1);
      var tmp2_safe_receiver = $this.d7d_1;
      if ((tmp2_safe_receiver == null ? null : tmp2_safe_receiver.hasChildNodes()) === false) {
        // Inline function 'kotlin.apply' call
        var this_2 = new ParserEvent();
        // Inline function 'kotlin.contracts.contract' call
        // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserJsImpl.logParserEvents.<anonymous>' call
        this_2.o7c_1 = $this.d7d_1;
        var tmp_1 = this_2;
        tmp_1.q7c_1 = 3;
        this_2.p7c_1 = $this.c7d_1.u() + 1 | 0;
        $this.b7d_1.i1(this_2);
      }
      var tmp_2;
      if ($this.c7d_1.c1()) {
        tmp_2 = true;
      } else {
        var tmp3_safe_receiver = $this.d7d_1;
        tmp_2 = (tmp3_safe_receiver == null ? null : tmp3_safe_receiver.hasChildNodes()) === true;
      }
      if (tmp_2) {
        var tmp4_safe_receiver = $this.d7d_1;
        if (tmp4_safe_receiver == null)
          null;
        else {
          // Inline function 'kotlin.let' call
          // Inline function 'kotlin.contracts.contract' call
          // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserJsImpl.logParserEvents.<anonymous>' call
          $this.c7d_1.i1(tmp4_safe_receiver);
        }
      }
      var currentParentNode = last($this.c7d_1);
      if (equals(currentParentNode.lastChild, $this.d7d_1)) {
        // Inline function 'kotlin.apply' call
        var this_3 = new ParserEvent();
        // Inline function 'kotlin.contracts.contract' call
        // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserJsImpl.logParserEvents.<anonymous>' call
        this_3.o7c_1 = currentParentNode;
        var tmp_3 = this_3;
        tmp_3.q7c_1 = 3;
        this_3.p7c_1 = $this.c7d_1.x(currentParentNode) + 1 | 0;
        $this.b7d_1.i1(this_3);
        removeLastOrNull($this.c7d_1);
        var tmp_4;
        var tmp5_safe_receiver = currentParentNode.parentNode;
        if (!((tmp5_safe_receiver == null ? null : tmp5_safe_receiver.nextSibling) == null)) {
          var tmp6_safe_receiver = currentParentNode.parentNode;
          tmp_4 = equals(tmp6_safe_receiver == null ? null : tmp6_safe_receiver.lastChild, currentParentNode);
        } else {
          tmp_4 = false;
        }
        if (tmp_4) {
          // Inline function 'kotlin.apply' call
          var this_4 = new ParserEvent();
          // Inline function 'kotlin.contracts.contract' call
          // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserJsImpl.logParserEvents.<anonymous>' call
          this_4.o7c_1 = currentParentNode.parentNode;
          var tmp_5 = this_4;
          tmp_5.q7c_1 = 3;
          this_4.p7c_1 = indexOf($this.c7d_1, currentParentNode.parentNode) + 1 | 0;
          $this.b7d_1.i1(this_4);
          removeLastOrNull($this.c7d_1);
        }
      }
    }
    $l$loop_0: while (!(XmlPullParserJsImpl$logParserEvents$lambda_0($this)() == null)) {
      // Inline function 'kotlin.apply' call
      var this_5 = new ParserEvent();
      // Inline function 'kotlin.contracts.contract' call
      // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserJsImpl.logParserEvents.<anonymous>' call
      this_5.o7c_1 = $this.f7d_1;
      var tmp_6 = this_5;
      tmp_6.q7c_1 = 3;
      this_5.p7c_1 = $this.c7d_1.u() + 1 | 0;
      $this.b7d_1.i1(this_5);
    }
    // Inline function 'kotlin.apply' call
    var this_6 = new ParserEvent();
    // Inline function 'kotlin.contracts.contract' call
    // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserJsImpl.logParserEvents.<anonymous>' call
    this_6.o7c_1 = _get_treeWalker__49d1m1($this).root;
    var tmp_7 = this_6;
    tmp_7.q7c_1 = 0;
    $this.b7d_1.c2(0, this_6);
    // Inline function 'kotlin.apply' call
    var this_7 = new ParserEvent();
    // Inline function 'kotlin.contracts.contract' call
    // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserJsImpl.logParserEvents.<anonymous>' call
    this_7.o7c_1 = _get_treeWalker__49d1m1($this).root;
    var tmp_8 = this_7;
    tmp_8.q7c_1 = 1;
    $this.b7d_1.i1(this_7);
    reverse($this.b7d_1);
  }
  function getAttributes($this) {
    var tmp0_safe_receiver = getCurrentEventElement$default($this);
    var tmp1_safe_receiver = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.attributes;
    var tmp2_elvis_lhs = tmp1_safe_receiver == null ? null : asList(tmp1_safe_receiver);
    var tmp;
    if (tmp2_elvis_lhs == null) {
      // Inline function 'kotlin.collections.listOf' call
      tmp = emptyList();
    } else {
      tmp = tmp2_elvis_lhs;
    }
    return tmp;
  }
  function getCurrentEventElement($this, event) {
    var mElement = event == null ? $this.e7d_1 : event;
    var tmp2_safe_receiver = mElement == null ? null : mElement.o7c_1;
    if (tmp2_safe_receiver == null)
      null;
    else
      tmp2_safe_receiver.appendChild(_get_document__ux3svk($this).createTextNode('text'));
    var tmp4_safe_receiver = mElement == null ? null : mElement.o7c_1;
    var tmp5_safe_receiver = tmp4_safe_receiver == null ? null : tmp4_safe_receiver.lastChild;
    return tmp5_safe_receiver == null ? null : tmp5_safe_receiver.parentElement;
  }
  function getCurrentEventElement$default($this, event, $super) {
    event = event === VOID ? null : event;
    return getCurrentEventElement($this, event);
  }
  function XmlPullParserJsImpl$setInput$lambda(it) {
    return NodeFilter.FILTER_ACCEPT;
  }
  function XmlPullParserJsImpl$logParserEvents$lambda(this$0) {
    return function () {
      this$0.d7d_1 = _get_treeWalker__49d1m1(this$0).nextNode();
      return this$0.d7d_1;
    };
  }
  function XmlPullParserJsImpl$logParserEvents$lambda_0(this$0) {
    return function () {
      this$0.f7d_1 = removeLastOrNull(this$0.c7d_1);
      return this$0.f7d_1;
    };
  }
  function XmlPullParserJsImpl() {
    var tmp = this;
    // Inline function 'kotlin.collections.mutableListOf' call
    tmp.b7d_1 = ArrayList_init_$Create$();
    var tmp_0 = this;
    // Inline function 'kotlin.collections.mutableListOf' call
    tmp_0.c7d_1 = ArrayList_init_$Create$();
    this.d7d_1 = null;
    this.e7d_1 = null;
    this.f7d_1 = null;
    this.g7d_1 = false;
    this.h7d_1 = true;
  }
  protoOf(XmlPullParserJsImpl).r7c = function (content) {
    this.a7d_1 = (new DOMParser()).parseFromString(content, 'text/' + (startsWith(content, '<?xml') ? 'xml' : 'html'));
    var tmp = this;
    var tmp_0 = _get_document__ux3svk(this);
    var tmp_1 = _get_document__ux3svk(this);
    var tmp_2 = NodeFilter.SHOW_ALL;
    tmp.z7c_1 = tmp_0.createTreeWalker(tmp_1, tmp_2, XmlPullParserJsImpl$setInput$lambda);
    logParserEvents(this);
  };
  protoOf(XmlPullParserJsImpl).j7d = function () {
    var tmp;
    var tmp0_safe_receiver = this.e7d_1;
    var tmp1_safe_receiver = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.o7c_1;
    var tmp2_safe_receiver = tmp1_safe_receiver == null ? null : tmp1_safe_receiver.nodeType;
    if ((tmp2_safe_receiver == null ? null : tmp2_safe_receiver) === Node.TEXT_NODE) {
      var tmp3_safe_receiver = this.e7d_1;
      var tmp4_safe_receiver = tmp3_safe_receiver == null ? null : tmp3_safe_receiver.o7c_1;
      tmp = tmp4_safe_receiver == null ? null : tmp4_safe_receiver.textContent;
    } else {
      tmp = null;
    }
    return tmp;
  };
  protoOf(XmlPullParserJsImpl).k7d = function () {
    var tmp0_safe_receiver = this.e7d_1;
    var tmp1_safe_receiver = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.o7c_1;
    var tmp2_safe_receiver = tmp1_safe_receiver == null ? null : tmp1_safe_receiver.nodeName;
    var tmp;
    if (tmp2_safe_receiver == null) {
      tmp = null;
    } else {
      // Inline function 'kotlin.text.lowercase' call
      // Inline function 'kotlin.js.asDynamic' call
      tmp = tmp2_safe_receiver.toLowerCase();
    }
    return tmp;
  };
  protoOf(XmlPullParserJsImpl).l7d = function () {
    var tmp0_safe_receiver = this.e7d_1;
    var tmp1_elvis_lhs = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.q7c_1;
    return tmp1_elvis_lhs == null ? -1 : tmp1_elvis_lhs;
  };
  protoOf(XmlPullParserJsImpl).w7c = function (name, state) {
    if (XmlPullParserConstants_instance.l7c_1 === name)
      this.g7d_1 = state;
    else if (isProp(this, name, false, 'relaxed'))
      this.h7d_1 = state;
    else
      throw Exception_init_$Create$('unsupported feature: ' + name);
  };
  protoOf(XmlPullParserJsImpl).m7d = function (namespace, name) {
    var tmp;
    var tmp0_safe_receiver = this.e7d_1;
    var tmp_0 = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.q7c_1;
    if (!(tmp_0 === 2)) {
      throw IndexOutOfBoundsException_init_$Create$();
    } else {
      var tmp$ret$1;
      $l$block: {
        // Inline function 'kotlin.collections.firstOrNull' call
        var tmp0_iterator = getAttributes(this).w();
        while (tmp0_iterator.f()) {
          var element = tmp0_iterator.e();
          // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserJsImpl.getAttributeValue.<anonymous>' call
          if ((element.name === name ? true : contains(element.name, name)) ? element.namespaceURI == null ? true : element.namespaceURI == namespace : false) {
            tmp$ret$1 = element;
            break $l$block;
          }
        }
        tmp$ret$1 = null;
      }
      var tmp1_safe_receiver = tmp$ret$1;
      tmp = tmp1_safe_receiver == null ? null : tmp1_safe_receiver.value;
    }
    return tmp;
  };
  protoOf(XmlPullParserJsImpl).e = function () {
    this.e7d_1 = removeLastOrNull(this.b7d_1);
    var tmp0_safe_receiver = this.e7d_1;
    var tmp1_elvis_lhs = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.q7c_1;
    return tmp1_elvis_lhs == null ? -1 : tmp1_elvis_lhs;
  };
  function XmlSerializer() {
  }
  //region block: init
  XmlPullParserConstants_instance = new XmlPullParserConstants();
  Companion_instance = new Companion();
  //endregion
  //region block: exports
  _.$_$ = _.$_$ || {};
  _.$_$.a = XmlPullParserFactory;
  _.$_$.b = XmlSerializer;
  _.$_$.c = setInputString;
  _.$_$.d = XmlPullParserConstants_instance;
  _.$_$.e = Companion_instance;
  //endregion
  return _;
}(module.exports, require('./kotlin-kotlin-stdlib.js')));

//# sourceMappingURL=xmlpullparserkmp.js.map
