import { MPostalCodeCountry } from '../../components/postalcodefield/postalcodefield';
import { POSTAL_CODE_NAME } from '../filter-names';
var PostalCodeFilter = /** @class */ (function () {
    function PostalCodeFilter() {
    }
    /**
     * Available formats:
     * No country code specified: Canadian format by default
     * CA (6 characters) — Example: "X1X 1X1"
     * US (5 or less characters) — Example: "11111" (Only 5 first characters are kept)
     * US (more than 5 characters, up to 9) — Example: "11111-1111" (Only 9 first characters are kept)
     * FR (5 characters) — Example: "11111" (Only 5 first characters are kept)
     * Other specified — Example: "11111-1111" (string stays the same)
     */
    PostalCodeFilter.format = function (text, isoCountry) {
        if (isoCountry === void 0) { isoCountry = MPostalCodeCountry.CA; }
        switch (isoCountry.toLowerCase()) {
            case MPostalCodeCountry.CA: {
                return [text.slice(0, 3), text.slice(3, 6)].join(' ');
            }
            case MPostalCodeCountry.US: {
                if (text.length <= 5) {
                    return text;
                }
                else {
                    return [text.slice(0, 5), text.slice(5, 9)].join('-');
                }
            }
            case MPostalCodeCountry.FR: {
                return text.substring(0, 5);
            }
            default: {
                return text;
            }
        }
    };
    return PostalCodeFilter;
}());
export { PostalCodeFilter };
var PostalCodeFilterPlugin = {
    install: function (v) {
        v.filter(POSTAL_CODE_NAME, PostalCodeFilter.format);
    }
};
export default PostalCodeFilterPlugin;
//# sourceMappingURL=postal-code.js.map