import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Prop } from 'vue-property-decorator';
import { AddressField, CountryKey, ProvinceKey } from '../../../utils/address-lookup/address';
import { ModulVue } from '../../../utils/vue/vue';
import WithRender from './address-reader.html';
var MAddressReader = /** @class */ (function (_super) {
    __extends(MAddressReader, _super);
    function MAddressReader() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Object.defineProperty(MAddressReader.prototype, "buildingNumber", {
        get: function () {
            return this.filterString(AddressField.BUILDING_NUMBER);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAddressReader.prototype, "street", {
        get: function () {
            return this.filterString(AddressField.STREET);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAddressReader.prototype, "city", {
        get: function () {
            return this.filterString(AddressField.CITY);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAddressReader.prototype, "postalCode", {
        get: function () {
            return this.filterString(AddressField.POSTAL_CODE);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAddressReader.prototype, "subBuilding", {
        get: function () {
            return this.filterString(AddressField.SUB_BUILDING);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAddressReader.prototype, "country", {
        get: function () {
            return this.filterString(AddressField.COUNTRY, this.countryKey);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAddressReader.prototype, "province", {
        get: function () {
            return this.filterString(AddressField.PROVINCE, this.provinceKey);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAddressReader.prototype, "hasProvince", {
        get: function () {
            return this.filterString(AddressField.PROVINCE, this.provinceKey).length > 0;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAddressReader.prototype, "isEstablishment", {
        get: function () {
            return this.address.isEstablishment;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAddressReader.prototype, "name", {
        get: function () {
            return this.address.name;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAddressReader.prototype, "filteredAddress", {
        get: function () {
            return {
                buildingNumber: this.buildingNumber,
                street: this.street,
                city: this.city,
                postalCode: this.postalCode,
                subBuilding: this.subBuilding,
                country: this.country,
                province: this.province,
                isEstablishment: this.isEstablishment,
                name: this.name
            };
        },
        enumerable: false,
        configurable: true
    });
    MAddressReader.prototype.filterString = function (key, subKey) {
        if (subKey === void 0) { subKey = ''; }
        var value = '';
        if (subKey !== '' && this.address[key] && this.address[key][subKey]) {
            value = this.address[key][subKey];
        }
        else if (subKey === '' && this.address[key]) {
            value = this.address[key];
        }
        return (this.filters[key] && value.length > 0) ? this.filters[key](value) : value;
    };
    __decorate([
        Prop({
            required: true,
            validator: function (value) { return value !== undefined; }
        })
    ], MAddressReader.prototype, "address", void 0);
    __decorate([
        Prop({ default: function () { return ({}); } })
    ], MAddressReader.prototype, "filters", void 0);
    __decorate([
        Prop({
            default: CountryKey.COUNTRY,
            validator: function (value) { return value === CountryKey.COUNTRY
                || value === CountryKey.COUNTRY_ISO2
                || value === CountryKey.COUNTRY_ISO3; }
        })
    ], MAddressReader.prototype, "countryKey", void 0);
    __decorate([
        Prop({
            default: ProvinceKey.PROVINCE,
            validator: function (value) { return value === ProvinceKey.PROVINCE
                || value === ProvinceKey.PROVINCE_CODE; }
        })
    ], MAddressReader.prototype, "provinceKey", void 0);
    MAddressReader = __decorate([
        WithRender,
        Component
    ], MAddressReader);
    return MAddressReader;
}(ModulVue));
export { MAddressReader };
//# sourceMappingURL=address-reader.js.map