import {Component, Input} from '@angular/core';
import {ObjectsService} from "@app/_services";
import {SortableOptions} from "sortablejs";

@Component({
  selector: 'cards-section-items',
  templateUrl: 'cards-section-items.component.html',
  styleUrls: ['cards-section-items.component.scss']
})
export class CardsSectionItemsComponent {
  @Input() section: any;
  @Input() type: any;
  @Input() editMode = false;

  public options: SortableOptions = {
    onUpdate: (event: any) => {
      this.move(event);
    }
  };

  constructor(private objectsService: ObjectsService) {
  }

  get cards() {
    return this.section.objects?.data;
  }

  ngOnInit() {
  }

  move(event: any) {
    this.objectsService.move(event.item.id, {modelType: 'object', modelId: this.section.id, ord: event.newIndex}).subscribe(res => {
    });
  }


}

