/**
 * @mergeTarget
 * @module Src/Screens/Accessibility
 */

import {
  LisioCategory,
  LisioCategoryNames,
  LisioParameterNames,
  LisioProfileNames,
  LisioUser,
} from "@lisio/lisio-profils";
import { LisioScreen } from "../lisio-screen";
import {
  BooleanParameterRenderObject,
  StringParameterRenderObject,
  NumberParameterRenderObject,
  ComponentAndPosition,
  CategoryRenderObject,
  ProfileRenderObject,
  VisualCategoryNames,
  MergedCategoriesNames,
  ScreenNames,
} from "../screen-types";
import { ListContainer } from "../../components/containers/list-container/list-container";
import { DaltonismScreen } from "../daltonism/daltonism-screen";
import { HomeScreen } from "../home/home-screen";
import { LisioComponent } from "@lisio/lisio-engine";
import { MoreScreen } from "../more/more-screen";

/**
 * Class representing an accessibility screen component extending LisioScreen.\
 * It aims to represent an accessibility screen component.\
 * An accessibility screen component is basically a component to render all accessibility categories, profiles and parameters.\
 */
class AccessibilityScreen extends LisioScreen {
  /**
   * Protected attribute to store category render objects
   * @source
   */
  protected _categoryRenderObjects: Map<
    MergedCategoriesNames,
    CategoryRenderObject
  > = new Map<MergedCategoriesNames, CategoryRenderObject>([
    [
      LisioCategoryNames.DALTONISM,
      {
        buttonId: "daltonism",
        titleId: "daltonism-button",
        nextScreenName: DaltonismScreen.name,
        position: 1,
        isActive: false,
        activeSubObjects: new Set(),
        firstIconClasses: ["primary"],
        iconsClasses: ["grey"],
        cssClasses: ["secondary", "space-between"],
      },
    ],
    [
      VisualCategoryNames.MORE,
      {
        buttonId: `${this.id}-more`,
        icon: {
          fileName: "footer-icons",
          iconName: "More",
        },
        titleId: "more-button",
        nextScreenName: MoreScreen.name,
        position: 10,
        isActive: false,
        activeSubObjects: new Set(),
        firstIconClasses: ["grey2"],
        iconsClasses: ["grey"],
        cssClasses: ["secondary", "footer-button"],
      },
    ],
  ]);

  /**
   * Protected attribute to store profile render objects
   * @source
   */
  protected _profileRenderObjects: Map<LisioProfileNames, ProfileRenderObject> =
    new Map<LisioProfileNames, ProfileRenderObject>([
      [
        LisioProfileNames.DYSLEXIA,
        {
          buttonId: "dyslexia",
          titleId: "dyslexia-button",
          position: 0,
          name: LisioProfileNames.DYSLEXIA,
          value: false,
          cssClasses: ["width-100", "btn-pill", "secondary", "space-between"],
          infoBoxes: [
            {
              textId: "infobox-dyslexia",
              cssClassesText: ["info-text"],
            },
          ],
        },
      ],
      [
        LisioProfileNames.GLASS_X2,
        {
          buttonId: "glass-x2",
          titleId: "glass-x2-button",
          position: 2,
          name: LisioProfileNames.GLASS_X2,
          value: false,
          cssClasses: ["width-100", "btn-pill", "secondary", "space-between"],
          infoBoxes: [
            {
              textId: "infobox-glass-x2",
              cssClassesText: ["info-text"],
            },
          ],
        },
      ],
      [
        LisioProfileNames.GLASS_X4,
        {
          buttonId: "glass-x4",
          titleId: "glass-x4-button",
          position: 3,
          name: LisioProfileNames.GLASS_X4,
          value: false,
          cssClasses: ["width-100", "btn-pill", "secondary", "space-between"],
          infoBoxes: [
            {
              textId: "infobox-glass-x4",
              cssClassesText: ["info-text"],
            },
          ],
        },
      ],
      [
        LisioProfileNames.EPILEPSY,
        {
          buttonId: "epilepsy",
          titleId: "epilepsy-button",
          position: 4,
          name: LisioProfileNames.EPILEPSY,
          value: false,
          cssClasses: ["width-100", "btn-pill", "secondary", "space-between"],
          infoBoxes: [
            {
              textId: "infobox-epilepsy",
              cssClassesText: ["info-text"],
            },
          ],
        },
      ],
      [
        LisioProfileNames.MOVEMENTS,
        {
          buttonId: "movements",
          titleId: "movements-button",
          position: 5,
          name: LisioProfileNames.MOVEMENTS,
          value: false,
          cssClasses: ["width-100", "btn-pill", "secondary", "space-between"],
          infoBoxes: [
            {
              textId: "infobox-movements",
              cssClassesText: ["info-text"],
            },
          ],
        },
      ],
      [
        LisioProfileNames.GESTURES,
        {
          buttonId: "gestures",
          titleId: "gestures-button",
          position: 6,
          name: LisioProfileNames.GESTURES,
          value: false,
          cssClasses: ["width-100", "btn-pill", "secondary", "space-between"],
          infoBoxes: [
            {
              textId: "infobox-gestures",
              cssClassesText: ["info-text"],
            },
          ],
        },
      ],
      [
        LisioProfileNames.FOCUS,
        {
          buttonId: "focus",
          titleId: "focus-button",
          position: 7,
          name: LisioProfileNames.FOCUS,
          value: false,
          cssClasses: ["width-100", "btn-pill", "secondary", "space-between"],
          infoBoxes: [
            {
              textId: "infobox-focus",
              cssClassesText: ["info-text"],
            },
          ],
        },
      ],
      [
        LisioProfileNames.DICTIONARY,
        {
          buttonId: "dictionary",
          titleId: "dictionary-button",
          position: 8,
          name: LisioProfileNames.DICTIONARY,
          value: false,
          cssClasses: ["width-100", "btn-pill", "secondary", "space-between"],
          infoBoxes: [
            {
              textId: "infobox-dictionary",
              cssClassesText: ["info-text"],
            },
          ],
        },
      ],
      [
        LisioProfileNames.DARK_MODE,
        {
          buttonId: "dark-mode",
          titleId: "dark-mode-button",
          position: 9,
          name: LisioProfileNames.DARK_MODE,
          value: false,
          cssClasses: ["width-100", "btn-pill", "secondary", "space-between"],
          infoBoxes: [
            {
              textId: "infobox-dark-mode",
              cssClassesText: ["info-text"],
            },
          ],
        },
      ],
    ]);

