"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Site = void 0;
const SiteAssetsManager_1 = require("./SiteAssetsManager");
const SiteDeployManager_1 = require("./SiteDeployManager");
const SiteGenerationManager_1 = require("./SiteGenerationManager");
const SitePagesManager_1 = require("./SitePagesManager");
const logger = __importStar(require("../utils/logger"));
const constants_1 = require("./constants");
// Change when migrated to TypeScript
require('../patches/htmlparser2');
class Site {
    // Getters for compatibility
    get siteConfig() { return this.generationManager.siteConfig; }
    set siteConfig(config) {
        this.generationManager.siteConfig = config;
        this.assetsManager.siteConfig = config;
        this.pagesManager.siteConfig = config;
        this.deployManager.siteConfig = config;
    }
    constructor(rootPath, outputPath, onePagePath, forceReload = false, siteConfigPath = constants_1.SITE_CONFIG_NAME, isDevMode, backgroundBuildMode, postBackgroundBuildFunc) {
        this.isDevMode = !!isDevMode;
        this.rootPath = rootPath;
        this.outputPath = outputPath;
        this.siteConfigPath = siteConfigPath;
        this.assetsManager = new SiteAssetsManager_1.SiteAssetsManager(rootPath, outputPath);
        this.pagesManager = new SitePagesManager_1.SitePagesManager(rootPath, outputPath, this.isDevMode);
        this.deployManager = new SiteDeployManager_1.SiteDeployManager(rootPath, outputPath);
        this.generationManager = new SiteGenerationManager_1.SiteGenerationManager(rootPath, outputPath, onePagePath, forceReload, siteConfigPath, this.isDevMode, backgroundBuildMode, postBackgroundBuildFunc);
        // Configure Generator with references
        this.generationManager.configure(this.assetsManager, this.pagesManager);
    }
    changeCurrentPage(normalizedUrl) {
        return this.generationManager.changeCurrentPage(normalizedUrl);
    }
    changeCurrentOpenedPages(normalizedUrls) {
        return this.generationManager.changeCurrentOpenedPages(normalizedUrls);
    }
    readSiteConfig(baseUrl) {
        return __awaiter(this, void 0, void 0, function* () {
            const config = yield this.generationManager.readSiteConfig(baseUrl);
            this.siteConfig = config;
            return config;
        });
    }
    static printBaseUrlMessage() {
        logger.info('The default base URL of your site is set to /\n'
            + 'You can change the base URL of your site by editing site.json\n'
            + 'Check https://markbind.org/userGuide/siteConfiguration.html for more information.');
    }
    generate(baseUrl) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.generationManager.generate(baseUrl);
        });
    }
    buildSourceFiles() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.generationManager.buildSourceFiles();
        });
    }
    rebuildAffectedSourceFiles(filePaths) {
        return this.generationManager.rebuildAffectedSourceFiles(filePaths);
    }
    rebuildSourceFiles() {
        return this.generationManager.rebuildSourceFiles();
    }
    buildAsset(filePaths) {
        return this.assetsManager.buildAsset(filePaths);
    }
    removeAsset(filePaths) {
        return this.assetsManager.removeAsset(filePaths);
    }
    isFilepathAPage(filePath) {
        return this.pagesManager.isFilepathAPage(filePath);
    }
    isDependencyOfPage(filePath) {
        return this.pagesManager.isDependencyOfPage(filePath);
    }
    reloadSiteConfig() {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.generationManager.reloadSiteConfig();
            this.siteConfig = this.generationManager.siteConfig;
        });
    }
    /**
     * Deploys the site to the specified deployment platform.
     * @param ciTokenVar The CI token variable to use for authentication.
     * @returns A promise that resolves when the deployment is complete.
     */
    deploy(ciTokenVar) {
        return __awaiter(this, void 0, void 0, function* () {
            const config = yield this.readSiteConfig();
            this.deployManager.siteConfig = config;
            return this.deployManager.deploy(ciTokenVar);
        });
    }
}
exports.Site = Site;
//# sourceMappingURL=index.js.map