import { Component, OnInit } from '@angular/core';
import { NbDialogRef } from '@nebular/theme';
import { MD2Icon } from '../massive-darkness2.model';
import { DialogRef } from '@progress/kendo-angular-dialog';
import { MD2Service } from '../../../services/MD2/md2.service';

@Component({
  selector: 'md2-icon-picker-dlg',
  template: `     <div class="md2-icon-grid">
          <div 
            *ngFor="let iconData of iconList"
            (click)="selectIcon(iconData)"
            class="icon-item" title="{{iconData.name}}"
            [innerHTML]="iconData.html">
          </div>
        </div>
    <!-- <nb-card>
      <nb-card-header>
        <h5>Insert MD2 Icon</h5>
      </nb-card-header>
      <nb-card-body>
   
      </nb-card-body>
      <nb-card-footer>
        <button nbButton status="primary" (click)="cancel()">Cancel</button>
      </nb-card-footer>
    </nb-card> -->
  `,
  styles: [`
  nb-card{
    max-width: 800px;
    z-index: 1050;
  }
    .md2-icon-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
      gap: 10px;
      max-height: 400px;
      overflow-y: auto;
      width:400px;
    }
    .icon-item {
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 10px;
      border: 1px solid #ddd;
      border-radius: 4px;
      transition: all 0.2s;
      font-size: 30px;
    }
    .icon-item:hover {
      background-color: #f0f0f0;
      border-color: #007bff;
      //transform: scale(1.1);
    }
  `]
})
export class MD2IconPickerDlgComponent implements OnInit {

  iconList: Array<{ icon: MD2Icon, name: string, html: string }> = [];

  constructor(
    private dlgRef: DialogRef,
    private md2Service: MD2Service
  ) { }

  ngOnInit(): void {
    // Get all icons
    for (let icon of Object.values(MD2Icon).filter(val => typeof val === 'number') as MD2Icon[]) {
      this.iconList.push({
        icon: icon,
        name: MD2Icon[icon],
        html: this.md2Service.iconHtml(icon)
      });
    }
  }

  selectIcon(iconData: { icon: MD2Icon, name: string, html: string }) {
    this.dlgRef.close(iconData.html);
  }

  cancel() {
    this.dlgRef.close(null);
  }
}

