var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { UmbUserItemRepository } from '../../../repository/item/index.js';
import { UmbNewUserPasswordRepository } from '../../../repository/new-password/index.js';
import { UMB_USER_WORKSPACE_PATH } from '../../../paths.js';
import { UmbTextStyles } from '../../../../../core/style/index.js';
import { css, html, customElement, state } from '../../../../../../external/lit/index.js';
import { UMB_NOTIFICATION_CONTEXT } from '../../../../../core/notification/index.js';
import { UmbModalBaseElement } from '../../../../../core/modal/index.js';
let UmbCreateUserSuccessModalElement = class UmbCreateUserSuccessModalElement extends UmbModalBaseElement {
    constructor() {
        super(...arguments);
        this._initialPassword = '';
        this.#userItemRepository = new UmbUserItemRepository(this);
        this.#userNewPasswordRepository = new UmbNewUserPasswordRepository(this);
        this.#onCloseModal = (event) => {
            event.stopPropagation();
            this._rejectModal();
        };
        this.#onCreateAnotherUser = (event) => {
            event.stopPropagation();
            this._rejectModal({ type: 'createAnotherUser' });
        };
        this.#onGoToProfile = () => {
            this._submitModal();
        };
    }
    #userItemRepository;
    #userNewPasswordRepository;
    #notificationContext;
    connectedCallback() {
        super.connectedCallback();
        this.consumeContext(UMB_NOTIFICATION_CONTEXT, (instance) => (this.#notificationContext = instance));
    }
    async firstUpdated() {
        const unique = this.data?.user.unique;
        if (!unique)
            throw new Error('No user unique is provided');
        const [userItemResponse, newPasswordResponse] = await Promise.all([
            this.#userItemRepository.requestItems([unique]),
            this.#userNewPasswordRepository.requestNewPassword(unique),
        ]);
        if (userItemResponse.data) {
            this._userItem = userItemResponse.data[0];
        }
        if (newPasswordResponse.data?.resetPassword) {
            this._initialPassword = newPasswordResponse.data.resetPassword;
        }
    }
    #copyPassword() {
        const passwordInput = this.shadowRoot?.querySelector('#password');
        if (!passwordInput || typeof passwordInput.value !== 'string')
            return;
        navigator.clipboard.writeText(passwordInput.value);
        const data = { message: 'Password copied' };
        this.#notificationContext?.peek('positive', { data });
    }
    #onCloseModal;
    #onCreateAnotherUser;
    #onGoToProfile;
    render() {
        return html `<uui-dialog-layout headline="${this._userItem?.name} has been created">
			<p>The new user has successfully been created. To log in to Umbraco use the password below</p>
			<uui-form-layout-item>
				<uui-label slot="label" for="password">Password</uui-label>
				<div id="password-control">
					<uui-input-password id="password" label="password" name="password" value="${this._initialPassword}" readonly>
					</uui-input-password>
					<uui-button compact label="Copy" @click=${this.#copyPassword} look="outline"></uui-button>
				</div>
			</uui-form-layout-item>

			<uui-button @click=${this.#onCloseModal} slot="actions" label="Close" look="secondary"></uui-button>
			<uui-button
				@click=${this.#onCreateAnotherUser}
				slot="actions"
				label="Create another user"
				look="secondary"></uui-button>
			<uui-button
				@click=${this.#onGoToProfile}
				slot="actions"
				label="Go to profile"
				look="primary"
				color="positive"
				href=${UMB_USER_WORKSPACE_PATH + '/edit/' + this.data?.user.unique}></uui-button>
		</uui-dialog-layout>`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			p {
				width: 580px;
			}

			#password {
				width: 100%;
			}

			#password-control {
				display: flex;
				align-items: center;
				gap: var(--uui-size-space-3);
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbCreateUserSuccessModalElement.prototype, "_userItem", void 0);
__decorate([
    state()
], UmbCreateUserSuccessModalElement.prototype, "_initialPassword", void 0);
UmbCreateUserSuccessModalElement = __decorate([
    customElement('umb-create-user-success-modal')
], UmbCreateUserSuccessModalElement);
export { UmbCreateUserSuccessModalElement };
export default UmbCreateUserSuccessModalElement;
