import type { UIEventStateContext } from '@blockeditor/block-std';
import type { ReactiveController } from 'lit';

import type { KanbanViewSelectionWithType } from '../../../_common/utils/index.js';
import type { DataViewKanban } from '../kanban-view.js';

export class KanbanClipboardController implements ReactiveController {
  constructor(public host: DataViewKanban) {
    host.addController(this);
  }

  private get readonly() {
    return this.host.view.readonly;
  }

  hostConnected() {
    this.host.disposables.add(
      this.host.handleEvent('copy', ctx => {
        const kanbanSelection = this.host.selectionController.selection;
        if (!kanbanSelection) return false;

        this._onCopy(ctx, kanbanSelection).catch(console.error);
        return true;
      })
    );

    this.host.disposables.add(
      this.host.handleEvent('paste', ctx => {
        if (this.readonly) return false;

        this._onPaste(ctx);
        return true;
      })
    );
  }

  private _onCopy = async (
    _context: UIEventStateContext,
    _kanbanSelection: KanbanViewSelectionWithType
  ) => {
    // todo
    return true;
  };

  private _onPaste = (_context: UIEventStateContext) => {
    // todo
    return true;
  };
}
