"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CookieUtils = void 0;
const MablSymbol_1 = require("../MablSymbol");
var CookieUtils;
(function (CookieUtils) {
    CookieUtils.validCookieNameCharacterRange = /^[\x21-\x7E]*$/;
    CookieUtils.invalidCookieNameCharaters = /[()<>@,;:\\"\\/\[\]?={}]/;
    CookieUtils.validCookieValueCharacters = /^(!|[\x23-\x2B]|[\x2D-\x3A]|[\x3C-\x5B]|[\x5D-\x7E])*$/;
    function validateCookieName(name) {
        const trimmed = name.trim();
        if ('' === trimmed) {
            return false;
        }
        if (!CookieUtils.validCookieNameCharacterRange.test(trimmed) ||
            CookieUtils.invalidCookieNameCharaters.test(trimmed)) {
            return false;
        }
        return true;
    }
    CookieUtils.validateCookieName = validateCookieName;
    function normalizeName(name) {
        const trimmed = name.trim();
        if ('' === trimmed) {
            throw new Error('Cookie name cannot be empty or include only whitespace characters');
        }
        return trimmed;
    }
    CookieUtils.normalizeName = normalizeName;
    function validateCookieValue(value) {
        const trimmed = value.trim();
        if ('' === trimmed) {
            return false;
        }
        if (!CookieUtils.validCookieValueCharacters.test(trimmed)) {
            return false;
        }
        return true;
    }
    CookieUtils.validateCookieValue = validateCookieValue;
    function normalizeValue(value) {
        if (!value) {
            throw new Error('Cookie value cannot be empty');
        }
        const valueStr = (0, MablSymbol_1.isMablSymbolObject)(value) ? (0, MablSymbol_1.formatSymbol)(value) : value;
        const trimmed = valueStr.trim();
        const bareValue = trimmed.startsWith('"') && trimmed.endsWith('"')
            ? trimmed.substring(1, trimmed.length - 1)
            : trimmed;
        if ('' === bareValue) {
            throw new Error('Cookie value cannot be empty or include only whitespace characters');
        }
        return trimmed;
    }
    CookieUtils.normalizeValue = normalizeValue;
})(CookieUtils || (exports.CookieUtils = CookieUtils = {}));
