text: sap.ui.define(["sap/ui/core/mvc/Controller",
  	"sap/m/MessageBox",
  	"./utilities",
  	"sap/ui/core/routing/History"
  ], function (BaseController, MessageBox, Utilities, History) {
  	"use strict";
  
  	return BaseController.extend("com.sap.build.standard.untitledPrototype.controller.Page12", {
  		handleRouteMatched: function (oEvent) {
  			var sAppId = "App5eb047adcc19661f91af43fb";
  
  			var oParams = {};
  
  			if (oEvent.mParameters.data.context) {
  				this.sContext = oEvent.mParameters.data.context;
  
  			} else {
  				if (this.getOwnerComponent().getComponentData()) {
  					var patternConvert = function (oParam) {
  						if (Object.keys(oParam).length !== 0) {
  							for (var prop in oParam) {
  								if (prop !== "sourcePrototype" && prop.includes("Set")) {
  									return prop + "(" + oParam[prop][0] + ")";
  								}
  							}
  						}
  					};
  
  					this.sContext = patternConvert(this.getOwnerComponent().getComponentData().startupParameters);
  
  				}
  			}
  
  			var oPath;
  
  			if (this.sContext) {
  				oPath = {
  					path: "/" + this.sContext,
  					parameters: oParams
  				};
  				this.getView().bindObject(oPath);
  			}
  
  		},
  		_onToggleButtonPress: function (oEvent) {
  			var oToolPage = oEvent.getSource().getParent().getParent();
  			var oSideNavigation = oToolPage.getAggregation('sideContent');
  			var bExpanded = oSideNavigation.getExpanded();
  			oSideNavigation.setExpanded(!bExpanded);
  
  		},
  		_onButtonPress: function (oEvent) {
  
  			var oBindingContext = oEvent.getSource().getBindingContext();
  
  			return new Promise(function (fnResolve) {
  
  				this.doNavigate("Page1", oBindingContext, fnResolve, "");
  			}.bind(this)).catch(function (err) {
  				if (err !== undefined) {
  					MessageBox.error(err.message);
  				}
  			});
  
  		},
  		doNavigate: function (sRouteName, oBindingContext, fnPromiseResolve, sViaRelation) {
  			var sPath = (oBindingContext) ? oBindingContext.getPath() : null;
  			var oModel = (oBindingContext) ? oBindingContext.getModel() : null;
  
  			var sEntityNameSet;
  			if (sPath !== null && sPath !== "") {
  				if (sPath.substring(0, 1) === "/") {
  					sPath = sPath.substring(1);
  				}
  				sEntityNameSet = sPath.split("(")[0];
  			}
  			var sNavigationPropertyName;
  			var sMasterContext = this.sMasterContext ? this.sMasterContext : sPath;
  
  			if (sEntityNameSet !== null) {
  				sNavigationPropertyName = sViaRelation || this.getOwnerComponent().getNavigationPropertyForNavigationWithContext(sEntityNameSet,
  					sRouteName);
  			}
  			if (sNavigationPropertyName !== null && sNavigationPropertyName !== undefined) {
  				if (sNavigationPropertyName === "") {
  					this.oRouter.navTo(sRouteName, {
  						context: sPath,
  						masterContext: sMasterContext
  					}, false);
  				} else {
  					oModel.createBindingContext(sNavigationPropertyName, oBindingContext, null, function (bindingContext) {
  						if (bindingContext) {
  							sPath = bindingContext.getPath();
  							if (sPath.substring(0, 1) === "/") {
  								sPath = sPath.substring(1);
  							}
  						} else {
  							sPath = "undefined";
  						}
  
  						// If the navigation is a 1-n, sPath would be "undefined" as this is not supported in Build
  						if (sPath === "undefined") {
  							this.oRouter.navTo(sRouteName);
  						} else {
  							this.oRouter.navTo(sRouteName, {
  								context: sPath,
  								masterContext: sMasterContext
  							}, false);
  						}
  					}.bind(this));
  				}
  			} else {
  				this.oRouter.navTo(sRouteName);
  			}
  
  			if (typeof fnPromiseResolve === "function") {
  				fnPromiseResolve();
  			}
  
  		},
  		_onNavigationListItemSelect: function (oEvent) {
  
  			var oBindingContext = oEvent.getSource().getBindingContext();
  
  			return new Promise(function (fnResolve) {
  
  				this.doNavigate("Page4", oBindingContext, fnResolve, "");
  			}.bind(this)).catch(function (err) {
  				if (err !== undefined) {
  					MessageBox.error(err.message);
  				}
  			});
  
  		},
  		_onNavigationListItemSelect1: function (oEvent) {
  
  			var oBindingContext = oEvent.getSource().getBindingContext();
  
  			return new Promise(function (fnResolve) {
  
  				this.doNavigate("Page2", oBindingContext, fnResolve, "");
  			}.bind(this)).catch(function (err) {
  				if (err !== undefined) {
  					MessageBox.error(err.message);
  				}
  			});
  
  		},
  		_onNavigationListItemSelect2: function (oEvent) {
  
  			var oBindingContext = oEvent.getSource().getBindingContext();
  
  			return new Promise(function (fnResolve) {
  
  				this.doNavigate("Page3", oBindingContext, fnResolve, "");
  			}.bind(this)).catch(function (err) {
  				if (err !== undefined) {
  					MessageBox.error(err.message);
  				}
  			});
  
  		},
  		_onNavigationListItemSelect3: function (oEvent) {
  
  			var oBindingContext = oEvent.getSource().getBindingContext();
  
  			return new Promise(function (fnResolve) {
  
  				this.doNavigate("Page4", oBindingContext, fnResolve, "");
  			}.bind(this)).catch(function (err) {
  				if (err !== undefined) {
  					MessageBox.error(err.message);
  				}
  			});
  
  		},
  		_onNavigationListItemSelect4: function (oEvent) {
  
  			var oBindingContext = oEvent.getSource().getBindingContext();
  
  			return new Promise(function (fnResolve) {
  
  				this.doNavigate("Page14", oBindingContext, fnResolve, "");
  			}.bind(this)).catch(function (err) {
  				if (err !== undefined) {
  					MessageBox.error(err.message);
  				}
  			});
  
  		},
  		_onNavigationListItemSelect5: function (oEvent) {
  
  			var oBindingContext = oEvent.getSource().getBindingContext();
  
  			return new Promise(function (fnResolve) {
  
  				this.doNavigate("Page15", oBindingContext, fnResolve, "");
  			}.bind(this)).catch(function (err) {
  				if (err !== undefined) {
  					MessageBox.error(err.message);
  				}
  			});
  
  		},
  		_onNavigationListItemSelect6: function (oEvent) {
  
  			var oBindingContext = oEvent.getSource().getBindingContext();
  
  			return new Promise(function (fnResolve) {
  
  				this.doNavigate("Page16", oBindingContext, fnResolve, "");
  			}.bind(this)).catch(function (err) {
  				if (err !== undefined) {
  					MessageBox.error(err.message);
  				}
  			});
  
  		},
  		_onNavigationListItemFirstLevelSelect: function (oEvent) {
  
  			var oBindingContext = oEvent.getSource().getBindingContext();
  
  			return new Promise(function (fnResolve) {
  
  				this.doNavigate("Page5", oBindingContext, fnResolve, "");
  			}.bind(this)).catch(function (err) {
  				if (err !== undefined) {
  					MessageBox.error(err.message);
  				}
  			});
  
  		},
  		_onNavigationListItemFirstLevelSelect1: function (oEvent) {
  
  			var oBindingContext = oEvent.getSource().getBindingContext();
  
  			return new Promise(function (fnResolve) {
  
  				this.doNavigate("Page12", oBindingContext, fnResolve, "");
  			}.bind(this)).catch(function (err) {
  				if (err !== undefined) {
  					MessageBox.error(err.message);
  				}
  			});
  
  		},
  		_onButtonPress1: function (oEvent) {
  
  			var oBindingContext = oEvent.getSource().getBindingContext();
  
  			return new Promise(function (fnResolve) {
  
  				this.doNavigate("Page8", oBindingContext, fnResolve, "");
  			}.bind(this)).catch(function (err) {
  				if (err !== undefined) {
  					MessageBox.error(err.message);
  				}
  			});
  
  		},
  		_onButtonPress2: function (oEvent) {
  
  			oEvent = jQuery.extend(true, {}, oEvent);
  			return new Promise(function (fnResolve) {
  					fnResolve(true);
  				})
  				.then(function (result) {
  					return new Promise(function (fnResolve) {
  						sap.m.MessageBox.confirm("¿Esta seguro que no quiere guardar los cambios?", {
  							title: "Cancelar",
  							actions: ["Sí", "No"],
  							onClose: function (sActionClicked) {
  								fnResolve(sActionClicked === "Sí");
  							}
  						});
  					});
  
  				}.bind(this))
  				.then(function (result) {
  					if (result === false) {
  						return false;
  					} else {
  
  						var oBindingContext = oEvent.getSource().getBindingContext();
  
  						return new Promise(function (fnResolve) {
  
  							this.doNavigate("Page6", oBindingContext, fnResolve, "");
  						}.bind(this));
  
  					}
  				}.bind(this)).catch(function (err) {
  					if (err !== undefined) {
  						MessageBox.error(err.message);
  					}
  				});
  		},
  		_onButtonPress3: function (oEvent) {
  
  			oEvent = jQuery.extend(true, {}, oEvent);
  			return new Promise(function (fnResolve) {
  					fnResolve(true);
  				})
  				.then(function (result) {
  					return new Promise(function (fnResolve) {
  						sap.m.MessageBox.confirm("Su respuesta ha sido añadida exitosamente.", {
  							title: "Respuesta añadida",
  							actions: ["Ok", ""],
  							onClose: function (sActionClicked) {
  								fnResolve(sActionClicked === "Ok");
  							}
  						});
  					});
  
  				}.bind(this))
  				.then(function (result) {
  					if (result === false) {
  						return false;
  					} else {
  						var oView = this.getView(),
  							oController = this,
  							status = true,
  							requiredFieldInfo = [];
  						if (requiredFieldInfo.length) {
  							status = this.handleChangeValuestate(requiredFieldInfo, oView);
  						}
  						if (status) {
  							return new Promise(function (fnResolve, fnReject) {
  								var oModel = oController.oModel;
  
  								var fnResetChangesAndReject = function (sMessage) {
  									oModel.resetChanges();
  									fnReject(new Error(sMessage));
  								};
  								if (oModel && oModel.hasPendingChanges()) {
  									oModel.submitChanges({
  										success: function (oResponse) {
  											var oBatchResponse = oResponse.__batchResponses[0];
  											var oChangeResponse = oBatchResponse.__changeResponses && oBatchResponse.__changeResponses[0];
  											if (oChangeResponse && oChangeResponse.data) {
  												var sNewContext = oModel.getKey(oChangeResponse.data);
  												oView.unbindObject();
  												oView.bindObject({
  													path: "/" + sNewContext
  												});
  												if (window.history && window.history.replaceState) {
  													window.history.replaceState(undefined, undefined, window.location.hash.replace(encodeURIComponent(oController.sContext),
  														encodeURIComponent(sNewContext)));
  												}
  												oModel.refresh();
  												fnResolve();
  											} else if (oChangeResponse && oChangeResponse.response) {
  												fnResetChangesAndReject(oChangeResponse.message);
  											} else if (!oChangeResponse && oBatchResponse.response) {
  												fnResetChangesAndReject(oBatchResponse.message);
  											} else {
  												oModel.refresh();
  												fnResolve();
  											}
  										},
  										error: function (oError) {
  											fnReject(new Error(oError.message));
  										}
  									});
  								} else {
  									fnResolve();
  								}
  							});
  						}
  					}
  				}.bind(this))
  				.then(function (result) {
  					if (result === false) {
  						return false;
  					} else {
  
  						var oBindingContext = oEvent.getSource().getBindingContext();
  
  						return new Promise(function (fnResolve) {
  
  							this.doNavigate("Page6", oBindingContext, fnResolve, "");
  						}.bind(this));
  
  					}
  				}.bind(this)).catch(function (err) {
  					if (err !== undefined) {
  						MessageBox.error(err.message);
  					}
  				});
  		},
  		handleChangeValuestate: function (requiredFieldInfo, oView) {
  			var status = true;
  			if (requiredFieldInfo) {
  				requiredFieldInfo.forEach(function (requiredinfo) {
  					var input = oView.byId(requiredinfo.id);
  					if (input) {
  						input.setValueState("None"); //initially set ValueState to None
  						if (input.getValue() === '') {
  							input.setValueState("Error"); //input is blank set ValueState to error
  							status = false;
  						} else if (input.getDateValue && !input._bValid) { //since 1.64 ui5 will be providing a function 'isValidValue' that can be used here.
  							input.setValueState("Error"); //Invalid Date set ValueState to error
  							status = false;
  						}
  					}
  				});
  			}
  			return status;
  
  		},
  		applyFiltersAndSorters: function (sControlId, sAggregationName, chartBindingInfo) {
  			if (chartBindingInfo) {
  				var oBindingInfo = chartBindingInfo;
  			} else {
  				var oBindingInfo = this.getView().byId(sControlId).getBindingInfo(sAggregationName);
  			}
  			var oBindingOptions = this.updateBindingOptions(sControlId);
  			this.getView().byId(sControlId).bindAggregation(sAggregationName, {
  				model: oBindingInfo.model,
  				path: oBindingInfo.path,
  				parameters: oBindingInfo.parameters,
  				template: oBindingInfo.template,
  				templateShareable: true,
  				sorter: oBindingOptions.sorters,
  				filters: oBindingOptions.filters
  			});
  
  		},
  		updateBindingOptions: function (sCollectionId, oBindingData, sSourceId) {
  			this.mBindingOptions = this.mBindingOptions || {};
  			this.mBindingOptions[sCollectionId] = this.mBindingOptions[sCollectionId] || {};
  
  			var aSorters = this.mBindingOptions[sCollectionId].sorters;
  			var aGroupby = this.mBindingOptions[sCollectionId].groupby;
  
  			// If there is no oBindingData parameter, we just need the processed filters and sorters from this function
  			if (oBindingData) {
  				if (oBindingData.sorters) {
  					aSorters = oBindingData.sorters;
  				}
  				if (oBindingData.groupby || oBindingData.groupby === null) {
  					aGroupby = oBindingData.groupby;
  				}
  				// 1) Update the filters map for the given collection and source
  				this.mBindingOptions[sCollectionId].sorters = aSorters;
  				this.mBindingOptions[sCollectionId].groupby = aGroupby;
  				this.mBindingOptions[sCollectionId].filters = this.mBindingOptions[sCollectionId].filters || {};
  				this.mBindingOptions[sCollectionId].filters[sSourceId] = oBindingData.filters || [];
  			}
  
  			// 2) Reapply all the filters and sorters
  			var aFilters = [];
  			for (var key in this.mBindingOptions[sCollectionId].filters) {
  				aFilters = aFilters.concat(this.mBindingOptions[sCollectionId].filters[key]);
  			}
  
  			// Add the groupby first in the sorters array
  			if (aGroupby) {
  				aSorters = aSorters ? aGroupby.concat(aSorters) : aGroupby;
  			}
  
  			var aFinalFilters = aFilters.length > 0 ? [new sap.ui.model.Filter(aFilters, true)] : undefined;
  			return {
  				filters: aFinalFilters,
  				sorters: aSorters
  			};
  
  		},
  		onInit: function () {
  			this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
  			this.oRouter.getTarget("Page12").attachDisplay(jQuery.proxy(this.handleRouteMatched, this));
  
  			this.oModel = this.getOwnerComponent().getModel();
  
  			var oView = this.getView(),
  				oData = {},
  				self = this;
  			var oModel = new sap.ui.model.json.JSONModel();
  			oView.setModel(oModel, "staticDataModel");
  			self.oBindingParameters = {};
  
  			oData[
  				"sap_tnt_ToolPageWithSideNav_0-mainContents-sap_ui_layout_BlockLayout-1588622528863-content-sap_ui_layout_BlockLayoutRow-1590355152720-content-sap_ui_layout_BlockLayoutCell-1-2e83mmu86zyh7gemqqnbdtp26_S6-content-build_simple_form_Form-1590355866113-formContainers-build_simple_form_FormContainer-1-formElements-build_simple_form_FormElement-3-f7asnrcn1aulp5bcenln7onu8_S8-fields-sap_ui_richtexteditor_RichTextEditor-1590358377611-x24i2qnqd7bv9kg9me1rutrn11_S11"
  			] = {};
  
  			oView.getModel("staticDataModel").setData(oData, true);
  
  			function dateDimensionFormatter(oDimensionValue, sTextValue) {
  				var oValueToFormat = sTextValue !== undefined ? sTextValue : oDimensionValue;
  				if (oValueToFormat instanceof Date) {
  					var oFormat = sap.ui.core.format.DateFormat.getDateInstance({
  						style: "short"
  					});
  					return oFormat.format(oValueToFormat);
  				}
  				return oValueToFormat;
  			}
  
  		},
  		onAfterRendering: function () {
  
  			var oChart,
  				self = this,
  				oBindingParameters = this.oBindingParameters,
  				oView = this.getView();
  
  		}
  	});
  }, /* bExport= */ true);