import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatDialogModule } from '@angular/material/dialog';
import { ToastModule } from 'primeng/toast';
import { MessageService } from 'primeng/api';
import * as i0 from "@angular/core";
import * as i1 from "../../../services/rest.service";
import * as i2 from "@angular/router";
import * as i3 from "@angular/material/dialog";
import * as i4 from "../../../services/storage.service";
import * as i5 from "primeng/api";
import * as i6 from "@angular/common";
import * as i7 from "@angular/forms";
import * as i8 from "primeng/toast";
export class UserBasicInfoComponent {
    constructor(restService, router, dialogRef, storageService, messageService) {
        this.restService = restService;
        this.router = router;
        this.dialogRef = dialogRef;
        this.storageService = storageService;
        this.messageService = messageService;
        this.gender = null;
        this.firstName = "";
        this.middleName = "";
        this.lastName = "";
        this.mobile = "";
        this.email = "";
        this.profilePic = "";
        this.userDetails = null;
        this.isEdit = false;
    }
    ngOnInit() {
        this.userDetails = this.storageService.getUser();
        this.isEdit = !!this.userDetails;
        this.firstName = this.userDetails?.contact?.name?.split(" ")?.[0] ?? "";
        // this.middleName = this.userDetails?.contact?.name?.split(" ")?.[1] ?? "";
        this.lastName = this.userDetails?.contact?.name?.split(" ")?.[1] ?? "";
        this.email = this.userDetails?.contact?.email ?? "";
        this.mobile = this.userDetails?.contact.mobile ?? "";
        this.gender = this.userDetails?.gender;
        this.profilePic = this.userDetails?.profilePic ?? "";
    }
    close() {
        this.dialogRef.close();
    }
    saveProfile() {
        const payload = {
            userId: this.userDetails?.userId,
            businessId: localStorage.getItem("bId") ?? localStorage.getItem("businessId"),
            gender: this.gender,
            profilePic: this.profilePic,
            contact: {
                countryCode: "91",
                email: this.email,
                name: this.firstName + " " + (this.middleName?.length > 0 ? this.middleName + " " : "") + this.lastName
            },
            addressDetailsList: this.userDetails?.addressDetailsList ?? []
        };
        this.restService.updateProfile(payload).subscribe((response) => {
            this.storageService.setUser(response.data);
            this.messageService.add({ severity: 'success', summary: 'Updated Successfully', detail: 'User detail updated' });
            if (this.dialogRef)
                this.dialogRef.close();
            else
                this.router.navigate(['/']);
        }, (error) => {
            this.messageService.add({ severity: 'error', summary: 'Error', detail: 'Failed to update your details try agin.' });
        });
    }
    validateName(event) {
        if ((event.keyCode >= 65 && event.keyCode <= 90) || event.keyCode == 16 || event.keyCode == 8 || event.keyCode == 32 || event.keyCode == 46) {
            return;
        }
        event.preventDefault();
    }
    get isMobile() {
        return window.innerWidth < 475;
    }
    get isEmailValid() {
        return this.email?.includes("@") && this.email.includes(".com") || (this.email?.length == 0);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: UserBasicInfoComponent, deps: [{ token: i1.RestService }, { token: i2.Router }, { token: i3.MatDialogRef }, { token: i4.StorageServiceService }, { token: i5.MessageService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: UserBasicInfoComponent, isStandalone: true, selector: "simpo-user-basic-info", providers: [MessageService], ngImport: i0, template: "<section style=\"padding: 20px\" class=\"position-relative\">\n    <div class=\"d-flex flex-wrap justify-content-between\">\n        <div class=\"form-control-group\">\n            <div class=\"label\">First Name</div>\n            <input type=\"text\" placeholder=\"Enter first name\" [(ngModel)]=\"firstName\" (keydown)=\"validateName($event)\">\n        </div>\n        <!-- <div class=\"form-control-group-3\">\n            <div class=\"label\">Middle Name</div>\n            <input type=\"text\" placeholder=\"Enter middle name\" [(ngModel)]=\"middleName\">\n        </div> -->\n        <div class=\"form-control-group\">\n            <div class=\"label\">Last Name</div>\n            <input type=\"text\" placeholder=\"Enter last name\" [(ngModel)]=\"lastName\" (keydown)=\"validateName($event)\">\n        </div>\n\n        <div class=\"form-control-group\" *ngIf=\"isEdit\">\n            <div class=\"label required\">Mobile</div>\n            <input type=\"number\" placeholder=\"Enter mobile\" [(ngModel)]=\"mobile\" disabled>\n        </div>\n        <div class=\"form-control-group\">\n            <div class=\"label\">Email</div>\n            <input type=\"text\" placeholder=\"Enter email\" [(ngModel)]=\"email\">\n            <span class=\"error-msg\" [style.visibility]=\"isEmailValid ? 'hidden' : 'visible'\">Please enter valid email</span>\n        </div>\n        \n        <div class=\"form-control-group-full\">\n            <div class=\"label\">Select Gender</div>\n            <div class=\"d-flex align-items-center\">\n                <img loading=\"lazy\" onerror=\"this.src='https://i.postimg.cc/hPS2JpV0/no-image-available.jpg'\"   src=\"https://img.icons8.com/?size=100&id=108296&format=png&color=000000\" alt=\"\"\n                    (click)=\"gender = 'MALE'\" [ngClass]=\"{'active': gender == 'MALE' }\">\n                <img loading=\"lazy\" onerror=\"this.src='https://i.postimg.cc/hPS2JpV0/no-image-available.jpg'\"   src=\"https://img.icons8.com/?size=100&id=108295&format=png&color=000000\" alt=\"\"\n                    (click)=\"gender = 'FEMALE'\" [ngClass]=\"{'active': gender == 'FEMALE'}\">\n            </div>\n        </div>\n    </div>\n    <div class=\"action-btn\">\n        <span class=\"skip-btn\" (click)=\"close()\">{{!isEdit ? 'Skip' : 'Close'}}</span>\n        <button (click)=\"saveProfile()\">Save Profile</button>\n    </div>\n</section>\n<p-toast position=\"bottom-right\" [baseZIndex]=\"10000000000\" [autoZIndex]=\"true\" [showTransformOptions]=\"isMobile ? 'translateY(-100%)' : ''\"></p-toast>", styles: [".form-control-group,.form-control-group-3,.form-control-group-full{width:100%}:is(.form-control-group,.form-control-group-3,.form-control-group-full)>input{width:100%;padding:10px;border-radius:3px;border:1.5px solid lightgray}*{font-family:var(--website-font-family)}mat-icon{font-family:Material Icons!important}.label{color:#000}.form-control-group-3{width:32%!important}.form-control-group-full{width:100%}img{height:60px;width:60px;object-fit:cover;margin:0 5px;border:2px solid transparent;cursor:pointer;border-radius:50%}.active{border:2px solid #0267C1}.form-control-group{margin:10px 0}.action-btn{position:relative;bottom:0;right:0;display:flex;align-items:center;justify-content:flex-end;gap:20px}.action-btn .skip-btn{color:#0267c1;cursor:pointer}.action-btn button{width:100px!important;border:none;background-color:#0267c1;color:#fff;cursor:pointer;border-radius:3px;padding:8px 0;font-size:14px!important;font-weight:500!important}.required:after{content:\"*\";color:tomato}.error-msg{color:tomato}@media screen and (max-width: 475px){.action-btn .skip-btn{color:#0267c1;cursor:pointer}.action-btn button{width:100px!important;border:none;background-color:#0267c1;color:#fff;cursor:pointer;border-radius:3px;padding:8px 0;font-size:14px!important;font-weight:500!important}}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i6.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: MatDialogModule }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i7.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i7.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i7.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i7.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "ngmodule", type: ToastModule }, { kind: "component", type: i8.Toast, selector: "p-toast", inputs: ["key", "autoZIndex", "baseZIndex", "life", "style", "styleClass", "position", "preventOpenDuplicates", "preventDuplicates", "showTransformOptions", "hideTransformOptions", "showTransitionOptions", "hideTransitionOptions", "breakpoints"], outputs: ["onClose"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: UserBasicInfoComponent, decorators: [{
            type: Component,
            args: [{ selector: 'simpo-user-basic-info', standalone: true, imports: [
                        CommonModule,
                        MatDialogModule,
                        FormsModule,
                        ToastModule
                    ], providers: [MessageService], template: "<section style=\"padding: 20px\" class=\"position-relative\">\n    <div class=\"d-flex flex-wrap justify-content-between\">\n        <div class=\"form-control-group\">\n            <div class=\"label\">First Name</div>\n            <input type=\"text\" placeholder=\"Enter first name\" [(ngModel)]=\"firstName\" (keydown)=\"validateName($event)\">\n        </div>\n        <!-- <div class=\"form-control-group-3\">\n            <div class=\"label\">Middle Name</div>\n            <input type=\"text\" placeholder=\"Enter middle name\" [(ngModel)]=\"middleName\">\n        </div> -->\n        <div class=\"form-control-group\">\n            <div class=\"label\">Last Name</div>\n            <input type=\"text\" placeholder=\"Enter last name\" [(ngModel)]=\"lastName\" (keydown)=\"validateName($event)\">\n        </div>\n\n        <div class=\"form-control-group\" *ngIf=\"isEdit\">\n            <div class=\"label required\">Mobile</div>\n            <input type=\"number\" placeholder=\"Enter mobile\" [(ngModel)]=\"mobile\" disabled>\n        </div>\n        <div class=\"form-control-group\">\n            <div class=\"label\">Email</div>\n            <input type=\"text\" placeholder=\"Enter email\" [(ngModel)]=\"email\">\n            <span class=\"error-msg\" [style.visibility]=\"isEmailValid ? 'hidden' : 'visible'\">Please enter valid email</span>\n        </div>\n        \n        <div class=\"form-control-group-full\">\n            <div class=\"label\">Select Gender</div>\n            <div class=\"d-flex align-items-center\">\n                <img loading=\"lazy\" onerror=\"this.src='https://i.postimg.cc/hPS2JpV0/no-image-available.jpg'\"   src=\"https://img.icons8.com/?size=100&id=108296&format=png&color=000000\" alt=\"\"\n                    (click)=\"gender = 'MALE'\" [ngClass]=\"{'active': gender == 'MALE' }\">\n                <img loading=\"lazy\" onerror=\"this.src='https://i.postimg.cc/hPS2JpV0/no-image-available.jpg'\"   src=\"https://img.icons8.com/?size=100&id=108295&format=png&color=000000\" alt=\"\"\n                    (click)=\"gender = 'FEMALE'\" [ngClass]=\"{'active': gender == 'FEMALE'}\">\n            </div>\n        </div>\n    </div>\n    <div class=\"action-btn\">\n        <span class=\"skip-btn\" (click)=\"close()\">{{!isEdit ? 'Skip' : 'Close'}}</span>\n        <button (click)=\"saveProfile()\">Save Profile</button>\n    </div>\n</section>\n<p-toast position=\"bottom-right\" [baseZIndex]=\"10000000000\" [autoZIndex]=\"true\" [showTransformOptions]=\"isMobile ? 'translateY(-100%)' : ''\"></p-toast>", styles: [".form-control-group,.form-control-group-3,.form-control-group-full{width:100%}:is(.form-control-group,.form-control-group-3,.form-control-group-full)>input{width:100%;padding:10px;border-radius:3px;border:1.5px solid lightgray}*{font-family:var(--website-font-family)}mat-icon{font-family:Material Icons!important}.label{color:#000}.form-control-group-3{width:32%!important}.form-control-group-full{width:100%}img{height:60px;width:60px;object-fit:cover;margin:0 5px;border:2px solid transparent;cursor:pointer;border-radius:50%}.active{border:2px solid #0267C1}.form-control-group{margin:10px 0}.action-btn{position:relative;bottom:0;right:0;display:flex;align-items:center;justify-content:flex-end;gap:20px}.action-btn .skip-btn{color:#0267c1;cursor:pointer}.action-btn button{width:100px!important;border:none;background-color:#0267c1;color:#fff;cursor:pointer;border-radius:3px;padding:8px 0;font-size:14px!important;font-weight:500!important}.required:after{content:\"*\";color:tomato}.error-msg{color:tomato}@media screen and (max-width: 475px){.action-btn .skip-btn{color:#0267c1;cursor:pointer}.action-btn button{width:100px!important;border:none;background-color:#0267c1;color:#fff;cursor:pointer;border-radius:3px;padding:8px 0;font-size:14px!important;font-weight:500!important}}\n"] }]
        }], ctorParameters: () => [{ type: i1.RestService }, { type: i2.Router }, { type: i3.MatDialogRef }, { type: i4.StorageServiceService }, { type: i5.MessageService }] });
//# sourceMappingURL=data:application/json;base64, 