"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = require("../../util/logger");
const sassImportEntryList_1 = require("../importer/sassImportEntryList");
/**
 * Supported output style.
 */
var OutputStyle;
(function (OutputStyle) {
    OutputStyle[OutputStyle["SASS_STYLE_NESTED"] = 0] = "SASS_STYLE_NESTED";
    OutputStyle[OutputStyle["SASS_STYLE_EXPANDED"] = 1] = "SASS_STYLE_EXPANDED";
    OutputStyle[OutputStyle["SASS_STYLE_COMPACT"] = 2] = "SASS_STYLE_COMPACT";
    OutputStyle[OutputStyle["SASS_STYLE_COMPRESSED"] = 3] = "SASS_STYLE_COMPRESSED";
})(OutputStyle || (OutputStyle = {}));
exports.OutputStyle = OutputStyle;
/**
 * @internal
 *
 */
class SassOptions {
    /**
     * Construct new instance of SassOptions.
     *
     * @param {ReturnType<typeof wrapSassContext>} cwrapCtx cwrapped function object to sass context api.
     * @param {ReturnType<typeof wrapSassOptions>} cwrapOptions cwrapped function object to sass option api.
     *
     * Manual creation of this class is prohibited;
     * Should use `context.options.create` static interface instead.
     */
    constructor(cwrapCtx, cwrapOptions, cwrapImporter, interop) {
        this.cwrapCtx = cwrapCtx;
        this.cwrapOptions = cwrapOptions;
        this.cwrapImporter = cwrapImporter;
        this.interop = interop;
        /**
         * List of virtual mounted path.
         */
        this.mountedPath = [];
        /**
         * Hold pointers to internaly allocated strings, to be removed when disposing entry instance
         */
        this.allocatedStringPtr = [];
        this.sassOptionsPtr = cwrapCtx.make_options();
        logger_1.log(`SassOptions: created new instance`, { sassOptionsPtr: this.sassOptionsPtr });
    }
    get precision() {
        return this.cwrapOptions.option_get_precision(this.sassOptionsPtr);
    }
    set precision(precision) {
        this.cwrapOptions.option_set_precision(this.sassOptionsPtr, precision);
    }
    get outputStyle() {
        return this.cwrapOptions.option_get_output_style(this.sassOptionsPtr);
    }
    set outputStyle(style) {
        this.cwrapOptions.option_set_output_style(this.sassOptionsPtr, style);
    }
    get sourceComments() {
        return !!this.cwrapOptions.option_get_source_comments(this.sassOptionsPtr);
    }
    set sourceComments(enabled) {
        this.cwrapOptions.option_set_source_comments(this.sassOptionsPtr, enabled);
    }
    get isIndentedSyntaxSrc() {
        return !!this.cwrapOptions.option_get_is_indented_syntax_src(this.sassOptionsPtr);
    }
    set isIndentedSyntaxSrc(isIndented) {
        this.cwrapOptions.option_set_is_indented_syntax_src(this.sassOptionsPtr, isIndented);
    }
    get omitMapComment() {
        return !!this.cwrapOptions.option_get_omit_source_map_url(this.sassOptionsPtr);
    }
    set omitMapComment(isOmitted) {
        this.cwrapOptions.option_set_omit_source_map_url(this.sassOptionsPtr, isOmitted);
    }
    get sourceMapEmbed() {
        return !!this.cwrapOptions.option_get_source_map_embed(this.sassOptionsPtr);
    }
    set sourceMapEmbed(embed) {
        this.cwrapOptions.option_set_source_map_embed(this.sassOptionsPtr, embed);
    }
    get sourceMapFile() {
        const mapFilePtr = this.cwrapOptions.option_get_source_map_file(this.sassOptionsPtr);
        return this.interop.str.ptrToString(mapFilePtr);
    }
    set sourceMapFile(mapFile) {
        const mapFilePtr = this.interop.str.alloc(mapFile);
        this.allocatedStringPtr.push(mapFilePtr);
        this.cwrapOptions.option_set_source_map_file(this.sassOptionsPtr, mapFilePtr);
    }
    get outputPath() {
        const outPathPtr = this.cwrapOptions.option_get_output_path(this.sassOptionsPtr);
        return this.interop.str.ptrToString(outPathPtr);
    }
    set outputPath(outPath) {
        const outputPathPtr = this.interop.str.alloc(outPath);
        this.allocatedStringPtr.push(outputPathPtr);
        this.cwrapOptions.option_set_output_path(this.sassOptionsPtr, outputPathPtr);
    }
    get inputPath() {
        const inputPathPtr = this.cwrapOptions.option_get_input_path(this.sassOptionsPtr);
        return this.interop.str.ptrToString(inputPathPtr);
    }
    set inputPath(outPath) {
        const outputPathStr = this.interop.str.alloc(outPath);
        this.allocatedStringPtr.push(outputPathStr);
        this.cwrapOptions.option_set_input_path(this.sassOptionsPtr, outputPathStr);
    }
    get importers() {
        return !!this.importersList ? this.importersList.entry : [];
    }
    set importers(values) {
        this.importersList = new sassImportEntryList_1.SassImportEntryList(this.cwrapImporter, values.length);
        this.importersList.entry = values;
        this.cwrapOptions.option_set_c_importers(this.sassOptionsPtr, this.importersList.sassImportEntryListPtr);
    }
    addIncludePath(includePath) {
        const mounted = this.interop.mount(includePath);
        this.mountedPath.push(mounted);
        const mountedPtr = this.interop.str.alloc(mounted);
        this.allocatedStringPtr.push(mountedPtr);
        this.cwrapOptions.option_push_include_path(this.sassOptionsPtr, mountedPtr);
    }
    addPluginPath(pluginPath) {
        const mounted = this.interop.mount(pluginPath);
        this.mountedPath.push(mounted);
        const mountedPtr = this.interop.str.alloc(mounted);
        this.allocatedStringPtr.push(mountedPtr);
        this.cwrapOptions.option_push_plugin_path(this.sassOptionsPtr, mountedPtr);
    }
    dispose() {
        this.cwrapCtx.delete_options(this.sassOptionsPtr);
        this.mountedPath.forEach(p => this.interop.unmount(p));
        this.allocatedStringPtr.forEach(ptr => this.interop.free(ptr));
        this.allocatedStringPtr.splice(0);
        logger_1.log(`SassOptions: disposed instance`);
    }
}
exports.SassOptions = SassOptions;
//# sourceMappingURL=sassOptions.js.map