import * as i0 from '@angular/core';
import { Component, ViewChild } from '@angular/core';
import * as i4 from '@angular/forms';
import * as i2 from '@c8y/ngx-components';
import { gettext, CommonModule, CoreModule } from '@c8y/ngx-components';
import * as i1 from '@c8y/ngx-components/protocol-lwm2m/services';
import * as i3 from '@angular/common';

class LWM2MPostOperationsComponent {
    constructor(lwm2mPostOperationsSvc, alertService) {
        this.lwm2mPostOperationsSvc = lwm2mPostOperationsSvc;
        this.alertService = alertService;
        this.exampleCommands = [
            {
                command: 'discover',
                resource: '<objectId>',
                description: gettext('Discover all resources of Object 3300, the generic sensor.')
            },
            {
                command: 'read',
                resource: '<objectId>/<objectInstanceId>/<resourceId>',
                description: gettext('Read maximum sensor value')
            },
            {
                command: 'write',
                resource: '<objectId>/<objectInstanceId>/<resourceId> <applicationType>',
                description: gettext('Write application type "CO2" to device')
            },
            {
                command: 'execute',
                resource: '<objectId>/<objectInstanceId>/<resourceId>',
                description: gettext('Reset min and max values')
            },
            {
                command: 'observe',
                resource: '<objectId>/<objectInstanceId>/<resourceId>',
                description: gettext('Observe sensor value. Causes device to send every new sensor value')
            },
            {
                command: 'writeattr',
                resource: '<objectId>/<objectInstanceId>/<resourceId> greater=<value>',
                description: gettext('Only send observations if sensor value is higher than 100')
            }
        ];
        this.operations = {
            commands: '',
            type: '',
            id: ''
        };
    }
    async ngOnInit() {
        this.operations = (await this.getPostOperationsParameters());
    }
    async save(operations) {
        try {
            await this.lwm2mPostOperationsSvc.put(operations);
            this.alertService.success(gettext('Post-operations saved'));
            this.commandsForm.form.markAsPristine();
        }
        catch (error) {
            this.alertService.addServerFailure(error);
        }
    }
    async getPostOperationsParameters() {
        try {
            const res = await this.lwm2mPostOperationsSvc.get();
            return (await res.json());
        }
        catch (error) {
            this.alertService.addServerFailure(error);
            return {};
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: LWM2MPostOperationsComponent, deps: [{ token: i1.LWM2MPostOperationsParametersService }, { token: i2.AlertService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.9", type: LWM2MPostOperationsComponent, isStandalone: true, selector: "lwm2m-post-operations", viewQueries: [{ propertyName: "commandsForm", first: true, predicate: ["commandsForm"], descendants: true }], ngImport: i0, template: "<c8y-title>{{ 'LWM2M post-operations' | translate }}</c8y-title>\n<c8y-breadcrumb>\n  <c8y-breadcrumb-item\n    [label]=\"'Device types' | translate\"\n    [icon]=\"'c8y-device-protocols'\"\n  ></c8y-breadcrumb-item>\n  <c8y-breadcrumb-item [label]=\"'LWM2M post-operations' | translate\"></c8y-breadcrumb-item>\n</c8y-breadcrumb>\n\n<div class=\"card content-fullpage card--grid grid__col--7-5--md grid__row--auto-min-content\">\n  <div class=\"inner-scroll bg-component\">\n    <div class=\"card-header large-padding separator sticky-top\">\n      <div class=\"h4 m-r-16\" id=\"commands\">\n        {{ 'Commands' | translate }}\n      </div>\n    </div>\n    <div class=\"card-block large-padding\">\n      <form\n        #commandsForm=\"ngForm\"\n        id=\"commandsForm\"\n        class=\"d-flex d-col flex-grow fit-h\"\n        (ngSubmit)=\"save(operations)\"\n      >\n        <div class=\"form-group\">\n          <textarea\n            [(ngModel)]=\"operations.commands\"\n            class=\"form-control\"\n            aria-labelledby=\"commands\"\n            name=\"commands\"\n            rows=\"20\"\n          ></textarea>\n        </div>\n      </form>\n    </div>\n  </div>\n\n  <div class=\"inner-scroll bg-level-1\" tabindex=\"0\">\n    <div class=\"card-block large-padding\">\n      <p class=\"m-b-16\">\n        <i class=\"text-info m-r-4 text-14\" c8yIcon=\"info-circle\"></i>\n        {{\n          'You can enter a set of LWM2M shell commands. Each command will be sent to every newly registered LWM2M device. Each command must be entered in a new line. Use the following syntax for specifying post-registration actions:'\n            | translate\n        }}\n      </p>\n      <pre class=\"bg-level-0 text-pre-normal m-b-0\">\n        <ul class=\"list-unstyled m-b-0\">\n          <li class=\"m-16\" *ngFor=\"let c of exampleCommands\">\n            <p class=\"text-muted\"># {{c.description | translate}}</p>\n            <span class=\"text-danger\">{{c.command}}</span>\n            <span class=\"text-muted\">{{c.resource}}</span>\n          </li>\n        </ul>\n      </pre>\n    </div>\n  </div>\n\n  <div class=\"card-footer large-padding separator grid__col--fullspan\">\n    <button\n      class=\"btn btn-primary\"\n      title=\"{{ 'Save' | translate }}\"\n      type=\"submit\"\n      form=\"commandsForm\"\n      [disabled]=\"commandsForm.valid && !commandsForm.dirty\"\n      [attr.aria-label]=\"'Save' | translate\"\n    >\n      {{ 'Save' | translate }}\n    </button>\n  </div>\n</div>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i2.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "pipe", type: i2.C8yTranslatePipe, name: "translate" }, { kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "ngmodule", type: CoreModule }, { kind: "component", type: i2.BreadcrumbComponent, selector: "c8y-breadcrumb" }, { kind: "component", type: i2.BreadcrumbItemComponent, selector: "c8y-breadcrumb-item", inputs: ["icon", "translate", "label", "path", "injector"] }, { kind: "component", type: i2.TitleComponent, selector: "c8y-title", inputs: ["pageTitleUpdate"] }, { kind: "directive", type: i4.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i4.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i4.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i4.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i4.NgForm, selector: "form:not([ngNoForm]):not([formGroup]),ng-form,[ngForm]", inputs: ["ngFormOptions"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: LWM2MPostOperationsComponent, decorators: [{
            type: Component,
            args: [{ selector: 'lwm2m-post-operations', standalone: true, imports: [CommonModule, CoreModule], template: "<c8y-title>{{ 'LWM2M post-operations' | translate }}</c8y-title>\n<c8y-breadcrumb>\n  <c8y-breadcrumb-item\n    [label]=\"'Device types' | translate\"\n    [icon]=\"'c8y-device-protocols'\"\n  ></c8y-breadcrumb-item>\n  <c8y-breadcrumb-item [label]=\"'LWM2M post-operations' | translate\"></c8y-breadcrumb-item>\n</c8y-breadcrumb>\n\n<div class=\"card content-fullpage card--grid grid__col--7-5--md grid__row--auto-min-content\">\n  <div class=\"inner-scroll bg-component\">\n    <div class=\"card-header large-padding separator sticky-top\">\n      <div class=\"h4 m-r-16\" id=\"commands\">\n        {{ 'Commands' | translate }}\n      </div>\n    </div>\n    <div class=\"card-block large-padding\">\n      <form\n        #commandsForm=\"ngForm\"\n        id=\"commandsForm\"\n        class=\"d-flex d-col flex-grow fit-h\"\n        (ngSubmit)=\"save(operations)\"\n      >\n        <div class=\"form-group\">\n          <textarea\n            [(ngModel)]=\"operations.commands\"\n            class=\"form-control\"\n            aria-labelledby=\"commands\"\n            name=\"commands\"\n            rows=\"20\"\n          ></textarea>\n        </div>\n      </form>\n    </div>\n  </div>\n\n  <div class=\"inner-scroll bg-level-1\" tabindex=\"0\">\n    <div class=\"card-block large-padding\">\n      <p class=\"m-b-16\">\n        <i class=\"text-info m-r-4 text-14\" c8yIcon=\"info-circle\"></i>\n        {{\n          'You can enter a set of LWM2M shell commands. Each command will be sent to every newly registered LWM2M device. Each command must be entered in a new line. Use the following syntax for specifying post-registration actions:'\n            | translate\n        }}\n      </p>\n      <pre class=\"bg-level-0 text-pre-normal m-b-0\">\n        <ul class=\"list-unstyled m-b-0\">\n          <li class=\"m-16\" *ngFor=\"let c of exampleCommands\">\n            <p class=\"text-muted\"># {{c.description | translate}}</p>\n            <span class=\"text-danger\">{{c.command}}</span>\n            <span class=\"text-muted\">{{c.resource}}</span>\n          </li>\n        </ul>\n      </pre>\n    </div>\n  </div>\n\n  <div class=\"card-footer large-padding separator grid__col--fullspan\">\n    <button\n      class=\"btn btn-primary\"\n      title=\"{{ 'Save' | translate }}\"\n      type=\"submit\"\n      form=\"commandsForm\"\n      [disabled]=\"commandsForm.valid && !commandsForm.dirty\"\n      [attr.aria-label]=\"'Save' | translate\"\n    >\n      {{ 'Save' | translate }}\n    </button>\n  </div>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.LWM2MPostOperationsParametersService }, { type: i2.AlertService }], propDecorators: { commandsForm: [{
                type: ViewChild,
                args: ['commandsForm']
            }] } });

/**
 * Generated bundle index. Do not edit.
 */

export { LWM2MPostOperationsComponent };
//# sourceMappingURL=c8y-ngx-components-protocol-lwm2m-components-post-registration-operations.mjs.map
