/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { PROFILE_CARD_CONSTANTS } from './profile-card-constants';
export class ProfileCardFoundation {
    constructor(_adapter) {
        this._adapter = _adapter;
        this._showSignOutButton = PROFILE_CARD_CONSTANTS.defaults.SHOW_SIGN_OUT_BUTTON;
        this._showProfileButton = PROFILE_CARD_CONSTANTS.defaults.SHOW_PROFILE_BUTTON;
        this._signOutButtonText = PROFILE_CARD_CONSTANTS.defaults.SIGN_OUT_BUTTON_TEXT;
        this._profileButtonText = PROFILE_CARD_CONSTANTS.defaults.PROFILE_BUTTON_TEXT;
        this._profileListener = evt => this._onProfileButtonClick(evt);
        this._signOutListener = evt => this._onSignOutButtonClick(evt);
    }
    initialize() {
        this._adapter.setProfileButtonListener(this._profileListener);
        this._adapter.setSignOutButtonListener(this._signOutListener);
        if (this._showSignOutButton || this._showProfileButton) {
            this._requestInitialFocus();
        }
        this._setActionVisibility();
        this._adapter.setSignOutButtonText(this._signOutButtonText);
        this._adapter.setProfileButtonText(this._profileButtonText);
    }
    _requestInitialFocus() {
        if (this._showSignOutButton) {
            this._adapter.requestSignOutButtonFocus();
        }
        else if (this._showProfileButton) {
            this._adapter.requestProfileButtonFocus();
        }
    }
    _setActionVisibility() {
        const showActionToolbar = this._showSignOutButton || this._showProfileButton;
        this._adapter.setActionToolbarVisibility(showActionToolbar);
        this._adapter.setSignOutButtonVisibility(this._showSignOutButton);
        this._adapter.setProfileButtonVisibility(this._showProfileButton);
    }
    _onProfileButtonClick(evt) {
        evt.stopPropagation();
        this._adapter.emitHostEvent(PROFILE_CARD_CONSTANTS.events.PROFILE);
    }
    _onSignOutButtonClick(evt) {
        evt.stopPropagation();
        this._adapter.emitHostEvent(PROFILE_CARD_CONSTANTS.events.SIGN_OUT);
    }
    get fullName() {
        return this._fullName;
    }
    set fullName(value) {
        if (this._fullName !== value) {
            this._fullName = value;
            this._adapter.setFullName(this._fullName);
        }
    }
    get email() {
        return this._email;
    }
    set email(value) {
        if (this._email !== value) {
            this._email = value;
            this._adapter.setEmail(this._email);
        }
    }
    get avatarText() {
        return this._avatarText;
    }
    set avatarText(value) {
        if (this._avatarText !== value) {
            this._avatarText = value;
            this._adapter.setAvatarText(this._avatarText);
        }
    }
    get avatarIcon() {
        return this._avatarIcon;
    }
    set avatarIcon(value) {
        if (this._avatarIcon !== value) {
            this._avatarIcon = value;
            this._adapter.setAvatarIcon(this._avatarIcon);
        }
    }
    get avatarImageUrl() {
        return this._avatarImageUrl;
    }
    set avatarImageUrl(value) {
        if (this._avatarImageUrl !== value) {
            this._avatarImageUrl = value;
            this._adapter.setAvatarImageUrl(this._avatarImageUrl);
        }
    }
    get avatarLetterCount() {
        return this._avatarLetterCount;
    }
    set avatarLetterCount(value) {
        if (this._avatarLetterCount !== value) {
            this._avatarLetterCount = value;
            this._adapter.setAvatarLetterCount(this._avatarLetterCount);
        }
    }
    get signOut() {
        return this._showSignOutButton;
    }
    set signOut(value) {
        if (this._showSignOutButton !== value) {
            this._showSignOutButton = value;
            this._setActionVisibility();
        }
    }
    get profile() {
        return this._showProfileButton;
    }
    set profile(value) {
        if (this._showProfileButton !== value) {
            this._showProfileButton = value;
            this._setActionVisibility();
        }
    }
    get signOutText() {
        return this._signOutButtonText;
    }
    set signOutText(value) {
        if (this._signOutButtonText !== value) {
            this._signOutButtonText = value || PROFILE_CARD_CONSTANTS.defaults.SIGN_OUT_BUTTON_TEXT;
            this._adapter.setSignOutButtonText(this._signOutButtonText);
        }
    }
    get profileText() {
        return this._profileButtonText;
    }
    set profileText(value) {
        if (this._profileButtonText !== value) {
            this._profileButtonText = value || PROFILE_CARD_CONSTANTS.defaults.PROFILE_BUTTON_TEXT;
            this._adapter.setProfileButtonText(this._profileButtonText);
        }
    }
}
