import { Disposable, ICommandService, IUniverInstanceService, UniverInstanceType, Workbook } from '@univerjs/core';
import { SetSelectionsOperation } from '@univerjs/sheets';

export class JnpfSheetsRangeService extends Disposable {
  constructor(
    @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
    @ICommandService private readonly _commandService: ICommandService,
  ) {
    super();
  }

  // 恢复选区
  public recoveryRange(row: number, col: number) {
    const unit = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
    const unitId = unit!.getUnitId();
    const sheet = unit!.getActiveSheet();
    const subUnitId = sheet?.getSheetId();

    this._commandService
      .executeCommand(SetSelectionsOperation.id, {
        selections: [
          {
            range: {
              endColumn: col,
              endRow: row,
              rangeType: 0,
              startColumn: col,
              startRow: row,
            },
          },
        ],
        subUnitId,
        type: 2,
        unitId,
      })
      .then();
  }
}
