import { Component, EventEmitter, Input, Output } from '@angular/core';
import { I18nService } from './services/system/locale/I18n';
import { RULE_RULE_ACTION_UPDATE_TYPE, RULE_RULE_ACTION_UPDATE_PARAMETER, RULE_RULE_ACTION_DELETE } from './services/Rule';
import { LoggerService } from 'dotcms-js/dotcms-js';
var RuleActionComponent = (function () {
    function RuleActionComponent(_resources, loggerService) {
        this._resources = _resources;
        this.loggerService = loggerService;
        this.index = 0;
        this.ruleActionTypes = {};
        this.updateRuleActionType = new EventEmitter(false);
        this.updateRuleActionParameter = new EventEmitter(false);
        this.deleteRuleAction = new EventEmitter(false);
    }
    RuleActionComponent.prototype.ngOnChanges = function (change) {
        var _this = this;
        if (change.ruleActionTypes && !this.typeDropdown) {
            this.typeDropdown = {
                options: []
            };
            Object.keys(this.ruleActionTypes).forEach(function (key) {
                var type = _this.ruleActionTypes[key];
                _this.typeDropdown.options.push(type._opt);
            });
        }
        if (change.action) {
            if (this.typeDropdown && this.action.type) {
                if (this.action.type.key !== 'NoSelection') {
                    this.typeDropdown.value = this.action.type.key;
                }
            }
        }
    };
    RuleActionComponent.prototype.onTypeChange = function (type) {
        this.loggerService.info('RuleActionComponent', 'onTypeChange', type);
        this.updateRuleActionType.emit({
            type: RULE_RULE_ACTION_UPDATE_TYPE,
            payload: { ruleAction: this.action, value: type, index: this.index }
        });
    };
    RuleActionComponent.prototype.onParameterValueChange = function (event) {
        this.loggerService.info('RuleActionComponent', 'onParameterValueChange', event);
        this.updateRuleActionParameter.emit({
            payload: {
                ruleAction: this.action,
                name: event.name,
                value: event.value,
                index: this.index
            },
            type: RULE_RULE_ACTION_UPDATE_PARAMETER
        });
    };
    RuleActionComponent.prototype.onDeleteRuleActionClicked = function () {
        this.deleteRuleAction.emit({
            type: RULE_RULE_ACTION_DELETE,
            payload: { ruleAction: this.action, index: this.index }
        });
    };
    return RuleActionComponent;
}());
export { RuleActionComponent };
RuleActionComponent.decorators = [
    { type: Component, args: [{
                selector: 'rule-action',
                template: "<div *ngIf=\"typeDropdown != null\" flex layout=\"row\" class=\"cw-rule-action cw-entry\">\n  <div flex=\"25\" layout=\"row\" class=\"cw-row-start-area\">\n    <cw-input-dropdown\n      flex\n      class=\"cw-type-dropdown\"\n      [value]=\"action.type?.key\"\n      placeholder=\"{{actionTypePlaceholder}}\"\n      (onDropDownChange)=\"onTypeChange($event)\">\n        <cw-input-option\n        *ngFor=\"let opt of typeDropdown.options\"\n        [value]=\"opt.value\"\n        [label]=\"opt.label\"\n        icon=\"{{opt.icon}}\"></cw-input-option>\n    </cw-input-dropdown>\n  </div>\n  <cw-serverside-condition flex=\"75\"\n                           class=\"cw-condition-component\"\n                           [componentInstance]=\"action\"\n                           (parameterValueChange)=\"onParameterValueChange($event)\">\n  </cw-serverside-condition>\n  <div class=\"cw-btn-group cw-delete-btn\">\n    <div class=\"ui basic icon buttons\">\n      <button class=\"ui button\" aria-label=\"Delete Action\" (click)=\"onDeleteRuleActionClicked()\" [disabled]=\"!action.isPersisted()\">\n        <i class=\"trash icon\"></i>\n      </button>\n    </div>\n  </div>\n</div>"
            },] },
];
/** @nocollapse */
RuleActionComponent.ctorParameters = function () { return [
    { type: I18nService, },
    { type: LoggerService, },
]; };
RuleActionComponent.propDecorators = {
    'action': [{ type: Input },],
    'index': [{ type: Input },],
    'actionTypePlaceholder': [{ type: Input },],
    'ruleActionTypes': [{ type: Input },],
    'updateRuleActionType': [{ type: Output },],
    'updateRuleActionParameter': [{ type: Output },],
    'deleteRuleAction': [{ type: Output },],
    'typeDropdown': [{ type: Input },],
};
//# sourceMappingURL=rule-action-component.js.map