import {Component, Inject, LOCALE_ID, OnDestroy, OnInit} from '@angular/core';

import {
    Application,
    ApplicationAttributesLocation,
    ApplicationAttributesInfo,
    IApplicationAttributesComponent
} from 'm2-core';


@Component({
  selector: 'm2-contractor-app-view',
  template: `
      <h4>Атрибуты заявки #{{application.uid}}</h4>
      <p>Расположение компонента: <strong>{{location}}</strong></p>
      <p>Всего атрибутов: {{_attributesInfo.attributes.length}}</p>
      
      <pre touchScroller>{{application | json}}</pre>
  `,
  styles: [`
      :host {
          display: block;
          padding: 3rem;
      }

      :host,
      h4 {
          color: darkred;
      }
  `]
})
export class M2ContractorAppViewComponent implements IApplicationAttributesComponent, OnInit, OnDestroy {

    constructor(
        @Inject(LOCALE_ID) private localeId: string
    ) {
    }

    application: Application;

    _attributesInfo: ApplicationAttributesInfo;
    set attributesInfo(value: ApplicationAttributesInfo) {
        this._attributesInfo = value;
        console.log(`attributes set`, value);
    }

    location: ApplicationAttributesLocation;


    comment = `Строка в классе`;


    ngOnInit(): void {
        console.log(`Plugin::M2ContractorAppViewComponent: ngOnInit(), localeId = ${this.localeId}`);
    }

    ngOnDestroy(): void {
        console.log(`Plugin::M2ContractorAppViewComponent: ngOnDestroy()`);
    }

}
