import initCtx from "@/utils/ctx.js";

export default function () {
	const {utils} = initCtx(this)

	this.createRoute = function () {
		utils.popup("/ns/routes/createPopup", {
			width: "50em",
			height: "40em",
			callback: function () {
				utils.success("保存成功", function () {
					window.location = "/ns/routes"
				})
			}
		})
	}

	this.selectedType = "isp"
	this.categoryRoutes = []

	this.selectRouteType = function (routeType) {
		this.selectedType = routeType

		if (routeType.startsWith("category:")) {
			const categoryId = parseInt(routeType.substring(routeType.indexOf(":")+1))
			this.categoryRoutes = this.publicRoutes.$findAll((_, route) => {
				return route.categoryId == categoryId
			})
		}
	}
}