// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Link from "../../src/client/Link.js";
import * as Parser from "../../src/client/Parser.js";
import * as Navigation from "../../src/client/Navigation.js";

function fromString(str) {
  if (str.length > 0) {
    return {
      TAG: "JourneyId",
      _0: str
    };
  }
}

function toString(str) {
  return str._0;
}

let parser = Parser.custom(fromString);

let JourneyId = {
  fromString: fromString,
  toString: toString,
  parser: parser
};

function journeySubToString(sub) {
  switch (sub) {
    case "JourneyOverview" :
      return "";
    case "JourneyMap" :
      return "/map";
    case "JourneyLog" :
      return "/log";
    case "JourneySettings" :
      return "/settings";
  }
}

let journeySubParser = Parser.oneOf([
  Parser.map(Parser.s("map"), () => "JourneyMap"),
  Parser.map(Parser.s("log"), () => "JourneyLog"),
  Parser.map(Parser.s("settings"), () => "JourneySettings"),
  Parser.map(Parser.top, () => "JourneyOverview")
]);

let parser$1 = Parser.oneOf([
  Parser.map(Parser.top, () => "Home"),
  Parser.map(Parser.s("mood"), () => "MoodInput"),
  Parser.map(Parser.andThen(Parser.andThen(Parser.s("journey"), parser), journeySubParser), param => ({
    TAG: "Journey",
    _0: param[0][1],
    _1: param[1]
  })),
  Parser.map(Parser.s("profile"), () => "Profile"),
  Parser.map(Parser.andThen(Parser.andThen(Parser.s("search"), Parser.queryRequired("q")), Parser.queryInt("page")), param => ({
    TAG: "Search",
    query: param[0][1],
    page: param[1]
  }))
]);

function toString$1(route) {
  if (typeof route !== "object") {
    switch (route) {
      case "Home" :
        return "/";
      case "MoodInput" :
        return "/mood";
      case "Profile" :
        return "/profile";
      case "NotFound" :
        return "/not-found";
    }
  } else {
    if (route.TAG === "Journey") {
      return "/journey/" + route._0._0 + journeySubToString(route._1);
    }
    let page = route.page;
    let pageParam = page !== undefined ? "&page=" + String(page) : "";
    return "/search?q=" + encodeURIComponent(route.query) + pageParam;
  }
}

function fromUrl(url) {
  let route = Parser.parse(parser$1, url);
  if (route !== undefined) {
    return route;
  } else {
    return "NotFound";
  }
}

let Nav = Navigation.Make({
  toString: toString$1
});

let Link$1 = Link.Make({
  toString: toString$1
});

export {
  JourneyId,
  journeySubToString,
  journeySubParser,
  parser$1 as parser,
  toString$1 as toString,
  fromUrl,
  Nav,
  Link$1 as Link,
}
/* parser Not a pure module */
