"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var framepay_error_1 = __importDefault(require("../../framepay-error"));
var base_element_1 = __importDefault(require("./base-element"));
var IBANElement = /** @class */ (function (_super) {
    __extends(IBANElement, _super);
    function IBANElement() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    IBANElement.prototype.setupElement = function () {
        var _this = this;
        var _a = this.props, onReady = _a.onReady, onChange = _a.onChange, onFocus = _a.onFocus, onBlur = _a.onBlur, elementType = _a.elementType;
        var makeElement = function () {
            // elementNode already checked in BaseElement.handleSetupElement
            // just ts checks fix
            if (!_this.elementNode) {
                throw (0, framepay_error_1.default)({
                    code: framepay_error_1.default.codes.elementMountError,
                    details: "IBANElement invalid elementNode, elementType: ".concat(elementType || 'default'),
                });
            }
            try {
                return _this.props.Framepay.iban.mount(_this.elementNode);
            }
            catch (e) {
                throw (0, framepay_error_1.default)({
                    code: framepay_error_1.default.codes.elementMountError,
                    details: "IBANElement error in remote api call, elementType: ".concat(elementType || 'default'),
                    trace: e,
                });
            }
        };
        var element = makeElement();
        try {
            element.on('ready', function () {
                _this.setState({ ready: true }, function () {
                    if (onReady) {
                        onReady();
                    }
                });
            });
            element.on('change', function (data) {
                if (onChange) {
                    onChange(data);
                }
            });
            element.on('focus', function () {
                if (onFocus) {
                    onFocus();
                }
            });
            element.on('blur', function () {
                if (onBlur) {
                    onBlur();
                }
            });
            this.setState({ element: element });
        }
        catch (e) {
            throw (0, framepay_error_1.default)({
                code: framepay_error_1.default.codes.elementMountError,
                details: "IBANElement events binding error, elementType: ".concat(elementType || 'default'),
                trace: e,
            });
        }
    };
    IBANElement.prototype.render = function () {
        var _this = this;
        return (React.createElement("div", { ref: function (node) {
                _this.elementNode = node;
            } }));
    };
    return IBANElement;
}(base_element_1.default));
exports.default = IBANElement;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaWJhbi1lbGVtZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2xpYi9jb21wb25lbnRzL2VsZW1lbnRzL2liYW4tZWxlbWVudC50c3giXSwibm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