!function(e){"use strict";var n=e.EasyChatDom,t=e.EasyChatMotion,i=e.EasyChatRequest,a=e.EasyChatOnboardingI18n||{};function s(e,n){return a[e]||n}function o(e){return n.one(e)}function r(e,i){var a=o("#onboarding-alert");a&&(n.setClasses(a,"d-none alert-success alert-danger alert-info","alert-"+(i||"danger")),a.textContent=e||"",t.reveal(a,{duration:150}))}function d(e,n,t){e&&(e.disabled=!!n,e.innerHTML=t)}function u(){var e=o("#onboarding-news-consent"),n=o("#onboarding-news-email-row"),i=o("#onboarding-news-email"),a=o("#onboarding-admin-email");if(e&&n&&i){if(e.checked)return n.classList.contains("d-none")?t.slideDown(n,{duration:180}):n.classList.remove("d-none"),i.setAttribute("required","required"),void(!i.value.trim()&&a&&a.value.trim()&&(i.value=a.value.trim()));i.removeAttribute("required"),n.classList.contains("d-none")||t.slideUp(n,{duration:160})}}function c(n,t){var a=o("#onboarding-submit"),u=o("#onboarding-skip"),c=o("#onboarding-news-consent"),l=o("#onboarding-news-email");if(!t&&c&&c.checked&&l&&!l.value.trim())return r(s("newsEmailRequired","Enter an email for EasyChat24 news or turn off the news switch."),"danger"),void(l.focus&&l.focus());d(a,!0,'<i class="fa fa-spinner fa-spin me-2" aria-hidden="true"></i> '+s("savingButton","Saving...")),d(u,!0,s("waitLabel","Please wait...")),r(t?s("skipSaving","Opening EasyChat without optional services..."):s("saving","Saving selected settings..."),"info");var f=i.formParams(n);f.set("skip",t?"1":"0"),i.post("index.php?route=onboarding/save",f).then(function(n){if(n&&n.success){var t=s("saved","Done. Opening EasyChat...");n.gift&&"issued"===n.gift.status?t=s("giftIssued","Done, gift AI tokens were issued. Opening EasyChat..."):n.gift&&n.gift.status&&"skipped"!==n.gift.status&&(t=s("giftRetryLater","Settings saved. Gift tokens can be requested again later in settings."));var o=n.attribution&&!1===n.attribution.success&&"not_requested"!==n.attribution.status;return o&&(t=s("installCodeRetryLater","EasyChat is ready. The download-page code could not be confirmed yet; this does not affect chats.")),r(t,o?"info":"success"),void e.setTimeout(function(){e.location.href=i.routeUrl(n.redirect||"index.php?route=index")},o?2400:0)}d(a,!1,'<i class="fa fa-check me-2" aria-hidden="true"></i> '+s("submitLabel","Save and open EasyChat")),d(u,!1,s("skipLabel","Continue without optional services")),r(n&&n.error||s("saveFailed","Could not save first-launch settings."),"danger")}).catch(function(){d(a,!1,'<i class="fa fa-check me-2" aria-hidden="true"></i> '+s("submitLabel","Save and open EasyChat")),d(u,!1,s("skipLabel","Continue without optional services")),r(s("networkError","The server is temporarily unavailable. Try again."),"danger")})}n.ready(function(){var e=o("#onboarding-form"),t=o("#onboarding-admin-email");n.on("#onboarding-news-consent","change",u),t&&t.addEventListener("input",function(){var e=o("#onboarding-news-email");e&&!e.value.trim()&&(e.value=t.value.trim())}),u(),n.on("#onboarding-skip","click",function(){e&&c(e,!0)}),e&&e.addEventListener("submit",function(n){n.preventDefault(),c(e,!1)})})}(window,document);