import { set } from "lodash";
import { EditorModule } from "..";
import { DesignComp } from "../../objects/DesignTemp/DesignComp";
import { CompObject } from "../../controllers/SelectCtrl/compObj";
import { ICompKeys } from "../../typings";
import { queenApi } from "queenjs";

export const manualActions = EditorModule.action({

 

  updateCompData(comp: DesignComp, path: string, value: any) {
    const { historyCtrl } = this.controls;
    historyCtrl.historyActionDoing = true;
    historyCtrl.historyCombine = true;


    set(comp, path, value);

    // call action method
    historyCtrl.historyCombine = false;
    historyCtrl.historyActionDoing = false;
  },

  updateCompDatas(comp: DesignComp, paths: string[], values: any[]) {
    const { historyCtrl } = this.controls;
    historyCtrl.historyActionDoing = true;
    historyCtrl.historyCombine = true;
    let n = paths.length;
    while(n--) {
      set(comp, paths[n], values[n]);
    }
    // call action method
    historyCtrl.historyCombine = false;
    historyCtrl.historyActionDoing = false;
  },

  submitUpdate() {
    this.controls.historyCtrl.history.submit();
  },
  textFocus(compId:string, focus=true) {
    console.log("text focus", compId,  focus);
  },
});
