/*!
 * Crafted with ❤ by Salla
 */
import { Host, h } from "@stencil/core";
import Bullhorn from "../../assets/svg/bullhorn.svg";
import UserOff from "../../assets/svg/user-off.svg";
import UserCancel from "../../assets/svg/user-cancel.svg";
export class SallaUserSettings {
    constructor() {
        // Texts
        this.deactivateAccount = salla.lang.get('pages.profile.deactivate_account');
        this.promotionalMsgs = salla.lang.get('pages.profile.promotional_messages');
        this.hideMyName = salla.lang.get('pages.profile.hide_my_name');
        this.hideMyNameDesc = salla.lang.get('pages.profile.hide_my_name_desc');
        this.deactivateDesc = salla.lang.get('pages.profile.deactivate_account_description');
        this.promotionalMsgsDesc = salla.lang.get('pages.profile.promotional_messages_description');
        this.sorryForLeavingText = salla.lang.get('pages.profile.warning_for_deactivate');
        this.warningText = salla.lang.get('pages.profile.sorry_for_leaving');
        this.keepAccount = salla.lang.get('pages.profile.keep_account');
        this.buttonLoading = false;
        this.canHideName = salla.config.get('store.settings.rating.can_customer_hide_name');
        salla.onReady(() => {
            this.isHiddenName = salla.config.get('user.is_hidden_name');
            this.isNotifiable = salla.config.get('user.is_notifiable');
            this.canHideName = salla.config.get('store.settings.rating.can_customer_hide_name');
            if (!this.isNotifiable || !this.isHiddenName) {
                salla.event.on('profile::info.fetched', res => {
                    this.isHiddenName = res.data.is_hidden_name;
                    this.isNotifiable = res.data.is_notifiable;
                });
            }
        });
        salla.lang.onLoaded(() => {
            this.deactivateAccount = salla.lang.get('pages.profile.deactivate_account');
            this.promotionalMsgs = salla.lang.get('pages.profile.promotional_messages');
            this.hideMyName = salla.lang.get('pages.profile.hide_my_name');
            this.hideMyNameDesc = salla.lang.get('pages.profile.hide_my_name_desc');
            this.deactivateDesc = salla.lang.get('pages.profile.deactivate_account_description');
            this.promotionalMsgsDesc = salla.lang.get('pages.profile.promotional_messages_description');
            this.warningText = salla.lang.get('pages.profile.warning_for_deactivate');
            this.sorryForLeavingText = salla.lang.get('pages.profile.sorry_for_leaving');
            this.keepAccount = salla.lang.get('pages.profile.keep_account');
        });
    }
    toggleSetting(setting, event) {
        salla.profile.updateSettings({ name: setting, value: event.target.checked });
    }
    capitalizeText(str) {
        return str.charAt(0).toUpperCase() + str.slice(1);
    }
    openDeactivateModal() {
        this.confirmationModal.setTitle(this.capitalizeText(this.deactivateAccount));
        this.confirmationModal.open();
    }
    async deleteAccount() {
        await salla.profile.delete().finally(() => this.confirmationModal.close());
    }
    render() {
        return (h(Host, { key: '09c239e885ba9e52e21ce17706c9296f99518c80', class: "s-user-settings-wrapper" }, this.canHideName && h("div", { key: 'ae1d8057c8bc4a1d355300f4be87b8a33091f694', class: "s-user-settings-section" }, h("salla-list-tile", { key: '93a7aec26398f466f350defd6f1878b89dc85351' }, h("div", { key: '2e89f6967972d7b95fe43ad735a2180409d234dd', slot: "icon", class: "s-user-settings-section-icon" }, h("span", { key: '622a59eff6171b5b1bb86d8482142df673cbf794', innerHTML: UserCancel })), h("div", { key: 'ce73e774974ea08605635a8443d068c73fd20129', slot: "title", class: "s-user-settings-section-title" }, this.capitalizeText(this.hideMyName)), h("div", { key: '000e5e933e8d6a1f1d4742b0441d86c8403d6cb5', slot: "subtitle", class: "s-user-settings-section-subtitle" }, this.capitalizeText(this.hideMyNameDesc)), h("div", { key: '498fc6ec63be3a7bc0a78b208a48a824af5c38df', slot: 'action', class: "s-user-settings-section-action" }, h("label", { key: '707181396eddd29d85826a48fb74a7119cfed2d6', class: "s-toggle" }, h("input", { key: 'a2188b266c8abe95a94affb128611074f8889405', class: "s-toggle-input", checked: this.isHiddenName, onChange: (e) => this.toggleSetting('is_hidden_name', e), type: "checkbox" }), h("div", { key: '1d50965f07763ba23f1675736f7d676a2e3300b9', class: "s-toggle-switcher" }))))), h("div", { key: '303f5388b3cb3954dc574dd8ac2c5f3981e870ce', class: "s-user-settings-section" }, h("salla-list-tile", { key: '6c751eafd2a3547fa7adaaf165230857c22820d4' }, h("div", { key: 'aaf770f0e43798c73d6fb7c5e0a71b7e03f812b8', slot: "icon", class: "s-user-settings-section-icon" }, h("span", { key: '3e5bbc36ed00b1c99816557314d82a5c51ceefac', innerHTML: Bullhorn })), h("div", { key: '9dce63894704b419536b9f7afec474b90bf047a8', slot: "title", class: "s-user-settings-section-title" }, this.capitalizeText(this.promotionalMsgs)), h("div", { key: 'd1df5e80e9ee8b8512cfe334b3032d64a61b9dc2', slot: "subtitle", class: "s-user-settings-section-subtitle" }, this.capitalizeText(this.promotionalMsgsDesc)), h("div", { key: 'a57e08a44055a8859b4f3f2fd4ee8e7d3abf8e46', slot: 'action', class: "s-user-settings-section-action" }, h("label", { key: '6289b221064d45fd944bbed843350f4183d32e7e', class: "s-toggle" }, h("input", { key: '545e32938c4f1da231486b20be8f220108c20019', class: "s-toggle-input", checked: this.isNotifiable, onChange: (e) => this.toggleSetting('is_notifiable', e), type: "checkbox" }), h("div", { key: 'efa1680c2fbbdcc280330ffa3d83379e96b0e755', class: "s-toggle-switcher" }))))), h("div", { key: '86e21a0171941aa0f1ddf008f479101a707c7e00', class: "s-user-settings-section s-user-settings-section-deactivate-user" }, h("salla-list-tile", { key: '55f0b6d0b72ff1f91ff4ba09d28e8962e7f445b3' }, h("div", { key: '2d8ff66a76c3c8bf6a3c0e5222c142c0402b1c75', slot: "icon", class: "s-user-settings-section-icon" }, h("span", { key: 'e59a4224af4f355679e2e163ca97c0f03b121ac7', innerHTML: UserOff })), h("div", { key: '59d4a4d841ab40f782f5a6a258c5e91211376d22', slot: "title", class: "s-user-settings-section-title" }, this.capitalizeText(this.deactivateAccount)), h("div", { key: 'b51a3eedf67d2635ebbf15eb7e39289866b92481', slot: "subtitle", class: "s-user-settings-section-subtitle" }, this.capitalizeText(this.deactivateDesc)), h("div", { key: '0871a013df31afcacad1f3e3f2a37a80668fffa0', slot: 'action', class: "s-user-settings-section-action" }, h("salla-button", { key: 'c42688b4aa87c5cbeb2145246327271cbc7561b5', fill: "outline", color: "danger", shape: "btn", size: "medium", width: "normal", onClick: () => this.openDeactivateModal() }, this.capitalizeText(this.deactivateAccount))))), h("salla-modal", { key: 'eaf3dbc98dc2483d2251fa5858bf77d698d24d66', width: "sm", subTitle: this.capitalizeText(this.sorryForLeavingText), ref: modal => this.confirmationModal = modal }, h("span", { key: 'e7403e420404a68db65c1efa8edfa7ce8095ed82', slot: 'icon', class: "s-user-settings-confirmation-icon", innerHTML: UserOff }), h("div", { key: '1625698c6e2d8058177b51b5565adcf3fb92115f', class: "s-user-settings-confirmation" }, h("div", { key: '97a28f55f8dd76f15caa25148021501fe6447ddc', class: "s-user-settings-confirmation-warning" }, this.capitalizeText(this.warningText)), h("div", { key: '8454d3da817db426934ff49b535f82e9e0711eb9', class: "s-user-settings-confirmation-actions" }, h("salla-button", { key: '9227e5eb5854e0415c0280c752340a526c2d19fb', width: "wide", onClick: () => this.confirmationModal.close() }, this.capitalizeText(this.keepAccount)), h("salla-button", { key: '3788d8ebbfe73e4bd085c942a9a651e22e4585e1', fill: 'outline', loading: this.buttonLoading, width: "wide", onClick: () => this.deleteAccount() }, this.capitalizeText(this.deactivateAccount)))))));
    }
    static get is() { return "salla-user-settings"; }
    static get originalStyleUrls() {
        return {
            "$": ["salla-user-settings.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["salla-user-settings.css"]
        };
    }
    static get states() {
        return {
            "deactivateAccount": {},
            "promotionalMsgs": {},
            "hideMyName": {},
            "hideMyNameDesc": {},
            "deactivateDesc": {},
            "promotionalMsgsDesc": {},
            "sorryForLeavingText": {},
            "warningText": {},
            "keepAccount": {},
            "buttonLoading": {},
            "canHideName": {},
            "isHiddenName": {},
            "isNotifiable": {}
        };
    }
}
