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;
};
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());
    });
};
import { css, html } from "lit";
import { customElement, property, query } from "lit/decorators.js";
import "@openremote/or-rules";
import { Page } from "@openremote/or-app";
import manager from "@openremote/core";
import { createSelector } from "reselect";
export function pageRulesProvider(store, config = PAGE_RULES_CONFIG_DEFAULT) {
    return {
        name: "rules",
        routes: [
            "rules",
            "rules/:id"
        ],
        pageCreator: () => {
            const page = new PageRules(store);
            page.config = {
                rules: Object.assign(Object.assign({}, PAGE_RULES_CONFIG_DEFAULT.rules), config.rules)
            };
            return page;
        }
    };
}
export const PAGE_RULES_CONFIG_DEFAULT = {
    rules: {
        controls: {
            allowedLanguages: ["JSON" /* RulesetLang.JSON */, "FLOW" /* RulesetLang.FLOW */, "GROOVY" /* RulesetLang.GROOVY */],
            allowedActionTargetTypes: {
                actions: {
                    wait: [],
                    attribute: [],
                    webhook: [],
                    email: ["USER" /* NotificationTargetType.USER */, "CUSTOM" /* NotificationTargetType.CUSTOM */],
                    email_localized: ["USER" /* NotificationTargetType.USER */, "CUSTOM" /* NotificationTargetType.CUSTOM */],
                    push: ["USER" /* NotificationTargetType.USER */, "ASSET" /* NotificationTargetType.ASSET */],
                    push_localized: ["USER" /* NotificationTargetType.USER */, "ASSET" /* NotificationTargetType.ASSET */]
                }
            }
        },
        descriptors: {
            all: {
                excludeAssets: [
                    "TradfriLightAsset" /* WellknownAssets.TRADFRILIGHTASSET */,
                    "TradfriPlugAsset" /* WellknownAssets.TRADFRIPLUGASSET */,
                    "ArtnetLightAsset" /* WellknownAssets.ARTNETLIGHTASSET */
                ]
            }
        },
        json: {}
    }
};
let PageRules = class PageRules extends Page {
    static get styles() {
        // language=CSS
        return css `
            :host {
            
            }
            
            or-rules {
                width: 100%;
                height: 100%;
            }
        `;
    }
    get name() {
        return "rules";
    }
    constructor(store) {
        super(store);
        this._realmSelector = (state) => state.app.realm || manager.displayRealm;
        this.getRealmState = createSelector([this._realmSelector], (realm) => __awaiter(this, void 0, void 0, function* () {
            if (this._orRules) {
                this._orRules.refresh();
            }
        }));
    }
    render() {
        return html `
            <or-rules id="rules" .config="${this.config && this.config.rules ? this.config.rules : PAGE_RULES_CONFIG_DEFAULT.rules}"></or-rules>
        `;
    }
    stateChanged(state) {
        this.getRealmState(state);
    }
};
__decorate([
    property()
], PageRules.prototype, "config", void 0);
__decorate([
    query("#rules")
], PageRules.prototype, "_orRules", void 0);
PageRules = __decorate([
    customElement("page-rules")
], PageRules);
export { PageRules };
//# sourceMappingURL=page-rules.js.map