import {
  ChangeDetectionStrategy,
  Component,<% if(controlValueAccessor) { %>
  forwardRef,
  ViewEncapsulation,<%}%>
} from '@angular/core';<% if(controlValueAccessor) { %>
import {
  AbstractControl,
  ControlValueAccessor,
  NG_VALIDATORS,
  NG_VALUE_ACCESSOR,<% if(standalone) { %>
  ReactiveFormsModule,<% } %>
  ValidationErrors,
  Validator,
} from '@angular/forms';<%}%><% if(standalone) { %>
import {MatButtonModule} from '@angular/material/button';<% } %>

import {<% if(controlValueAccessor) { %>
  type <%= classify(name) %>ComponentData,<%}%>
  <%= classify(name) %>ComponentService,
} from './<%= name %>-component.service';

@Component({
  selector: 'app-<%= name %>',
  templateUrl: './<%= name %>.component.html',
  styleUrls: ['./<%= name %>.component.scss'],<% if(standalone) { %>
  standalone: true,
  imports: [MatButtonModule, ReactiveFormsModule],<% } %>
  changeDetection: ChangeDetectionStrategy.OnPush,<% if(controlValueAccessor) { %>
  providers: [
    <%= classify(name) %>ComponentService,
    {
      provide: NG_VALUE_ACCESSOR,
      useExisting: forwardRef(() => <%= classify(name) %>Component),
      multi: true,
    },
    {
      provide: NG_VALIDATORS,
      useExisting: forwardRef(() => <%= classify(name) %>Component),
      multi: true,
    },
  ],<%}%>
  host: {
    'class': 'app-<%= name %>',<% if(controlValueAccessor) { %>
    '(focusout)': '_onTouched?.()',<%}%>
  },
  encapsulation: ViewEncapsulation.None,
})
export class <%= classify(name) %>Component<% if(controlValueAccessor) { %> implements ControlValueAccessor, Validator<%}%> {<% if(controlValueAccessor) { %>
  /**
   * Keep a reference to the "OnChanged" function provided by angular
   * (ControlValueAccessor)
   */
  private _onChange!: (data: <%= classify(name) %>ComponentData) => void;

  /**
   * Keep a reference for the 'OnTouched' function provided by angular
   * (ControlValueAccessor)
   */
  _onTouched!: () => void;<%}%>

  constructor(private _componentService: <%= classify(name) %>ComponentService) {}<% if(controlValueAccessor) { %>

  /** Implements da ControlValueAccessor */
  writeValue(data: <%= classify(name) %>ComponentData): void {
    throw new Error('Method not implemented.');
  }

  /** Implements ControlValueAccessor */
  registerOnChange(fn: (data: <%= classify(name) %>ComponentData) => void): void {
    this._onChange = fn;
  }

  /** Implements ControlValueAccessor */
  registerOnTouched(fn: () => void): void {
    this._onTouched = fn;
  }

  /** Implements ControlValueAccessor */
  setDisabledState?(isDisabled: boolean): void {
    throw new Error('Method not implemented.');
  }

  /** Implements Validator */
  validate(control: AbstractControl): ValidationErrors {
    throw new Error('Method not implemented.');
  }<%}%>
}
