var apx = apx || {};
apx.apxprofil = {};
apx.apxprofil.loadwco = async (id, ctx) => {
  console.log(
    `Load wconame:apxauth apx.apxauth.loadwco with id:${id} and ctx: ${JSON.stringify(
      ctx
    )}`
  );
  // Check that in localdb tpl exist if not means it is not authenticated 
  if (!apx.data.tpl[`apxauthscreen${ctx.link}`]) ctx.link="signin";
  const tpldataname = `${apx.data.pagename}_${id}_apxprofil`;
  const destid = document.getElementById(id);
  const data = apx.apxprofil.getdata(id, ctx);
  if (destid.innerHTML.trim() === "") {
    destid.innerHTML = Mustache.render(apx.data.tpl.apxprofilmain, data);
  }
  destid.querySelector(`.screenaction`).innerHTML = Mustache.render(
    apx.data.tpl[`apxprofilscreen${ctx.link}`],
    data
  );
  apxauthid.querySelector(`.msginfo`).innerHTML = "";
};
apx.apxprofil.getdata = (id, ctx) => {
  const tpldataname = `${apx.data.pagename}_${id}_apxauth`;
  const data = JSON.parse(JSON.stringify(apx.data.tpldata[tpldataname]));
  data.id = id;
  data.xalias = apx.data.headers.xalias;
  data.xtribe = apx.data.headers.xtribe;

  data.emailsupport = apx.data?.appdata?.emailsupport
    ? apx.data.appdata.emailsupport
    : "";
  console.log("data:",data)
  switch (ctx.link) {
    case "alias":
      break;
    case "unique":
      break;  
    case "tribes":
      break;
    case "towns":
      break;
    default:
      break;
  }
  console.log("data for tpl:", data);
  return data;
};

apx.apxprofil.gohome=()=>{
  window.location.href=`apxid_${apx.data.headers.xlang}.html`;

}