import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%>, inject } from '@angular/core';<% if(!modal) { %>
import { ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common';<% } %>
import { SFSchema, SFUISchema } from '@yelon/form';
import { _HttpClient } from '@yelon/theme';
import { NzMessageService } from 'ng-zorro-antd/message';<% if(modal) { %>
import { NzModalRef } from 'ng-zorro-antd/modal';<% } %><% if(standalone) {%>
import { SHARED_IMPORTS } from '@shared';<%}%>

@Component({
  selector: '<%= selector %>',<% if(standalone) {%>
  imports: [...SHARED_IMPORTS],<%}%>
  templateUrl: './<%= dasherize(name) %>.component.html',<% if(!inlineStyle) { %><% } else { %>
    styleUrls: ['./<%= dasherize(name) %>.component.<%= style %>']<% } %><% if(!!viewEncapsulation) { %>,
  encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
  changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
})
export class <%= componentName %> implements OnInit {
  private readonly http = inject(_HttpClient);
  private readonly msgSrv = inject(NzMessageService);<% if(modal) { %>
  private readonly modal = inject(NzModalRef);<% } else { %>
  private readonly route = inject(ActivatedRoute);
  readonly location = inject(Location);<% } %>

  <% if(modal) { %>record: any = {};<% } else { %>
  id = this.route.snapshot.params.id;<% } %>
  i: any;
  schema: SFSchema = {
    properties: {
      no: { type: 'string', title: '编号' },
      owner: { type: 'string', title: '姓名', maxLength: 15 },
      callNo: { type: 'number', title: '调用次数' },
      href: { type: 'string', title: '链接', format: 'uri' },
      description: { type: 'string', title: '描述', maxLength: 140 },
    },
    required: ['owner', 'callNo', 'href', 'description'],
  };
  ui: SFUISchema = {
    '*': {
      spanLabelFixed: 100,
      grid: { span: 12 },
    },
    $no: {
      widget: 'text'
    },
    $href: {
      widget: 'string',
    },
    $description: {
      widget: 'textarea',
      grid: { span: 24 },
    },
  };

  ngOnInit(): void {
    <% if(modal) { %>if (this.record.id > 0)<% } else { %>if (this.id > 0)<% } %>
    this.http.get(`/user/${this.record.id}`).subscribe(res => (this.i = res));
  }

  save(value: any): void {
    this.http.post(`/user/${this.record.id}`, value).subscribe(res => {
      this.msgSrv.success('保存成功');
      this.modal.close(true);
    });
  }<% if(modal) { %>

  close(): void {
    this.modal.destroy();
  }<% } %>
}
