import ExtensionAPI from 'sap/fe/core/ExtensionAPI';
import Context from 'sap/ui/model/odata/v4/Context';
// @ts-ignore
import MessageBox, { Action } from 'sap/m/MessageBox';
// @ts-ignore
import { URLHelper } from 'sap/m/library';

/**
 * Generated event handler.
 *
 * @param this reference to the 'this' that the event handler is bound to.
 * @param context the context of the page on which the event was fired. `undefined` for list report page.
 * @param selectedContexts the selected contexts of the table rows.
 */
export function onGoogleSearchPress(this: ExtensionAPI, pageContext: Context | undefined, selectedContexts: Context[]) {
    let isbn: string = pageContext?.getObject().ISBN

    MessageBox.confirm("This will open another window. Do you want to continue?", {
        onClose: (action: Action) => {
            if (action === Action.OK) {
                URLHelper.redirect(`https://www.google.com/search?q=ISBN ${isbn}`, true);
            }
        }
    });
}