import { Css, PermissionsService, Util } from "../../lib/index";
// <ema-permission roles-only="DEVELOPER,ADMIN">
//  <div>ONLY VISIBLE DURING DEV<div>
// </ema-permission>
// <ema-permission roles-except="ANONYMOUS">
//  <div>ONLY VISIBLE WHEN AUTHENTICATED<div>
// </ema-permission>
// <div data-permission-roles-only="DEVELOPER,ADMIN">ONLY VISIBLE DURING DEV</div>
// <div data-permission-roles-except="ANONYMOUS">ONLY VISIBLE WHEN AUTHENTICATED</div>
// <div data-permission-read="false">NOT VISIBLE</div>
export class Permission {
    constructor() {
        this.roles = ['ANONYMOUS'];
        this.crudArray = [];
        this.state = {
            create: false,
            read: true,
            update: false,
            delete: false,
            execute: true
        };
        this.read = true;
        this.permissions = PermissionsService.instance;
    }
    componentDidLoad() {
        this.displayDefault = Css.getStyle('display', this.el);
        this.setStyles();
    }
    componentDidUpdate() {
        this.setStyles();
    }
    getCrud() {
        return this.state;
    }
    setCrud(create, read, update, del, execute = true) {
        this.state.create = create;
        this.state.read = read;
        this.state.update = update;
        this.state.delete = del;
        this.state.execute = execute;
    }
    setStyles() {
        this.el.style.display = this.displayDefault;
        if (this.state.create) {
        }
        if (!this.state.read) {
            this.el.style.display = 'none';
        }
        if (this.state.update) {
        }
        if (this.state.delete) {
        }
        console.log(this);
    }
    render() {
        if (this.rolesOnly) {
        }
        if (this.rolesExcept) {
        }
        if (this.crud) {
            this.crudArray = this.crud.split(',');
            this.crudArray.forEach((v, i) => {
                this.crudArray[i] = Util.castToType(v);
            });
            this.setCrud(this.crudArray[0], this.crudArray[1], this.crudArray[2], this.crudArray[3]);
        }
        if (!this.read) {
            this.state.read = false;
        }
        return (h("div", null,
            h("slot", null)));
    }
    static get is() { return "ema-permission"; }
    static get properties() { return {
        "crud": {
            "type": String,
            "attr": "crud"
        },
        "el": {
            "elementRef": true
        },
        "getCrud": {
            "method": true
        },
        "read": {
            "type": Boolean,
            "attr": "read"
        },
        "rolesExcept": {
            "type": String,
            "attr": "roles-except"
        },
        "rolesOnly": {
            "type": String,
            "attr": "roles-only"
        },
        "setCrud": {
            "method": true
        },
        "state": {
            "state": true
        }
    }; }
    static get events() { return [{
            "name": "change",
            "method": "change",
            "bubbles": true,
            "cancelable": true,
            "composed": true
        }]; }
}
//# sourceMappingURL=permission.js.map