import ControllerExtension from 'sap/ui/core/mvc/ControllerExtension';
import ExtensionAPI from 'sap/fe/templates/ObjectPage/ExtensionAPI';
import MessageBox from 'sap/m/MessageBox';

/**
 * @namespace at.clouddna.books.ext.controller
 * @controller
 */
export default class CustomBookController extends ControllerExtension<ExtensionAPI> {
	static overrides = {
		/**
		 * Called when a controller is instantiated and its View controls (if available) are already created.
		 * Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
		 * @memberOf at.clouddna.books.ext.controller.CustomBookController
		 */
		onInit(this: CustomBookController) {
			// you can access the Fiori elements extensionAPI via this.base.getExtensionAPI
			const model = this.base.getExtensionAPI().getModel();
		},
		editFlow: {
			onBeforeEdit: function (mParameters: any): any {
				(<any>this).getView().getBindingContext().requestProperty("ReadingFinished").then((readingFinished: boolean) => {
					if (readingFinished) {
						MessageBox.warning("Editing will not bepossible as this book was already read.")
					}
				});
			}
		}
	}
}