"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Copy_1 = __importDefault(require("./Copy"));
const types_1 = require("../types");
class DuplicateQueue extends Copy_1.default {
    constructor(connId, src, dest, filter, onState, onConflict, onError, onComplete, watcher) {
        super(connId, src, dest, filter, onState, onConflict, onError, onComplete, watcher, false);
        this.newNames = new Map();
        this.resolve({ type: types_1.QueueActionType.Rename }, true);
    }
    async enqueue(paths, dest) {
        await super.enqueue(paths, dest);
        for (const item of this.queue) {
            if (item.dirs.length) {
                const name = item.dirs[0];
                if (!this.newNames.has(name)) {
                    this.newNames.set(name, await this.rename(name, item.to));
                }
                item.dirs[0] = this.newNames.get(name);
            }
        }
    }
}
exports.default = DuplicateQueue;
