import { LisioBooleanParameterNames } from "@lisio/lisio-profils";

import LisioDictionaryAdapter from "../../adapters/lisio-dictionary-adapter";
import { Lisio } from "../../lisio";

function lisioEncodeProfilesResponseMessageHandler(this: Lisio, datas: string) {
  const profils: string = JSON.parse(datas);
  document.getSelection()?.removeAllRanges();
  const dictionaryAdapter = this.adapters.get(
    LisioBooleanParameterNames.VOCA,
  ) as LisioDictionaryAdapter | undefined;
  if (dictionaryAdapter != undefined && dictionaryAdapter.query != undefined) {
    window.open(
      `${import.meta.env.VITE_PHP_SERVER}/IM_GenerationMinisite.php?fic_id=3493&wsu=lisiojs${import.meta.env.VITE_TEST_MODE}&params=${profils}&url=https://www.larousse.fr/dictionnaires/francais/${dictionaryAdapter.query}/`,
      "",
      `top:0, left:0, width:${window.innerWidth}, height:${window.innerHeight}`,
    );
  }
}

export { lisioEncodeProfilesResponseMessageHandler };
