'use strict';

var _commonjsHelpers = require('../../../_virtual/_commonjsHelpers.js');
var XMLDocType = require('../../../_virtual/XMLDocType.js');
var Utility = require('./Utility.js');
var XMLNode = require('./XMLNode.js');
var NodeType = require('./NodeType.js');
var XMLDTDAttList = require('./XMLDTDAttList.js');
var XMLDTDEntity = require('./XMLDTDEntity.js');
var XMLDTDElement = require('./XMLDTDElement.js');
var XMLDTDNotation = require('./XMLDTDNotation.js');
var XMLNamedNodeMap = require('./XMLNamedNodeMap.js');

var hasRequiredXMLDocType;

function requireXMLDocType () {
	if (hasRequiredXMLDocType) return XMLDocType.__module.exports;
	hasRequiredXMLDocType = 1;
	// Generated by CoffeeScript 1.12.7
	(function() {
	  var NodeType$1, XMLDTDAttList$1, XMLDTDElement$1, XMLDTDEntity$1, XMLDTDNotation$1, XMLNamedNodeMap$1, XMLNode$1, isObject,
	    extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
	    hasProp = {}.hasOwnProperty;

	  isObject = Utility.__require().isObject;

	  XMLNode$1 = XMLNode.__require();

	  NodeType$1 = NodeType.__require();

	  XMLDTDAttList$1 = XMLDTDAttList.__require();

	  XMLDTDEntity$1 = XMLDTDEntity.__require();

	  XMLDTDElement$1 = XMLDTDElement.__require();

	  XMLDTDNotation$1 = XMLDTDNotation.__require();

	  XMLNamedNodeMap$1 = XMLNamedNodeMap.__require();

	  XMLDocType.__module.exports = (function(superClass) {
	    extend(XMLDocType, superClass);

	    function XMLDocType(parent, pubID, sysID) {
	      var child, i, len, ref, ref1, ref2;
	      XMLDocType.__super__.constructor.call(this, parent);
	      this.type = NodeType$1.DocType;
	      if (parent.children) {
	        ref = parent.children;
	        for (i = 0, len = ref.length; i < len; i++) {
	          child = ref[i];
	          if (child.type === NodeType$1.Element) {
	            this.name = child.name;
	            break;
	          }
	        }
	      }
	      this.documentObject = parent;
	      if (isObject(pubID)) {
	        ref1 = pubID, pubID = ref1.pubID, sysID = ref1.sysID;
	      }
	      if (sysID == null) {
	        ref2 = [pubID, sysID], sysID = ref2[0], pubID = ref2[1];
	      }
	      if (pubID != null) {
	        this.pubID = this.stringify.dtdPubID(pubID);
	      }
	      if (sysID != null) {
	        this.sysID = this.stringify.dtdSysID(sysID);
	      }
	    }

	    Object.defineProperty(XMLDocType.prototype, 'entities', {
	      get: function() {
	        var child, i, len, nodes, ref;
	        nodes = {};
	        ref = this.children;
	        for (i = 0, len = ref.length; i < len; i++) {
	          child = ref[i];
	          if ((child.type === NodeType$1.EntityDeclaration) && !child.pe) {
	            nodes[child.name] = child;
	          }
	        }
	        return new XMLNamedNodeMap$1(nodes);
	      }
	    });

	    Object.defineProperty(XMLDocType.prototype, 'notations', {
	      get: function() {
	        var child, i, len, nodes, ref;
	        nodes = {};
	        ref = this.children;
	        for (i = 0, len = ref.length; i < len; i++) {
	          child = ref[i];
	          if (child.type === NodeType$1.NotationDeclaration) {
	            nodes[child.name] = child;
	          }
	        }
	        return new XMLNamedNodeMap$1(nodes);
	      }
	    });

	    Object.defineProperty(XMLDocType.prototype, 'publicId', {
	      get: function() {
	        return this.pubID;
	      }
	    });

	    Object.defineProperty(XMLDocType.prototype, 'systemId', {
	      get: function() {
	        return this.sysID;
	      }
	    });

	    Object.defineProperty(XMLDocType.prototype, 'internalSubset', {
	      get: function() {
	        throw new Error("This DOM method is not implemented." + this.debugInfo());
	      }
	    });

	    XMLDocType.prototype.element = function(name, value) {
	      var child;
	      child = new XMLDTDElement$1(this, name, value);
	      this.children.push(child);
	      return this;
	    };

	    XMLDocType.prototype.attList = function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
	      var child;
	      child = new XMLDTDAttList$1(this, elementName, attributeName, attributeType, defaultValueType, defaultValue);
	      this.children.push(child);
	      return this;
	    };

	    XMLDocType.prototype.entity = function(name, value) {
	      var child;
	      child = new XMLDTDEntity$1(this, false, name, value);
	      this.children.push(child);
	      return this;
	    };

	    XMLDocType.prototype.pEntity = function(name, value) {
	      var child;
	      child = new XMLDTDEntity$1(this, true, name, value);
	      this.children.push(child);
	      return this;
	    };

	    XMLDocType.prototype.notation = function(name, value) {
	      var child;
	      child = new XMLDTDNotation$1(this, name, value);
	      this.children.push(child);
	      return this;
	    };

	    XMLDocType.prototype.toString = function(options) {
	      return this.options.writer.docType(this, this.options.writer.filterOptions(options));
	    };

	    XMLDocType.prototype.ele = function(name, value) {
	      return this.element(name, value);
	    };

	    XMLDocType.prototype.att = function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
	      return this.attList(elementName, attributeName, attributeType, defaultValueType, defaultValue);
	    };

	    XMLDocType.prototype.ent = function(name, value) {
	      return this.entity(name, value);
	    };

	    XMLDocType.prototype.pent = function(name, value) {
	      return this.pEntity(name, value);
	    };

	    XMLDocType.prototype.not = function(name, value) {
	      return this.notation(name, value);
	    };

	    XMLDocType.prototype.up = function() {
	      return this.root() || this.documentObject;
	    };

	    XMLDocType.prototype.isEqualNode = function(node) {
	      if (!XMLDocType.__super__.isEqualNode.apply(this, arguments).isEqualNode(node)) {
	        return false;
	      }
	      if (node.name !== this.name) {
	        return false;
	      }
	      if (node.publicId !== this.publicId) {
	        return false;
	      }
	      if (node.systemId !== this.systemId) {
	        return false;
	      }
	      return true;
	    };

	    return XMLDocType;

	  })(XMLNode$1);

	}).call(_commonjsHelpers.commonjsGlobal);
	return XMLDocType.__module.exports;
}

exports.__require = requireXMLDocType;
