(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.$_$.gj;
  var startsWith = kotlin_kotlin.$_$.wf;
  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.$_$.kj;
  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.q7b_1 = 0;
    this.r7b_1 = 1;
    this.s7b_1 = 2;
    this.t7b_1 = 3;
    this.u7b_1 = 4;
    this.v7b_1 = 5;
    this.w7b_1 = 10;
    this.x7b_1 = 6;
    this.y7b_1 = 'http://xmlpull.org/v1/doc/features.html#process-namespaces';
    this.z7b_1 = 'http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone';
    this.a7c_1 = 'http://xmlpull.org/v1/doc/properties.html#xmldecl-version';
  }
  var XmlPullParserConstants_instance;
  function XmlPullParserConstants_getInstance() {
    return XmlPullParserConstants_instance;
  }
  function ParserEvent() {
    this.b7c_1 = null;
    this.c7c_1 = -1;
    this.d7c_1 = -1;
  }
  function setInputString(_this__u8e3s4, xmlString) {
    return _this__u8e3s4.e7c(xmlString);
  }
  function Companion() {
    this.f7c_1 = 'http://xmlpull.org/v1/doc/features.html#validation';
    this.g7c_1 = 'http://xmlpull.org/v1/doc/features.html#process-namespaces';
  }
  protoOf(Companion).h7c = 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.i7c_1 = LinkedHashMap_init_$Create$();
  }
  protoOf(XmlPullParserFactory).j7c = function (name, state) {
    // Inline function 'kotlin.collections.set' call
    this.i7c_1.s(name, state);
  };
  protoOf(XmlPullParserFactory).k7c = function (awareness) {
    this.j7c('http://xmlpull.org/v1/doc/features.html#process-namespaces', awareness);
  };
  protoOf(XmlPullParserFactory).l7c = function () {
    var xpp = new XmlPullParserJsImpl();
    // Inline function 'kotlin.collections.forEach' call
    // Inline function 'kotlin.collections.iterator' call
    var tmp0_iterator = this.i7c_1.q2().w();
    while (tmp0_iterator.f()) {
      var element = tmp0_iterator.e();
      // Inline function 'com.ustadmobile.xmlpullparserkmp.XmlPullParserFactory.newPullParser.<anonymous>' call
      xpp.j7c(element.s2(), element.t2());
    }
    return xpp;
  };
  protoOf(XmlPullParserFactory).v7c = function () {
    throw IllegalStateException_init_$Create$('Not available on Javascript yet');
  };
  function _get_treeWalker__49d1m1($this) {
    var tmp = $this.m7c_1;
    if (!(tmp == null))
      return tmp;
    else {
      throwUninitializedPropertyAccessException('treeWalker');
    }
  }
  function _get_document__ux3svk($this) {
    var tmp = $this.n7c_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.q7c_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.b7c_1 = $this.q7c_1;
        var tmp = this_0;
        tmp.d7c_1 = 4;
        this_0.c7c_1 = $this.p7c_1.u() + 1 | 0;
        $this.o7c_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.b7c_1 = $this.q7c_1;
      var tmp_0 = this_1;
      tmp_0.d7c_1 = 2;
      this_1.c7c_1 = $this.p7c_1.u() + 1 | 0;
      $this.o7c_1.i1(this_1);
      var tmp2_safe_receiver = $this.q7c_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.b7c_1 = $this.q7c_1;
        var tmp_1 = this_2;
        tmp_1.d7c_1 = 3;
        this_2.c7c_1 = $this.p7c_1.u() + 1 | 0;
        $this.o7c_1.i1(this_2);
      }
      var tmp_2;
      if ($this.p7c_1.c1()) {
        tmp_2 = true;
      } else {
        var tmp3_safe_receiver = $this.q7c_1;
        tmp_2 = (tmp3_safe_receiver == null ? null : tmp3_safe_receiver.hasChildNodes()) === true;
      }
      if (tmp_2) {
        var tmp4_safe_receiver = $this.q7c_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.p7c_1.i1(tmp4_safe_receiver);
        }
      }
      var currentParentNode = last($this.p7c_1);
      if (equals(currentParentNode.lastChild, $this.q7c_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.b7c_1 = currentParentNode;
        var tmp_3 = this_3;
        tmp_3.d7c_1 = 3;
        this_3.c7c_1 = $this.p7c_1.x(currentParentNode) + 1 | 0;
        $this.o7c_1.i1(this_3);
        removeLastOrNull($this.p7c_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.b7c_1 = currentParentNode.parentNode;
          var tmp_5 = this_4;
          tmp_5.d7c_1 = 3;
          this_4.c7c_1 = indexOf($this.p7c_1, currentParentNode.parentNode) + 1 | 0;
          $this.o7c_1.i1(this_4);
          removeLastOrNull($this.p7c_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.b7c_1 = $this.s7c_1;
      var tmp_6 = this_5;
      tmp_6.d7c_1 = 3;
      this_5.c7c_1 = $this.p7c_1.u() + 1 | 0;
      $this.o7c_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.b7c_1 = _get_treeWalker__49d1m1($this).root;
    var tmp_7 = this_6;
    tmp_7.d7c_1 = 0;
    $this.o7c_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.b7c_1 = _get_treeWalker__49d1m1($this).root;
    var tmp_8 = this_7;
    tmp_8.d7c_1 = 1;
    $this.o7c_1.i1(this_7);
    reverse($this.o7c_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.r7c_1 : event;
    var tmp2_safe_receiver = mElement == null ? null : mElement.b7c_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.b7c_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.q7c_1 = _get_treeWalker__49d1m1(this$0).nextNode();
      return this$0.q7c_1;
    };
  }
  function XmlPullParserJsImpl$logParserEvents$lambda_0(this$0) {
    return function () {
      this$0.s7c_1 = removeLastOrNull(this$0.p7c_1);
      return this$0.s7c_1;
    };
  }
  function XmlPullParserJsImpl() {
    var tmp = this;
    // Inline function 'kotlin.collections.mutableListOf' call
    tmp.o7c_1 = ArrayList_init_$Create$();
    var tmp_0 = this;
    // Inline function 'kotlin.collections.mutableListOf' call
    tmp_0.p7c_1 = ArrayList_init_$Create$();
    this.q7c_1 = null;
    this.r7c_1 = null;
    this.s7c_1 = null;
    this.t7c_1 = false;
    this.u7c_1 = true;
  }
  protoOf(XmlPullParserJsImpl).e7c = function (content) {
    this.n7c_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.m7c_1 = tmp_0.createTreeWalker(tmp_1, tmp_2, XmlPullParserJsImpl$setInput$lambda);
    logParserEvents(this);
  };
  protoOf(XmlPullParserJsImpl).w7c = function () {
    var tmp;
    var tmp0_safe_receiver = this.r7c_1;
    var tmp1_safe_receiver = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.b7c_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.r7c_1;
      var tmp4_safe_receiver = tmp3_safe_receiver == null ? null : tmp3_safe_receiver.b7c_1;
      tmp = tmp4_safe_receiver == null ? null : tmp4_safe_receiver.textContent;
    } else {
      tmp = null;
    }
    return tmp;
  };
  protoOf(XmlPullParserJsImpl).x7c = function () {
    var tmp0_safe_receiver = this.r7c_1;
    var tmp1_safe_receiver = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.b7c_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).y7c = function () {
    var tmp0_safe_receiver = this.r7c_1;
    var tmp1_elvis_lhs = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.d7c_1;
    return tmp1_elvis_lhs == null ? -1 : tmp1_elvis_lhs;
  };
  protoOf(XmlPullParserJsImpl).j7c = function (name, state) {
    if (XmlPullParserConstants_instance.y7b_1 === name)
      this.t7c_1 = state;
    else if (isProp(this, name, false, 'relaxed'))
      this.u7c_1 = state;
    else
      throw Exception_init_$Create$('unsupported feature: ' + name);
  };
  protoOf(XmlPullParserJsImpl).z7c = function (namespace, name) {
    var tmp;
    var tmp0_safe_receiver = this.r7c_1;
    var tmp_0 = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.d7c_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.r7c_1 = removeLastOrNull(this.o7c_1);
    var tmp0_safe_receiver = this.r7c_1;
    var tmp1_elvis_lhs = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.d7c_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
