import { __, sprintf } from "@wordpress/i18n";
import { isObject } from "quickbuilder";
import Swal from "sweetalert2";
// Pro upgrade target for the Settings pro-teaser / license modals. Kept in sync
// with the analytics teaser's upgradeUrl() fallback (ProTeaser.js).
const UPGRADE_URL = "https://betterdocs.co/dashboard-upgrade-to-pro";
export const SweetAlert = (args = {}) => {
return Swal.mixin({
target: args?.target ?? "#betterdocsQuickBuilder",
html: args?.html,
title: args?.title ?? __("Title Goes Here: title", "betterdocs"),
text: args?.text ?? __("Text Goes Here: text", "betterdocs"),
icon: args?.icon ?? (args?.type || "success"),
timer: args?.timer ?? null,
...args,
});
};
const proAlert = (html = null) => {
const tabKey = document.querySelector('li.wprf-tab-nav-item.wprf-active-nav')?.getAttribute('data-key');
let title = __('Upgrade to BetterDocs PRO', 'betterdocs');
let description = __('To access this feature, simply upgrade to BetterDocs PRO for premium access.', 'betterdocs');
if (tabKey === 'tab-ai-chatbot') {
title = __('Upgrade To BetterDocs PRO & Get BetterDocs AI Chatbot Addon', 'betterdocs');
description = __('To access this feature, simply upgrade to BetterDocs PRO, get the BetterDocs AI chatbot Addon, and activate the license keys.', 'betterdocs');
}
let htmlObject = {};
let closeButtonHtml = ``;
if (html === null) {
html = sprintf(
'
' +
'' +
'
' +
'%s
' +
'%s
' +
'' +
'
%s
' +
'
' +
'- %s
' +
'- %s
' +
'- %s
' +
'- %s
' +
'- %s
' +
'- %s
' +
'- %s
' +
'- %s
' +
'
' +
'
' +
'',
title,
description,
__("Here’s what’s inside BetterDocs Pro.", "betterdocs"),
__("Multiple Knowledge Bases", "betterdocs"),
__("Internal Knowledge Base", "betterdocs"),
__("Instant Answer", "betterdocs"),
__("Git Sync", "betterdocs"),
__("Insightful Analytics Report", "betterdocs"),
__("User Role Management", "betterdocs"),
__("Glossaries & Encyclopedia", "betterdocs"),
__("AI-Powered Chatbot", "betterdocs"),
UPGRADE_URL,
__("Upgrade Now", "betterdocs")
);
}
if (isObject(html)) {
htmlObject = html;
html = html.message || html.html;
}
let alertOptions = {
showConfirmButton: false,
showDenyButton: false,
icon: false,
type: "warning",
title: false,
showCloseButton: true,
closeButtonHtml: closeButtonHtml,
customClass: {
container: "betterdocs-pro-alert-container",
popup: "betterdocs-pro-alert-popup",
closeButton: "betterdocs-pro-alert-close-button",
htmlContainer: "betterdocs-pro-alert-html",
},
...htmlObject,
html,
};
return SweetAlert(alertOptions);
};
export const licenseInactiveAlert = (html = null) => {
let htmlObject = {};
let closeButtonHtml = ``;
if (html === null) {
html = sprintf(
'' +
'' +
'
' +
'%s
' +
'%s
' +
'' +
'
%s
' +
'
' +
'- %s
' +
'- %s
' +
'- %s
' +
'- %s
' +
'- %s
' +
'- %s
' +
'
' +
'
' +
'',
__("License Not Activated", "betterdocs"),
__("To access this feature, simply upgrade to BetterDocs PRO for premium access.", "betterdocs"),
__("Here’s what’s inside BetterDocs Pro.", "betterdocs"),
__("Multiple Knowledge Bases", "betterdocs"),
__("Internal Knowledge Base", "betterdocs"),
__("Instant Answer", "betterdocs"),
__("Advanced Live Search", "betterdocs"),
__("Insightful Analytics Report", "betterdocs"),
__("User Role Management", "betterdocs"),
UPGRADE_URL,
__("Upgrade Now", "betterdocs")
);
}
if (isObject(html)) {
htmlObject = html;
html = html.message || html.html;
}
let alertOptions = {
showConfirmButton: false,
showDenyButton: false,
icon: false,
title: false,
showCloseButton: true,
closeButtonHtml: closeButtonHtml,
customClass: {
container: "betterdocs-pro-alert-container",
popup: "betterdocs-pro-alert-popup",
closeButton: "betterdocs-pro-alert-close-button",
htmlContainer: "betterdocs-pro-alert-html",
},
...htmlObject,
html,
};
return SweetAlert(alertOptions);
};
export default proAlert;