"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.newThing = newThing;
exports.uniqueNodes = uniqueNodes;
exports.getArchiveUrl = getArchiveUrl;
exports.differentOrigin = differentOrigin;
exports.suggestPreferencesFile = suggestPreferencesFile;
exports.determineChatContainer = determineChatContainer;
const rdflib_1 = require("rdflib");
function newThing(doc) {
    return (0, rdflib_1.sym)(doc.uri + '#' + 'id' + ('' + Date.now()));
}
function uniqueNodes(arr) {
    const uris = arr.map(x => x.uri);
    const set = new Set(uris);
    const uris2 = Array.from(set);
    const arr2 = uris2.map(u => new rdflib_1.NamedNode(u));
    return arr2; // Array.from(new Set(arr.map(x => x.uri))).map(u => sym(u))
}
function getArchiveUrl(baseUrl, date) {
    const year = date.getUTCFullYear();
    const month = ('0' + (date.getUTCMonth() + 1)).slice(-2);
    const day = ('0' + (date.getUTCDate())).slice(-2);
    const parts = baseUrl.split('/');
    const filename = parts[parts.length - 1];
    return new URL(`./archive/${year}/${month}/${day}/${filename}`, baseUrl).toString();
}
function differentOrigin(doc) {
    if (!doc) {
        return true;
    }
    return (`${window.location.origin}/` !== new URL(doc.value).origin);
}
function suggestPreferencesFile(me) {
    const stripped = me.uri.replace('/profile/', '/').replace('/public/', '/');
    // const stripped = me.uri.replace(\/[p|P]rofile/\g, '/').replace(\/[p|P]ublic/\g, '/')
    const folderURI = stripped.split('/').slice(0, -1).join('/') + '/Settings/';
    const fileURI = folderURI + 'Preferences.ttl';
    return (0, rdflib_1.sym)(fileURI);
}
function determineChatContainer(invitee, podRoot) {
    // Create chat
    // See https://gitter.im/solid/chat-app?at=5f3c800f855be416a23ae74a
    const chatContainerStr = new URL(`IndividualChats/${new URL(invitee.value).host}/`, podRoot.value).toString();
    return new rdflib_1.NamedNode(chatContainerStr);
}
//# sourceMappingURL=utils.js.map