/**
 * @license
 * Copyright 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);
    }
    focus(options) {
        if (this._showSignOutButton) {
            this._adapter.requestSignOutButtonFocus(Object.assign(Object.assign({}, options), { focusVisible: true }));
        }
        else if (this._showProfileButton) {
            this._adapter.requestProfileButtonFocus(Object.assign(Object.assign({}, options), { focusVisible: true }));
        }
    }
    _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 !== null && value !== void 0 ? value : '';
            this._adapter.setFullName(this._fullName);
            if (!this._avatarText) {
                this._adapter.setAvatarText(this._fullName);
            }
            this._adapter.toggleHostAttribute(PROFILE_CARD_CONSTANTS.attributes.FULL_NAME, !!this._fullName, this._fullName);
        }
    }
    get email() {
        return this._email;
    }
    set email(value) {
        if (this._email !== value) {
            this._email = value !== null && value !== void 0 ? value : '';
            this._adapter.setEmail(this._email);
            this._adapter.toggleHostAttribute(PROFILE_CARD_CONSTANTS.attributes.EMAIL, !!this._email, this._email);
        }
    }
    get avatarText() {
        return this._avatarText;
    }
    set avatarText(value) {
        if (this._avatarText !== value) {
            this._avatarText = value !== null && value !== void 0 ? value : '';
            this._adapter.setAvatarText(this._avatarText);
            this._adapter.toggleHostAttribute(PROFILE_CARD_CONSTANTS.attributes.AVATAR_TEXT, !!this._avatarText, this._avatarText);
        }
    }
    get avatarIcon() {
        return this._avatarIcon;
    }
    set avatarIcon(value) {
        if (this._avatarIcon !== value) {
            this._avatarIcon = value !== null && value !== void 0 ? value : '';
            this._adapter.setAvatarIcon(this._avatarIcon);
            this._adapter.toggleHostAttribute(PROFILE_CARD_CONSTANTS.attributes.AVATAR_ICON, !!this._avatarIcon, this._avatarIcon);
        }
    }
    get avatarImageUrl() {
        return this._avatarImageUrl;
    }
    set avatarImageUrl(value) {
        if (this._avatarImageUrl !== value) {
            this._avatarImageUrl = value;
            this._adapter.setAvatarImageUrl(this._avatarImageUrl);
            this._adapter.toggleHostAttribute(PROFILE_CARD_CONSTANTS.attributes.AVATAR_IMAGE_URL, !!this._avatarImageUrl, this._avatarImageUrl);
        }
    }
    get avatarLetterCount() {
        return this._avatarLetterCount;
    }
    set avatarLetterCount(value) {
        if (this._avatarLetterCount !== value) {
            this._avatarLetterCount = value;
            this._adapter.setAvatarLetterCount(this._avatarLetterCount);
            this._adapter.toggleHostAttribute(PROFILE_CARD_CONSTANTS.attributes.AVATAR_LETTER_COUNT, !!this._avatarLetterCount, `${this._avatarLetterCount}`);
        }
    }
    get signOut() {
        return this._showSignOutButton;
    }
    set signOut(value) {
        value = Boolean(value);
        if (this._showSignOutButton !== value) {
            this._showSignOutButton = value;
            this._setActionVisibility();
            this._adapter.toggleHostAttribute(PROFILE_CARD_CONSTANTS.attributes.SIGN_OUT, this._showSignOutButton);
        }
    }
    get profile() {
        return this._showProfileButton;
    }
    set profile(value) {
        value = Boolean(value);
        if (this._showProfileButton !== value) {
            this._showProfileButton = value;
            this._setActionVisibility();
            this._adapter.toggleHostAttribute(PROFILE_CARD_CONSTANTS.attributes.PROFILE, this._showProfileButton);
        }
    }
    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);
            const hasSignOutTextAttr = this._signOutButtonText !== PROFILE_CARD_CONSTANTS.defaults.SIGN_OUT_BUTTON_TEXT;
            this._adapter.toggleHostAttribute(PROFILE_CARD_CONSTANTS.attributes.SIGN_OUT_TEXT, hasSignOutTextAttr, 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);
            const hasProfileAttr = value !== PROFILE_CARD_CONSTANTS.defaults.PROFILE_BUTTON_TEXT;
            this._adapter.toggleHostAttribute(PROFILE_CARD_CONSTANTS.attributes.PROFILE_TEXT, hasProfileAttr, this._profileButtonText);
        }
    }
}
