/* eslint-disable jsx-a11y/control-has-associated-label */
import React from "react";
import PropTypes from "prop-types";
import { Divider, Typography } from "@mui/material";
import { Layer } from "mobility-toolbox-js/ol";
import useTranslation from "../../utils/useTranslation";
import GeltungsbereicheLegend, { getLegends, defaultDashArray } from "../../popups/GeltungsbereicheGaPopup/GeltungsbereicheLegend";
export const infos = {
  ga: {
    100: "Freie Fahrt",
    50: "Fahrt zum ermässigten Preis",
    0: "Keine Ermässigung",
    vorOrt: "Gültigkeit vor Ort erfragen",
    footer: true
  },
  tk: {
    100: "Freie Fahrt",
    0: "Keine Ermässigung",
    vorOrt: "Gültigkeit vor Ort erfragen",
    footer: true
  },
  hta: {
    100: "Fahrt zum ermässigten Preis",
    0: "Keine Ermässigung",
    vorOrt: "Gültigkeit vor Ort erfragen",
    footer: true
  },
  sts: {
    100: "Freie Fahrt",
    50: "50% Ermässigung",
    25: "25% Ermässigung",
    0: "Keine Ermässigung",
    vorOrt: "Gültigkeit vor Ort erfragen",
    footer: true
  },
  at: {
    100: "Automatisches Ticketing gültig",
    0: "Automatisches Ticketing nicht gültg",
    footer: true
  }
};
const warranty = {
  de: /*#__PURE__*/React.createElement("i", null, "Aus Platzgr\xFCnden sind, je nach Zoomstufe, nicht alle Linien angegeben.", /*#__PURE__*/React.createElement("br", null), "Alle Angaben ohne Gew\xE4hr. \xC4nderungen vorbehalten.", /*#__PURE__*/React.createElement("br", null), "Es gilt der Anwendungsbereich (", /*#__PURE__*/React.createElement("a", {
    href: "https://www.allianceswisspass.ch/de/tarife-vorschriften/uebersicht",
    rel: "noopener noreferrer",
    target: "_blank"
  }, "\xDCbersicht der Tarife und Vorschriften - Alliance SwissPass"), ")."),
  fr: /*#__PURE__*/React.createElement("i", null, "Faute de place, selon le niveau de zoom, toutes les lignes ne sont pas mentionn\xE9es.", /*#__PURE__*/React.createElement("br", null), "Toutes les indications sont sans garantie. Sous r\xE9serve de modifications.", /*#__PURE__*/React.createElement("br", null), "Le champ d'application fait foi (", /*#__PURE__*/React.createElement("a", {
    href: "https://www.allianceswisspass.ch/fr/tarifs/TarifsPrescriptions",
    rel: "noopener noreferrer",
    target: "_blank"
  }, "Tarifs et prescriptions Vue d'ensemble - Alliance SwissPass"), ")."),
  en: /*#__PURE__*/React.createElement("i", null, "Depending on the zoom level, not all lines shown due to lack of space.", /*#__PURE__*/React.createElement("br", null), "All information without guarantee. Subject to change.", /*#__PURE__*/React.createElement("br", null), "The scope of application applies (", /*#__PURE__*/React.createElement("a", {
    href: "https://www.allianceswisspass.ch/de/tarife-vorschriften/uebersicht",
    rel: "noopener noreferrer",
    target: "_blank"
  }, "\xDCbersicht der Tarife und Vorschriften - Alliance SwissPass"), "\xA0German only)."),
  it: /*#__PURE__*/React.createElement("i", null, "Per mancanza di spazio, a seconda del livello di zoom, non vi figurano tutte le linee.", /*#__PURE__*/React.createElement("br", null), "Tutte le informazioni non sono garantite. Salvo modifiche.", /*#__PURE__*/React.createElement("br", null), "Si applica il campi d'applicazione (", /*#__PURE__*/React.createElement("a", {
    href: "https://www.allianceswisspass.ch/it/Tariffeprescrizioni/Panoramica",
    rel: "noopener noreferrer",
    target: "_blank"
  }, "Tariffe e prescrizioni Panoramica - Alliance SwissPass"), ").")
};
function GbLegendValidity(_ref) {
  let {
    valid = 100,
    legends,
    products,
    productsRemark = null,
    lineDashArray50 = defaultDashArray,
    lineDashArray25 = defaultDashArray,
    text
  } = _ref;
  const {
    t
  } = useTranslation();
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    style: {
      display: "flex",
      gap: 5
    }
  }, legends.filter(_ref2 => {
    let {
      mots: [mot]
    } = _ref2;
    return !!mot;
  }).map(_ref3 => {
    let {
      mots: [mot]
    } = _ref3;
    return /*#__PURE__*/React.createElement(GeltungsbereicheLegend, {
      key: mot,
      mot: mot,
      valid: valid,
      lineDashArray50: lineDashArray50,
      lineDashArray25: lineDashArray25
    });
  })), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement(Typography, {
    paragraph: true
  }, products.map((p, idx, arr) => /*#__PURE__*/React.createElement("b", {
    key: p
    // eslint-disable-next-line react/no-danger
    ,
    dangerouslySetInnerHTML: {
      __html: "".concat(t(p)).concat(idx !== arr.length - 1 ? ", " : "") // We don't use .join() because of html parsing for line breaks
    }
  })), !!productsRemark && /*#__PURE__*/React.createElement("b", null, ", ", t(productsRemark)), products.length || !!productsRemark ? ": " : "", t(text)), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null));
}
GbLegendValidity.propTypes = {
  valid: PropTypes.number,
  legends: PropTypes.arrayOf(PropTypes.object).isRequired,
  products: PropTypes.arrayOf(PropTypes.string).isRequired,
  productsRemark: PropTypes.string,
  lineDashArray50: PropTypes.arrayOf(PropTypes.number),
  lineDashArray25: PropTypes.arrayOf(PropTypes.number),
  text: PropTypes.string.isRequired
};
function GeltungsbereicheLayerInfo(_ref4) {
  let {
    properties: layer
  } = _ref4;
  const {
    t,
    i18n
  } = useTranslation();
  const cardsScope = layer.get("cardsScope") || "ga";
  const cardsInfos = infos[cardsScope];
  const full = infos[cardsScope]["100"];
  const reduced50 = infos[cardsScope]["50"];
  const reduced25 = infos[cardsScope]["25"];
  const none = infos[cardsScope]["0"] || "Keine Ermässigung";
  const {
    vorOrt,
    footer
  } = infos[cardsScope];
  const products = layer.get("products") || [];
  const productsRemark = layer.get("productsRemark");
  const lineDashArray50 = layer.get("lineDashArray50");
  const lineDashArray25 = layer.get("lineDashArray25");
  const legends = getLegends(lineDashArray50, lineDashArray25);
  return /*#__PURE__*/React.createElement("div", {
    style: {
      maxHeight: 450
    }
  }, legends.filter(_ref5 => {
    let {
      mots: [mot]
    } = _ref5;
    return !!mot;
  }).map(_ref6 => {
    let {
      mots: [mot],
      validity
    } = _ref6;
    return /*#__PURE__*/React.createElement(React.Fragment, {
      key: mot + validity
    }, /*#__PURE__*/React.createElement("table", {
      style: {
        borderSpacing: 0
      }
    }, /*#__PURE__*/React.createElement("thead", null), /*#__PURE__*/React.createElement("tbody", null, validity.filter(_ref7 => {
      let {
        value
      } = _ref7;
      return !!cardsInfos["".concat(value)];
    }).map((_ref8, index) => {
      let {
        value
      } = _ref8;
      return /*#__PURE__*/React.createElement("tr", {
        key: mot + value
      }, /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement(GeltungsbereicheLegend, {
        mot: mot,
        valid: value,
        lineDashArray50: lineDashArray50,
        lineDashArray25: lineDashArray25
      })), index === 0 && /*#__PURE__*/React.createElement("td", {
        rowSpan: validity.length,
        style: {
          paddingLeft: 5
        }
      }, t("gb.mot.".concat(mot))));
    }))), /*#__PURE__*/React.createElement("br", null));
  }), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), full && /*#__PURE__*/React.createElement(GbLegendValidity, {
    legends: legends,
    products: products,
    productsRemark: productsRemark,
    text: full
  }), reduced50 && /*#__PURE__*/React.createElement(GbLegendValidity, {
    valid: 50,
    legends: legends,
    products: products,
    productsRemark: productsRemark,
    lineDashArray25: lineDashArray25,
    lineDashArray50: lineDashArray50,
    text: reduced50
  }), reduced25 && /*#__PURE__*/React.createElement(GbLegendValidity, {
    valid: 25,
    legends: legends,
    products: products,
    productsRemark: productsRemark,
    lineDashArray25: lineDashArray25,
    lineDashArray50: lineDashArray50,
    text: reduced25
  }), /*#__PURE__*/React.createElement(GeltungsbereicheLegend, null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement(Typography, {
    paragraph: true
  }, t(none)), !!vorOrt && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(GeltungsbereicheLegend, {
    mot: "ferry",
    valid: -1
  }), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement(Typography, {
    paragraph: true
  }, t("Gültigkeit vor Ort erfragen"))), footer && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement(Divider, null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement(Typography, {
    paragraph: true
  }, /*#__PURE__*/React.createElement("i", null, i18n.exists("".concat(layer.key, ".layerinfo-footer")) ? t("".concat(layer.key, ".layerinfo-footer")) : t("ch.sbb.geltungsbereiche.layerinfo-footer"))), /*#__PURE__*/React.createElement(Typography, {
    paragraph: true
  }, warranty[i18n.language]), /*#__PURE__*/React.createElement("br", null)));
}
GeltungsbereicheLayerInfo.propTypes = {
  properties: PropTypes.instanceOf(Layer).isRequired
};
GeltungsbereicheLayerInfo.renderTitle = (layer, t) => {
  return t("ch.sbb.geltungsbereiche"); // - ${t(`${layer.name || layer.key}`)}`;
};
export default GeltungsbereicheLayerInfo;
//# sourceMappingURL=GeltungsbereicheLayerInfo.js.map