import { Component, OnDestroy, OnChanges, OnInit, ApplicationRef, ChangeDetectorRef, ViewChild, ElementRef } from '@angular/core';
import { ComponentBase } from './ComponentBase';
import { NzMessageService, UploadChangeParam, UploadXHRArgs } from 'ng-zorro-antd';

@Component({
  selector: 'app-form',
  templateUrl: './form.component.html',
  styleUrls: ['./form.component.css']
})
export class FormComponent extends ComponentBase implements OnInit, OnChanges, OnDestroy {
  // 储存数据用
  saveKey = "dg_video";

  item = {
    "url": "",
    "duration": 0,
    "size": 0,
    "snapshotUrl": "",
    "muteVideoUrl": ""
  }

  // testUrl = "http://staging-teach.cdn.ireadabc.com/0e64dfbfc54a7bd0bb121092f74b130b.mp4";

  constructor(public nzMessageService: NzMessageService, public appRef: ApplicationRef, public changeDetectorRef: ChangeDetectorRef) {
    super(appRef, changeDetectorRef);
  }

  // 截图
  handleOnCapture(e) {
    console.log(e)
    const href = URL.createObjectURL(e)
    const box = document.createElement('a')
    box.download = new Date().getTime() + ".jpg"
    box.href = href
    box.click()
  }

  /**
   * 储存图片数据
   * @param e
   */
  onImageUploadSuccess(e, item, key) {
    item[key] = e.url
    this.save();
  }

  onVideoUploaded(e, item, key) {
    item[key] = e.url.replace(".mp4", "_h.mp4")
    this.save();
  }

}