  /**
   * Protected attribute to store parameter render objects
   * @source
   */
  protected _parameterRenderObjects: Map<
    LisioParameterNames,
    | BooleanParameterRenderObject
    | StringParameterRenderObject
    | NumberParameterRenderObject
  > = new Map<
    LisioParameterNames,
    | BooleanParameterRenderObject
    | StringParameterRenderObject
    | NumberParameterRenderObject
  >();

  /**
   * @async
   * Public method implementing abstract method render of LisioComponent
   * @returns Returns a promise containing the representation of an accessibility screen in HTML string
   * @source
   */
  public async render(): Promise<string> {
    return `
    <section id="${this._id}" role="tabpanel">
      <children></children>
    </section>
    `;
  }

  /**
   * Constructor of class {@link AccessibilityScreen | AccessibilityScreen}
   * @param {(VisualCategoryNames | LisioCategory)[]} categories - Categories to include in this screen
   * @param {LisioProfileNames[]} profileNames - Profiles to include in this screen
   * @param {LisioProfileNames[]} hiddenProfileNames - Profiles to hide
   * @param {LisioUser | undefined} user - Current user
   * @source
   */
  constructor(
    categories: (VisualCategoryNames | LisioCategory)[],
    profileNames: LisioProfileNames[],
    hiddenProfileNames: LisioProfileNames[],
    isCompensation?: boolean,
    user?: LisioUser,
  ) {
    ScreenNames[AccessibilityScreen.name] = "accessibility-screen";
    super(
      AccessibilityScreen.name,
      AccessibilityScreen.name,
      LisioCategoryNames.ACCESSIBILITY,
      HomeScreen.name,
    );
    const categoriesElements: ComponentAndPosition[] =
      this.initCategories(categories);

    const profilesElements: ComponentAndPosition[] = this.initProfiles(
      profileNames,
      hiddenProfileNames,
      user?.profiles,
    );

    const elementsTitleContainer: LisioComponent = this.createScreenTitle(
      "accessibility-title",
    );

    const elements: ComponentAndPosition[] =
      categoriesElements.concat(profilesElements);
    elements.sort((a, b) => a.position - b.position);

    const elementsContainer: LisioComponent = new ListContainer(
      [...elements.map((group) => group.component)],
      undefined,
      ["lines-h", "column", "secondary"],
    );

    const contentAndFooterContainer: LisioComponent = new ListContainer(
      [
        elementsContainer,
        ...(isCompensation ? this.createFooter(isCompensation) : []),
      ],
      undefined,
      ["column", "screen-ul", "width-100"],
    );

    this._children?.push(elementsTitleContainer, contentAndFooterContainer);
  }
}

export { AccessibilityScreen };
