(function (_, kotlin_kotlin) {
  'use strict';
  //region block: imports
  var protoOf = kotlin_kotlin.$_$.uc;
  var objectMeta = kotlin_kotlin.$_$.tc;
  var setMetadataFor = kotlin_kotlin.$_$.vc;
  var classMeta = kotlin_kotlin.$_$.jb;
  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.$_$.kj;
  var startsWith = kotlin_kotlin.$_$.yf;
  var last = kotlin_kotlin.$_$.g8;
  var removeLastOrNull = kotlin_kotlin.$_$.c9;
  var equals = kotlin_kotlin.$_$.mb;
  var indexOf = kotlin_kotlin.$_$.v7;
  var reverse = kotlin_kotlin.$_$.g9;
  var asList = kotlin_kotlin.$_$.oj;
  var emptyList = kotlin_kotlin.$_$.i7;
  var ArrayList_init_$Create$ = kotlin_kotlin.$_$.m;
  var Exception_init_$Create$ = kotlin_kotlin.$_$.n1;
  var contains = kotlin_kotlin.$_$.oe;
  var IndexOutOfBoundsException_init_$Create$ = kotlin_kotlin.$_$.d2;
  var interfaceMeta = kotlin_kotlin.$_$.vb;
  //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.i7i_1 = 0;
    this.j7i_1 = 1;
    this.k7i_1 = 2;
    this.l7i_1 = 3;
    this.m7i_1 = 4;
    this.n7i_1 = 5;
    this.o7i_1 = 10;
    this.p7i_1 = 6;
    this.q7i_1 = 'http://xmlpull.org/v1/doc/features.html#process-namespaces';
    this.r7i_1 = 'http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone';
    this.s7i_1 = 'http://xmlpull.org/v1/doc/properties.html#xmldecl-version';
  }
  var XmlPullParserConstants_instance;
  function XmlPullParserConstants_getInstance() {
    return XmlPullParserConstants_instance;
  }
  function ParserEvent() {
    this.t7i_1 = null;
    this.u7i_1 = -1;
    this.v7i_1 = -1;
  }
  function setInputString(_this__u8e3s4, xmlString) {
    return _this__u8e3s4.w7i(xmlString);
  }
  function Companion() {
    this.x7i_1 = 'http://xmlpull.org/v1/doc/features.html#validation';
    this.y7i_1 = 'http://xmlpull.org/v1/doc/features.html#process-namespaces';
  }
  protoOf(Companion).z7i = 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.a7j_1 = LinkedHashMap_init_$Create$();
  }
  protoOf(XmlPullParserFactory).b7j = function (name, state) {
    // Inline function 'kotlin.collections.set' call
    this.a7j_1.s(name, state);
  };
  protoOf(XmlPullParserFactory).c7j = function (awareness) {
    this.b7j('http://xmlpull.org/v1/doc/features.html#process-namespaces', awareness);
  };
  protoOf(XmlPullParserFactory).d7j = function () {
    var xpp = new XmlPullParserJsImpl();
    // Inline function 'kotlin.collections.forEach' call
    // Inline function 'kotlin.collections.iterator' call
    var tmp0_iterator = this.a7j_1.q2().w();
    while (tmp0_iterator.f()) {
      var element = tmp0_iterator.e();
      // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserFactory.newPullParser.<anonymous>' call
      xpp.b7j(element.s2(), element.t2());
    }
    return xpp;
  };
  protoOf(XmlPullParserFactory).n7j = function () {
    throw IllegalStateException_init_$Create$('Not available on Javascript yet');
  };
  function _get_treeWalker__49d1m1($this) {
    var tmp = $this.e7j_1;
    if (!(tmp == null))
      return tmp;
    else {
      throwUninitializedPropertyAccessException('treeWalker');
    }
  }
  function _get_document__ux3svk($this) {
    var tmp = $this.f7j_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.i7j_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.t7i_1 = $this.i7j_1;
        var tmp = this_0;
        tmp.v7i_1 = 4;
        this_0.u7i_1 = $this.h7j_1.u() + 1 | 0;
        $this.g7j_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.t7i_1 = $this.i7j_1;
      var tmp_0 = this_1;
      tmp_0.v7i_1 = 2;
      this_1.u7i_1 = $this.h7j_1.u() + 1 | 0;
      $this.g7j_1.i1(this_1);
      var tmp2_safe_receiver = $this.i7j_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.t7i_1 = $this.i7j_1;
        var tmp_1 = this_2;
        tmp_1.v7i_1 = 3;
        this_2.u7i_1 = $this.h7j_1.u() + 1 | 0;
        $this.g7j_1.i1(this_2);
      }
      var tmp_2;
      if ($this.h7j_1.c1()) {
        tmp_2 = true;
      } else {
        var tmp3_safe_receiver = $this.i7j_1;
        tmp_2 = (tmp3_safe_receiver == null ? null : tmp3_safe_receiver.hasChildNodes()) === true;
      }
      if (tmp_2) {
        var tmp4_safe_receiver = $this.i7j_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.h7j_1.i1(tmp4_safe_receiver);
        }
      }
      var currentParentNode = last($this.h7j_1);
      if (equals(currentParentNode.lastChild, $this.i7j_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.t7i_1 = currentParentNode;
        var tmp_3 = this_3;
        tmp_3.v7i_1 = 3;
        this_3.u7i_1 = $this.h7j_1.x(currentParentNode) + 1 | 0;
        $this.g7j_1.i1(this_3);
        removeLastOrNull($this.h7j_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.t7i_1 = currentParentNode.parentNode;
          var tmp_5 = this_4;
          tmp_5.v7i_1 = 3;
          this_4.u7i_1 = indexOf($this.h7j_1, currentParentNode.parentNode) + 1 | 0;
          $this.g7j_1.i1(this_4);
          removeLastOrNull($this.h7j_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.t7i_1 = $this.k7j_1;
      var tmp_6 = this_5;
      tmp_6.v7i_1 = 3;
      this_5.u7i_1 = $this.h7j_1.u() + 1 | 0;
      $this.g7j_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.t7i_1 = _get_treeWalker__49d1m1($this).root;
    var tmp_7 = this_6;
    tmp_7.v7i_1 = 0;
    $this.g7j_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.t7i_1 = _get_treeWalker__49d1m1($this).root;
    var tmp_8 = this_7;
    tmp_8.v7i_1 = 1;
    $this.g7j_1.i1(this_7);
    reverse($this.g7j_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.j7j_1 : event;
    var tmp2_safe_receiver = mElement == null ? null : mElement.t7i_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.t7i_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.i7j_1 = _get_treeWalker__49d1m1(this$0).nextNode();
      return this$0.i7j_1;
    };
  }
  function XmlPullParserJsImpl$logParserEvents$lambda_0(this$0) {
    return function () {
      this$0.k7j_1 = removeLastOrNull(this$0.h7j_1);
      return this$0.k7j_1;
    };
  }
  function XmlPullParserJsImpl() {
    var tmp = this;
    // Inline function 'kotlin.collections.mutableListOf' call
    tmp.g7j_1 = ArrayList_init_$Create$();
    var tmp_0 = this;
    // Inline function 'kotlin.collections.mutableListOf' call
    tmp_0.h7j_1 = ArrayList_init_$Create$();
    this.i7j_1 = null;
    this.j7j_1 = null;
    this.k7j_1 = null;
    this.l7j_1 = false;
    this.m7j_1 = true;
  }
  protoOf(XmlPullParserJsImpl).w7i = function (content) {
    this.f7j_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.e7j_1 = tmp_0.createTreeWalker(tmp_1, tmp_2, XmlPullParserJsImpl$setInput$lambda);
    logParserEvents(this);
  };
  protoOf(XmlPullParserJsImpl).o7j = function () {
    var tmp;
    var tmp0_safe_receiver = this.j7j_1;
    var tmp1_safe_receiver = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.t7i_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.j7j_1;
      var tmp4_safe_receiver = tmp3_safe_receiver == null ? null : tmp3_safe_receiver.t7i_1;
      tmp = tmp4_safe_receiver == null ? null : tmp4_safe_receiver.textContent;
    } else {
      tmp = null;
    }
    return tmp;
  };
  protoOf(XmlPullParserJsImpl).p7j = function () {
    var tmp0_safe_receiver = this.j7j_1;
    var tmp1_safe_receiver = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.t7i_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).q7j = function () {
    var tmp0_safe_receiver = this.j7j_1;
    var tmp1_elvis_lhs = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.v7i_1;
    return tmp1_elvis_lhs == null ? -1 : tmp1_elvis_lhs;
  };
  protoOf(XmlPullParserJsImpl).b7j = function (name, state) {
    if (XmlPullParserConstants_instance.q7i_1 === name)
      this.l7j_1 = state;
    else if (isProp(this, name, false, 'relaxed'))
      this.m7j_1 = state;
    else
      throw Exception_init_$Create$('unsupported feature: ' + name);
  };
  protoOf(XmlPullParserJsImpl).r7j = function (namespace, name) {
    var tmp;
    var tmp0_safe_receiver = this.j7j_1;
    var tmp_0 = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.v7i_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.j7j_1 = removeLastOrNull(this.g7j_1);
    var tmp0_safe_receiver = this.j7j_1;
    var tmp1_elvis_lhs = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.v7i_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
