let libFS = require("fs");

fcf.module({
  name: "fcfManagement:templates/pages/translations/translations-tab.receive.js",
  dependencies: [],
  module: function(){
    return class Handler {
      receive(a_fields, a_files) {
        return fcf.actions()
        .each(a_fields.files, (a_language, a_file, a_res, a_act)=>{
          libFS.writeFile(fcf.getPath(a_file), JSON.stringify(a_fields.modify[a_language], false, 2) , "utf8", (a_error)=>{
            if (a_error){
              a_act.error(a_error);
              return;
            }
            a_act.complete();
          });
        })
        .then(()=>{
          return fcf.application.getEventChannel().send("translations")
          .then(()=>{});
        })
      }
    }
  }
});
