import React from "react";
import PropTypes from "prop-types";
export const defaultDashArray = [1, 7];
const lineWidth = 3.5;
const colorYellow = "rgba(255, 242, 0, 1)";
const colorRed = "rgba(235, 0, 0, 1)";
const colorBlue = "rgba(42, 102, 152, 1)";
const colorBlack = "rgba(0, 0, 0, 1)";
const colorGray = "rgba(180,180,180, 1)";

// Be aware that order is important here!
export const getLegends = function () {
  let lineDashArray50 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultDashArray;
  let lineDashArray25 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDashArray;
  return [{
    mots: ["rail", "tram", "subway"],
    validity: [{
      value: 100,
      paint: [{
        "line-color": colorRed,
        "line-width": lineWidth
      }]
    }, {
      value: 50,
      paint: [{
        "line-color": colorRed,
        "line-width": lineWidth,
        "line-dasharray": lineDashArray50
      }]
    }, {
      value: 25,
      paint: [{
        "line-color": colorRed,
        "line-width": lineWidth,
        "line-dasharray": lineDashArray25
      }]
    }]
  }, {
    mots: ["bus"],
    validity: [{
      value: 100,
      paint: [{
        "line-color": "rgba(74, 74, 74, 1)",
        "line-width": lineWidth + 0.5
      }, {
        "line-color": colorYellow,
        "line-width": lineWidth
      }]
    }, {
      value: 50,
      paint: [{
        "line-color": "rgba(74, 74, 74, 1)",
        "line-width": lineWidth + 0.5,
        "line-dasharray": lineDashArray50
      }, {
        "line-color": colorYellow,
        "line-width": lineWidth,
        "line-dasharray": lineDashArray50
      }]
    }, {
      value: 25,
      paint: [{
        "line-color": "rgba(74, 74, 74, 1)",
        "line-width": lineWidth + 0.5,
        "line-dasharray": lineDashArray25
      }, {
        "line-color": colorYellow,
        "line-width": lineWidth,
        "line-dasharray": lineDashArray25
      }]
    }]
  }, {
    mots: ["gondola", "funicular"],
    validity: [{
      value: 100,
      paint: [{
        "line-color": colorBlack,
        "line-width": lineWidth
      }]
    }, {
      value: 50,
      paint: [{
        "line-color": colorBlack,
        "line-width": lineWidth,
        "line-dasharray": lineDashArray50
      }]
    }, {
      value: 25,
      paint: [{
        "line-color": colorBlack,
        "line-width": lineWidth,
        "line-dasharray": lineDashArray25
      }]
    }]
  }, {
    mots: ["ferry"],
    validity: [{
      value: 100,
      paint: [{
        "line-color": colorBlue,
        "line-width": lineWidth
      }]
    }, {
      value: 50,
      paint: [{
        "line-color": colorBlue,
        "line-width": lineWidth,
        "line-dasharray": lineDashArray50
      }]
    }, {
      value: 25,
      paint: [{
        "line-color": colorBlue,
        "line-width": lineWidth,
        "line-dasharray": lineDashArray25
      }]
    }, {
      value: -1,
      paint: [{
        "line-color": colorGray,
        "line-width": lineWidth,
        "line-dasharray": defaultDashArray
      }]
    }]
  }, {
    mots: [null],
    validity: [{
      value: null,
      paint: [{
        "line-color": colorGray,
        "line-width": lineWidth
      }]
    }]
  }];
};

// eslint-disable-next-line react/prop-types
function GeltungsbereicheLegend(_ref) {
  var _getLegends$find;
  let {
    mot = null,
    valid = null,
    background = false,
    lineDashArray50 = defaultDashArray,
    lineDashArray25 = defaultDashArray
  } = _ref;
  const legend = (_getLegends$find = getLegends(lineDashArray50, lineDashArray25).find(_ref2 => {
    let {
      mots
    } = _ref2;
    return mots.includes(mot);
  })) === null || _getLegends$find === void 0 ? void 0 : _getLegends$find.validity.find(_ref3 => {
    let {
      value
    } = _ref3;
    if (Array.isArray(value) && !Array.isArray(valid)) {
      return value.includes(valid);
    }
    return value === valid;
  });
  if (!legend) {
    // eslint-disable-next-line no-console
    console.warn("No legend found! Check feature data and extend legend options if necessary");
  }
  return /*#__PURE__*/React.createElement("svg", {
    viewBox: "0 0 50 ".concat(background ? "50" : "10"),
    width: "50",
    height: background ? "50" : "10",
    xmlns: "http://www.w3.org/2000/svg"
  }, background ? /*#__PURE__*/React.createElement("circle", {
    cx: "25",
    cy: "25",
    r: "25",
    fill: "#f5f5f5"
  }) : null, legend === null || legend === void 0 ? void 0 : legend.paint.map(paint => {
    var _paint$lineDasharray;
    return /*#__PURE__*/React.createElement("line", {
      key: paint["line-dasharray"] + paint["line-color"],
      x1: "0",
      y1: background ? "25" : "5",
      x2: "50",
      y2: background ? "25" : "5",
      stroke: paint["line-color"],
      strokeWidth: paint["line-width"],
      strokeDasharray: (_paint$lineDasharray = paint["line-dasharray"]) === null || _paint$lineDasharray === void 0 ? void 0 : _paint$lineDasharray.join(" "),
      strokeLinecap: paint["line-dasharray"] && "round"
    });
  }));
}
GeltungsbereicheLegend.propTypes = {
  mot: PropTypes.string,
  valid: PropTypes.number,
  background: PropTypes.bool,
  lineDashArray50: PropTypes.arrayOf(PropTypes.number),
  lineDashArray25: PropTypes.arrayOf(PropTypes.number)
};
export default GeltungsbereicheLegend;
//# sourceMappingURL=GeltungsbereicheLegend.js.map