"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var sp_diagnostics_1 = require("@microsoft/sp-diagnostics");
/**
 * Represents custom content that is rendered inside a placeholder on a SharePoint page.
 *
 * @remarks
 * This object is returned by {@link PlaceholderProvider.tryCreateContent}.
 * It provides access to a Document Object Model (DOM) element where the owner can render
 * its custom content.
 *
 * @public
 */
var PlaceholderContent = /** @class */ (function () {
    /**
     * @internal
     */
    function PlaceholderContent(parameters) {
        this._disposeHandler = undefined;
        this._isDisposed = false;
        this._placeholder = parameters.placeholder;
        this._disposeHandler = parameters.options ? parameters.options.onDispose : undefined;
        this._domElement = parameters.domElement;
    }
    Object.defineProperty(PlaceholderContent.prototype, "name", {
        /**
         * Identifies the placeholder that this content was added to.
         *
         * @remarks
         * Example: PlaceholderName.Top
         */
        get: function () {
            return this._placeholder.name;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PlaceholderContent.prototype, "domElement", {
        /**
         * The Document Object Model (DOM) element where the owner should render its custom content.
         *
         * @remarks
         * If the caller needs to be notified when the DOM element is disposed, use
         * the {@link IPlaceholderCreateContentOptions.onDispose} callback.
         */
        get: function () {
            return this._domElement;
        },
        enumerable: false,
        configurable: true
    });
    /**
     * Sets the placeholder of the content. This is used when the placeholders are modifying and the content may
     * hang from a new placeholder object.
     * @param placeholder - Placeholder that own this placeholder content.
     *
     * @internal
     */
    PlaceholderContent.prototype._setPlaceholder = function (placeholder) {
        this._placeholder = placeholder;
    };
    /**
     * Sets the options of the content. This is used when a bottom or top preAllocatedContent is created.
     * @param options - Options that own this placeholder content.
     *
     * @internal
     */
    PlaceholderContent.prototype._setOptions = function (options) {
        this._disposeHandler = options && options.onDispose;
    };
    /**
     * Disposes the PlaceholderContent object and removes its attached DOM element from the page.
     *
     * @remarks
     * This method can be called to immediately dispose the attached DOM element. Otherwise, it
     * will be disposed by the application when the containing placeholder is disposed. Calling dispose()
     * invokes the {@link IPlaceholderCreateContentOptions.onDispose} callback, removes the associated
     * DOM element from the page, and disposes the PlaceholderContent object.
     */
    PlaceholderContent.prototype.dispose = function () {
        if (!this._isDisposed) {
            if (this._disposeHandler) {
                try {
                    this._disposeHandler(this);
                }
                catch (error) {
                    sp_diagnostics_1._TraceLogger.logError(PlaceholderContent._logSource, new Error("The onDispose API threw an exception for placeholder '" + this._placeholder.name + "'. Error information is '" + error.message + "'"));
                }
            }
            this._placeholder.removePlaceholderContent(this);
            delete this._domElement;
            delete this._placeholder;
            delete this._disposeHandler;
        }
        this._isDisposed = true;
    };
    Object.defineProperty(PlaceholderContent.prototype, "isDisposed", {
        get: function () {
            return this._isDisposed;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PlaceholderContent.prototype, "isVisible", {
        /**
         * Return true if this PlacholderContent object is visible.  If you create a placeholder
         * and the host page isn't displaying it, this will return false.
         */
        get: function () {
            return document.body.contains(this._domElement);
        },
        enumerable: false,
        configurable: true
    });
    PlaceholderContent._logSource = sp_diagnostics_1._LogSource.create('Placeholder');
    return PlaceholderContent;
}());
exports.default = PlaceholderContent;
//# sourceMappingURL=PlaceholderContent.js.map