"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getYoutubeId = void 0;
var Allowed;
(function (Allowed) {
    Allowed["Tiny"] = "youtu.be";
    Allowed["Full"] = "www.youtube.com";
})(Allowed || (Allowed = {}));
function getYoutubeId({ hostname, pathname, search }) {
    if (hostname !== Allowed.Full && hostname !== Allowed.Tiny) {
        throw new Error(`Cannot get valid youtube ID from "${hostname}" - address is not whitelisted`);
    }
    switch (hostname) {
        case Allowed.Tiny:
            return pathname.replace('/', '');
        case Allowed.Full:
            const searchParams = new URLSearchParams(search);
            const id = searchParams.get('v');
            if (!id) {
                throw new Error("Cannot get valid youtube ID from search params.");
            }
            return id;
    }
}
exports.getYoutubeId = getYoutubeId;
