import {
  trigger,
  state,
  style,
  transition,
  animate,
} from '@angular/animations';
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { MatDialogRef } from '@angular/material/dialog';
import { MatDialog } from '@angular/material/dialog';
import { CustomerRegistrationComposeComponent } from './customer-registration-compose.component';

@Component({
  selector: 'message-compose',
  templateUrl: './message-compose.component.html',
  animations: [
    trigger('detailExpand', [
      state('collapsed', style({ height: '0px', minHeight: '0' })),
      state('expanded', style({ height: '*', minHeight: '50px' })),
      transition(
        'expanded <=> collapsed',
        animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')
      ),
    ]),
  ],
})
export class MessageComposeComponent implements OnInit {
  composeForm!: FormGroup;

  dataSource = ELEMENT_DATA;
  columnsToDisplay = ['state', 'content', 'delete', 'applicationDate'];
  expandedElement: PeriodicElement | null | undefined;

  /**
   * Constructor
   */
  constructor(
    public matDialogRef: MatDialogRef<MessageComposeComponent>,
    private _formBuilder: FormBuilder,
    private _matDialog: MatDialog
  ) {}

  // -----------------------------------------------------------------------------------------------------
  // @ Lifecycle hooks
  // -----------------------------------------------------------------------------------------------------

  /**
   * On init
   */
  ngOnInit(): void {
    // Create the form
    this.composeForm = this._formBuilder.group({
      accountHolder: ['', [Validators.required]],
      amount: ['', [Validators.required]],
    });
  }

  // -----------------------------------------------------------------------------------------------------
  // @ Public methods
  // -----------------------------------------------------------------------------------------------------

  /**
   * Save and close
   */
  saveAndClose(): void {
    // Save the message as a draft
    this.saveAsDraft();

    // Close the dialog
    this.matDialogRef.close();
  }

  /**
   * Discard the message
   */
  discard(): void {}

  /**
   * Save the message as a draft
   */
  saveAsDraft(): void {}

  /**
   * Send the message
   */
  send(): void {}
}

export interface PeriodicElement {
  state: string;
  content: string;
  delete: string;
  applicationDate: string;
  description: string;
}

const ELEMENT_DATA: PeriodicElement[] = [
  {
    state: '읽지않음',
    content: '쪽지받아',
    delete: '삭제하기',
    applicationDate: '2022-08-23',
    description: `입금계좌를 알려달라`,
  },
  {
    state: '읽음',
    content: '쪽지읽어랏',
    delete: '삭제하기',
    applicationDate: '2022-08-23',
    description: `하단이미지를 참고해주시기바랍니다`,
  },
  {
    state: '읽지않음',
    content: '함하맣마하맣ㅁ',
    delete: '삭제하기',
    applicationDate: '2022-08-23',
    description: `입금해라입금. 출금해라출금 이로이로ㅓㅁ;ㅇ롱러;올;ㅣㅁㄴ더ㅗ래;ㄷ로ㅑ`,
  },
];
