var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/// <reference path="IRequestWriter.ts"/>
/// <reference path="../../base/BaseClass.ts"/>
var econda;
(function (econda) {
    var ajax;
    (function (ajax) {
        var writer;
        (function (writer) {
            /**
             * Encode request data as form url encoded post payload. Do not use this class directly. See {@link econda.ajax.Request} for details.
             *
             *     econda.Ajax.request({
             *         uri: 'http://www.econda.de',
             *         method: 'post',
             *         data: { myparam: 'myvalue' },
             *         writer: 'form-encoded'
             *     });
             *
             * @class econda.ajax.writer.FormEncodedWriter
             */
            var FormEncodedWriter = (function (_super) {
                __extends(FormEncodedWriter, _super);
                function FormEncodedWriter() {
                    _super.apply(this, arguments);
                    this._data = null;
                }
                FormEncodedWriter.prototype.setData = function (data) {
                    this._data = data;
                    return this;
                };
                FormEncodedWriter.prototype.getHeaders = function () {
                    return {
                        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
                    };
                };
                FormEncodedWriter.prototype.getBody = function () {
                    var arr = [], str, data = this._data;
                    for (var name in data) {
                        if (econda.util.ArrayUtils.isArray(data[name])) {
                            for (var i = 0; i < data[name].length; i++) {
                                arr.push(name + '=' + encodeURIComponent(data[name][i]));
                            }
                        }
                        else {
                            arr.push(name + '=' + encodeURIComponent(data[name]));
                        }
                    }
                    str = arr.join('&');
                    return str;
                };
                return FormEncodedWriter;
            }(econda.base.BaseClass));
            writer.FormEncodedWriter = FormEncodedWriter; // end of class
        })(writer = ajax.writer || (ajax.writer = {}));
    })(ajax = econda.ajax || (econda.ajax = {}));
})(econda || (econda = {})); // end of module