let libFS = require("fs");

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