/**
 * @dyna-grid/core - Advanced Data Grid / Data Table supporting Javascript / Web Components
 * @version v1.1.0
 * @link 
 * @license 
 */
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { TextCellEditor } from "../../rendering/cellEditors/textCellEditor";
import { Autowired, Bean, PostConstruct } from "../../context/context";
import { DateFilter } from "../../filter/provided/date/dateFilter";
import { HeaderComp } from "../../headerRendering/header/headerComp";
import { HeaderGroupComp } from "../../headerRendering/headerGroup/headerGroupComp";
import { GroupCellRenderer } from "../../rendering/cellRenderers/groupCellRenderer";
import { AnimateShowChangeCellRenderer } from "../../rendering/cellRenderers/animateShowChangeCellRenderer";
import { AnimateSlideCellRenderer } from "../../rendering/cellRenderers/animateSlideCellRenderer";
import { LoadingCellRenderer } from "../../rendering/cellRenderers/loadingCellRenderer";
import { SelectCellEditor } from "../../rendering/cellEditors/selectCellEditor";
import { PopupTextCellEditor } from "../../rendering/cellEditors/popupTextCellEditor";
import { PopupSelectCellEditor } from "../../rendering/cellEditors/popupSelectCellEditor";
import { LargeTextCellEditor } from "../../rendering/cellEditors/largeTextCellEditor";
import { NumberFilter } from "../../filter/provided/number/numberFilter";
import { LoadingOverlayComponent } from "../../rendering/overlays/loadingOverlayComponent";
import { NoRowsOverlayComponent } from "../../rendering/overlays/noRowsOverlayComponent";
import { TooltipComponent } from "../../rendering/tooltipComponent";
import { DefaultDateComponent } from "../../filter/provided/date/defaultDateComponent";
import { DateFloatingFilter } from "../../filter/provided/date/dateFloatingFilter";
import { TextFilter } from "../../filter/provided/text/textFilter";
import { NumberFloatingFilter } from "../../filter/provided/number/numberFloatingFilter";
import { TextFloatingFilter } from "../../filter/provided/text/textFloatingFilter";
import { BeanStub } from "../../context/beanStub";
import { iterateObject } from '../../utils/object';
import { doOnce } from "../../utils/function";
export var RegisteredComponentSource;
(function (RegisteredComponentSource) {
    RegisteredComponentSource[RegisteredComponentSource["DEFAULT"] = 0] = "DEFAULT";
    RegisteredComponentSource[RegisteredComponentSource["REGISTERED"] = 1] = "REGISTERED";
})(RegisteredComponentSource || (RegisteredComponentSource = {}));
var UserComponentRegistry = /** @class */ (function (_super) {
    __extends(UserComponentRegistry, _super);
    function UserComponentRegistry() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.dyGridDefaults = {
            //date
            dyDateInput: DefaultDateComponent,
            //header
            dyColumnHeader: HeaderComp,
            dyColumnGroupHeader: HeaderGroupComp,
            //floating filters
            dyTextColumnFloatingFilter: TextFloatingFilter,
            dyNumberColumnFloatingFilter: NumberFloatingFilter,
            dyDateColumnFloatingFilter: DateFloatingFilter,
            // renderers
            dyAnimateShowChangeCellRenderer: AnimateShowChangeCellRenderer,
            dyAnimateSlideCellRenderer: AnimateSlideCellRenderer,
            dyGroupCellRenderer: GroupCellRenderer,
            dyGroupRowRenderer: GroupCellRenderer,
            dyLoadingCellRenderer: LoadingCellRenderer,
            //editors
            dyCellEditor: TextCellEditor,
            dyTextCellEditor: TextCellEditor,
            dySelectCellEditor: SelectCellEditor,
            dyPopupTextCellEditor: PopupTextCellEditor,
            dyPopupSelectCellEditor: PopupSelectCellEditor,
            dyLargeTextCellEditor: LargeTextCellEditor,
            //filter
            dyTextColumnFilter: TextFilter,
            dyNumberColumnFilter: NumberFilter,
            dyDateColumnFilter: DateFilter,
            //overlays
            dyLoadingOverlay: LoadingOverlayComponent,
            dyNoRowsOverlay: NoRowsOverlayComponent,
            // tooltips
            dyTooltipComponent: TooltipComponent
        };
        _this.dyDeprecatedNames = {
            set: {
                newComponentName: 'dySetColumnFilter',
                propertyHolder: 'filter'
            },
            text: {
                newComponentName: 'dyTextColumnFilter',
                propertyHolder: 'filter'
            },
            number: {
                newComponentName: 'dyNumberColumnFilter',
                propertyHolder: 'filter'
            },
            date: {
                newComponentName: 'dyDateColumnFilter',
                propertyHolder: 'filter'
            },
            group: {
                newComponentName: 'dyGroupCellRenderer',
                propertyHolder: 'cellRenderer'
            },
            animateShowChange: {
                newComponentName: 'dyAnimateShowChangeCellRenderer',
                propertyHolder: 'cellRenderer'
            },
            animateSlide: {
                newComponentName: 'dyAnimateSlideCellRenderer',
                propertyHolder: 'cellRenderer'
            },
            select: {
                newComponentName: 'dySelectCellEditor',
                propertyHolder: 'cellEditor'
            },
            largeText: {
                newComponentName: 'dyLargeTextCellEditor',
                propertyHolder: 'cellEditor'
            },
            popupSelect: {
                newComponentName: 'dyPopupSelectCellEditor',
                propertyHolder: 'cellEditor'
            },
            popupText: {
                newComponentName: 'dyPopupTextCellEditor',
                propertyHolder: 'cellEditor'
            },
            richSelect: {
                newComponentName: 'dyRichSelectCellEditor',
                propertyHolder: 'cellEditor'
            },
            headerComponent: {
                newComponentName: 'dyColumnHeader',
                propertyHolder: 'headerComponent'
            }
        };
        _this.jsComponents = {};
        _this.frameworkComponents = {};
        return _this;
    }
    UserComponentRegistry.prototype.init = function () {
        var _this = this;
        if (this.gridOptions.components != null) {
            iterateObject(this.gridOptions.components, function (key, component) { return _this.registerComponent(key, component); });
        }
        if (this.gridOptions.frameworkComponents != null) {
            iterateObject(this.gridOptions.frameworkComponents, function (key, component) { return _this.registerFwComponent(key, component); });
        }
    };
    UserComponentRegistry.prototype.registerDefaultComponent = function (rawName, component) {
        var name = this.translateIfDeprecated(rawName);
        if (this.dyGridDefaults[name]) {
            console.error("Trying to overwrite a default component. You should call registerComponent");
            return;
        }
        this.dyGridDefaults[name] = component;
    };
    UserComponentRegistry.prototype.registerComponent = function (rawName, component) {
        var name = this.translateIfDeprecated(rawName);
        if (this.frameworkComponents[name]) {
            console.error("Trying to register a component that you have already registered for frameworks: " + name);
            return;
        }
        this.jsComponents[name] = component;
    };
    /**
     * B the business interface (ie IHeader)
     * A the dyGridComponent interface (ie IHeaderComp). The final object acceptable by dyna-grid
     */
    UserComponentRegistry.prototype.registerFwComponent = function (rawName, component) {
        var name = this.translateIfDeprecated(rawName);
        if (this.jsComponents[name]) {
            console.error("Trying to register a component that you have already registered for plain javascript: " + name);
            return;
        }
        this.frameworkComponents[name] = component;
    };
    /**
     * B the business interface (ie IHeader)
     * A the dyGridComponent interface (ie IHeaderComp). The final object acceptable by dyna-grid
     */
    UserComponentRegistry.prototype.retrieve = function (rawName) {
        var name = this.translateIfDeprecated(rawName);
        var frameworkComponent = this.frameworkComponents[name];
        if (frameworkComponent) {
            return {
                componentFromFramework: true,
                component: frameworkComponent,
                source: RegisteredComponentSource.REGISTERED
            };
        }
        var jsComponent = this.jsComponents[name];
        if (jsComponent) {
            return {
                componentFromFramework: false,
                component: jsComponent,
                source: RegisteredComponentSource.REGISTERED
            };
        }
        var defaultComponent = this.dyGridDefaults[name];
        if (defaultComponent) {
            return {
                componentFromFramework: false,
                component: defaultComponent,
                source: RegisteredComponentSource.DEFAULT
            };
        }
        if (Object.keys(this.dyGridDefaults).indexOf(name) < 0) {
            console.warn("DYNA Grid: Looking for component [" + name + "] but it wasn't found.");
        }
        return null;
    };
    UserComponentRegistry.prototype.translateIfDeprecated = function (raw) {
        var deprecatedInfo = this.dyDeprecatedNames[raw];
        if (deprecatedInfo != null) {
            doOnce(function () {
                console.warn("dyna-grid. component names have been renamed to be namespaced. You should rename " + deprecatedInfo.propertyHolder + ":" + raw + " to " + deprecatedInfo.propertyHolder + ":" + deprecatedInfo.newComponentName);
            }, 'DEPRECATE_COMPONENT_' + raw);
            return deprecatedInfo.newComponentName;
        }
        return raw;
    };
    __decorate([
        Autowired('gridOptions')
    ], UserComponentRegistry.prototype, "gridOptions", void 0);
    __decorate([
        PostConstruct
    ], UserComponentRegistry.prototype, "init", null);
    UserComponentRegistry = __decorate([
        Bean('userComponentRegistry')
    ], UserComponentRegistry);
    return UserComponentRegistry;
}(BeanStub));
export { UserComponentRegistry };
