import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { AddressComponent } from '../../ecommerce/sections/address/address.component';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import * as i0 from "@angular/core";
import * as i1 from "@angular/material/dialog";
import * as i2 from "../../services/storage.service";
import * as i3 from "../../services/rest.service";
import * as i4 from "@angular/common";
import * as i5 from "@angular/material/progress-spinner";
export class AddressListComponent {
    constructor(matDialog, data, dialogRef, storageService, restService) {
        this.matDialog = matDialog;
        this.data = data;
        this.dialogRef = dialogRef;
        this.storageService = storageService;
        this.restService = restService;
        this.addressList = [];
        this.defaultAddressIndex = -1;
        this.isLoading = false;
        this.deleteLoading = false;
    }
    ngOnInit() {
        this.addressList = this.data['addressList'];
        this.defaultAddressIndex = this.addressList?.findIndex(address => address.default === true) ?? -1;
        this.defaultAddress = this.defaultAddressIndex !== -1
            ? this.addressList[this.defaultAddressIndex]
            : this.addressList?.[0] || {};
        this.defaultAddressIndex = this.defaultAddressIndex === -1 ? 0 : this.defaultAddressIndex;
    }
    addOrEditAddress(editIndex, address) {
        this.matDialog.open(AddressComponent, { panelClass: ['sidepanel-class', 'address-class'], data: { 'address': address, 'addressList': this.addressList, 'editIndex': editIndex } }).afterClosed().subscribe((res) => {
            this.dialogRef.close();
        });
    }
    closeDialog() {
        this.dialogRef.close();
    }
    markAddressAsDefault() {
        this.isLoading = true;
        this.defaultAddress['default'] = false;
        this.addressList[this.selectedAddressIndex]['default'] = true;
        const userDetails = this.storageService.getUser();
        const payload = {
            "userId": userDetails.userId,
            "businessId": userDetails.businessId,
            "addressDetailsList": this.addressList,
            "contact": userDetails?.contact ?? {},
            "gender": userDetails?.gender?.length > 0 ? userDetails?.gender : "NOT_PROVIDED"
        };
        this.restService.addUserAddress(payload).subscribe((response) => {
            if (!!userDetails) {
                userDetails.addressDetailsList = this.addressList;
                this.storageService.setUser(userDetails);
                this.isLoading = false;
                this.dialogRef.close();
            }
        }, (error) => {
            this.isLoading = false;
        });
    }
    deleteAddress(index) {
        this.addressList.splice(index, 1);
        this.updateUserAddress();
    }
    updateUserAddress() {
        this.deleteLoading = true;
        const userDetails = this.storageService.getUser();
        const payload = {
            "userId": userDetails.userId,
            "businessId": userDetails.businessId,
            "addressDetailsList": this.addressList,
            "contact": userDetails?.contact ?? {},
            "gender": userDetails?.gender?.length > 0 ? userDetails?.gender : "NOT_PROVIDED"
        };
        this.restService.addUserAddress(payload).subscribe((response) => {
            if (!!userDetails) {
                userDetails.addressDetailsList = this.addressList;
                this.storageService.setUser(userDetails);
                this.deleteLoading = false;
            }
        }, (error) => {
            this.deleteLoading = false;
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AddressListComponent, deps: [{ token: i1.MatDialog }, { token: MAT_DIALOG_DATA }, { token: i1.MatDialogRef }, { token: i2.StorageServiceService }, { token: i3.RestService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: AddressListComponent, isStandalone: true, selector: "simpo-address-list", ngImport: i0, template: "<div class=\"address-selection-container\">\n  <!-- Header -->\n  <div class=\"header\">\n    <h2 class=\"title\">Select Address</h2>\n    <button class=\"close-btn\" (click)=\"closeDialog()\">\u2715</button>\n  </div>\n\n  <!-- Add New Address Button -->\n  <div class=\"content\">\n    <button class=\"add-new-address-btn\" (click)=\"addOrEditAddress(-1)\">\n      ADD NEW ADDRESS\n    </button>\n\n    <!-- Currently Selected Section -->\n    <div class=\"currently-selected-section\">\n      <h3 class=\"section-title\">Currently Selected</h3>\n\n      <div class=\"address-card selected\">\n        <div class=\"address-header\">\n          <span class=\"address-name\">{{defaultAddress?.receiverName}} ({{defaultAddress?.addressType}})</span>\n          <!-- <div class=\"radio-button checked\">\n            <div class=\"radio-inner\"></div>\n          </div> -->\n        </div>\n\n        <p class=\"address-text\">{{defaultAddress?.addressLine1}}, {{defaultAddress?.cityName}},\n          {{defaultAddress?.stateName}}</p>\n\n        <p class=\"mobile-text\">\n          <strong>Mobile: {{defaultAddress?.receiverPhone}}</strong>\n        </p>\n\n        <div class=\"address-actions\">\n          <button class=\"action-btn delete-btn\" (click)=\"deleteAddress(defaultAddressIndex)\"\n            *ngIf=\"(this.addressList?.length || 0) > 1 && !deleteLoading\">\n            DELETE\n          </button>\n          <button class=\"action-btn delete-btn loading-btn\" *ngIf=\"deleteLoading\">\n            <mat-spinner></mat-spinner> Loading\n          </button>\n          <button class=\"action-btn edit-btn\"\n            (click)=\"addOrEditAddress(defaultAddressIndex != -1 ? defaultAddressIndex : 0, defaultAddress)\">\n            EDIT\n          </button>\n        </div>\n      </div>\n\n      <ng-container *ngIf=\"(addressList?.length || 0) > 1\">\n        <h3 class=\"section-title\">Others Address</h3>\n        <div>\n          <ng-container *ngFor=\"let address of addressList;let i = index\">\n            <div class=\"other-address-card\" (click)=\"selectedAddressIndex = i\"\n              [ngClass]=\"{'selected-address': selectedAddressIndex === i}\" *ngIf=\"!address.default\">\n              <div class=\"address-header\">\n                <span class=\"address-name\">{{address?.receiverName}} ({{address?.addressType}})</span>\n                <!-- <div class=\"radio-button checked\">\n                  <div class=\"radio-inner\"></div>\n                </div> -->\n              </div>\n\n              <p class=\"address-text\">{{address?.addressLine1}}, {{address?.cityName}},\n                {{defaultAddress?.stateName}}</p>\n\n              <p class=\"mobile-text\">\n                <strong>Mobile: {{address.receiverPhone}}</strong>\n              </p>\n\n              <div class=\"address-actions\">\n                <button class=\"action-btn delete-btn other-address-btn\" (click)=\"deleteAddress(i)\" *ngIf=\"!deleteLoading\">\n                  DELETE\n                </button>\n                <button class=\"action-btn delete-btn loading-btn\" *ngIf=\"deleteLoading\">\n                  <mat-spinner></mat-spinner> Loading\n                </button>\n                <button class=\"action-btn edit-btn other-address-btn\" (click)=\"addOrEditAddress(i, address)\">\n                  EDIT\n                </button>\n              </div>\n            </div>\n          </ng-container>\n        </div>\n      </ng-container>\n    </div>\n\n  </div>\n  <!-- Confirm Button -->\n  <div class=\"footer\">\n    <button class=\"confirm-btn\" *ngIf=\"!isLoading\" (click)=\"markAddressAsDefault()\">\n      CONFIRM\n    </button>\n    <button class=\"confirm-btn loading-btn\" *ngIf=\"isLoading\"><mat-spinner></mat-spinner> Loading</button>\n  </div>\n</div>\n", styles: ["*{font-family:var(--primary-font-family)}.address-selection-container{background:#fff;border-radius:12px;width:100%;max-width:500px}.header{display:flex;justify-content:space-between;align-items:center;padding:0 20px;height:60px;background-color:#f6f3f9}.content{padding:20px;height:calc(100vh - 120px);overflow:scroll}.title{font-size:18px;font-weight:600;color:#000}.close-btn{background:none;border:none;cursor:pointer;padding:4px;color:#666;font-size:24px;line-height:1;width:max-content!important}.close-btn:hover{color:#333}.add-new-address-btn{font-size:1rem!important;font-weight:700!important;padding:6px;background:#fff;border:1px solid rgb(229,221,255);border-radius:8px;color:#000;cursor:pointer;transition:all .2s;box-shadow:#0000000a 0 4px 8px;width:100%}.add-new-address-btn:hover{border-color:#fbf9ff;background-color:#faf7ff}.section-title{font-size:16px;font-weight:600;color:#000;margin-bottom:16px;margin-top:16px}.address-card{border:1px solid #e0e0e0;border-radius:12px;padding:20px;margin-bottom:16px;cursor:pointer;transition:all .2s}.other-address-card{border:1px solid rgb(238,232,255);box-shadow:#0000000a 0 4px 8px;background:#fbf9ff;border-radius:12px;padding:20px;margin-bottom:16px;cursor:pointer;transition:all .2s}.address-card.selected,.selected-address{border-color:#000}.address-card:hover{border-color:#fbf9ff}.address-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}.address-name{font-size:16px;font-weight:600;color:#000}.radio-button{width:20px;height:20px;border:2px solid #ccc;border-radius:50%;display:flex;justify-content:center;align-items:center;transition:all .2s}.radio-button.checked{border-color:#000;background-color:#000}.radio-inner{width:8px;height:8px;background-color:#fff;border-radius:50%}.address-text{color:#000;font-size:14px;line-height:1.4;margin-bottom:8px}.mobile-text{color:#000;font-size:14px;margin-bottom:16px}.address-actions{display:flex;gap:24px}.action-btn{background:none;border:none;font-size:12px;font-weight:600;cursor:pointer;padding:4px 0;transition:opacity .2s}.delete-btn,.edit-btn{box-shadow:#0000000a 0 4px 8px;background:#fbf9ff;color:#000;font-size:14px!important;border-radius:5px}.action-btn:hover{opacity:.7}.confirm-btn{font-size:1rem!important;font-weight:700!important;padding:6px;background:#fff;border:1px solid rgb(229,221,255);border-radius:8px;color:#000;cursor:pointer;transition:all .2s;box-shadow:#0000000a 0 4px 8px;width:90%!important}.confirm-btn:hover{background:#fbf9ff}@media (max-width: 480px){.title{font-size:18px}}.other-address-btn{background-color:#fff!important}.footer{display:flex;align-items:center;justify-content:center;height:60px;position:absolute;width:100%;bottom:0;box-shadow:#0000000a 0 -1px 8px}.loading-btn{display:flex;gap:10px;justify-content:center}.loading-btn mat-spinner{height:20px!important;width:20px!important}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: FormsModule }, { kind: "ngmodule", type: MatProgressSpinnerModule }, { kind: "component", type: i5.MatProgressSpinner, selector: "mat-progress-spinner, mat-spinner", inputs: ["color", "mode", "value", "diameter", "strokeWidth"], exportAs: ["matProgressSpinner"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AddressListComponent, decorators: [{
            type: Component,
            args: [{ selector: 'simpo-address-list', standalone: true, imports: [CommonModule, FormsModule, MatProgressSpinnerModule], template: "<div class=\"address-selection-container\">\n  <!-- Header -->\n  <div class=\"header\">\n    <h2 class=\"title\">Select Address</h2>\n    <button class=\"close-btn\" (click)=\"closeDialog()\">\u2715</button>\n  </div>\n\n  <!-- Add New Address Button -->\n  <div class=\"content\">\n    <button class=\"add-new-address-btn\" (click)=\"addOrEditAddress(-1)\">\n      ADD NEW ADDRESS\n    </button>\n\n    <!-- Currently Selected Section -->\n    <div class=\"currently-selected-section\">\n      <h3 class=\"section-title\">Currently Selected</h3>\n\n      <div class=\"address-card selected\">\n        <div class=\"address-header\">\n          <span class=\"address-name\">{{defaultAddress?.receiverName}} ({{defaultAddress?.addressType}})</span>\n          <!-- <div class=\"radio-button checked\">\n            <div class=\"radio-inner\"></div>\n          </div> -->\n        </div>\n\n        <p class=\"address-text\">{{defaultAddress?.addressLine1}}, {{defaultAddress?.cityName}},\n          {{defaultAddress?.stateName}}</p>\n\n        <p class=\"mobile-text\">\n          <strong>Mobile: {{defaultAddress?.receiverPhone}}</strong>\n        </p>\n\n        <div class=\"address-actions\">\n          <button class=\"action-btn delete-btn\" (click)=\"deleteAddress(defaultAddressIndex)\"\n            *ngIf=\"(this.addressList?.length || 0) > 1 && !deleteLoading\">\n            DELETE\n          </button>\n          <button class=\"action-btn delete-btn loading-btn\" *ngIf=\"deleteLoading\">\n            <mat-spinner></mat-spinner> Loading\n          </button>\n          <button class=\"action-btn edit-btn\"\n            (click)=\"addOrEditAddress(defaultAddressIndex != -1 ? defaultAddressIndex : 0, defaultAddress)\">\n            EDIT\n          </button>\n        </div>\n      </div>\n\n      <ng-container *ngIf=\"(addressList?.length || 0) > 1\">\n        <h3 class=\"section-title\">Others Address</h3>\n        <div>\n          <ng-container *ngFor=\"let address of addressList;let i = index\">\n            <div class=\"other-address-card\" (click)=\"selectedAddressIndex = i\"\n              [ngClass]=\"{'selected-address': selectedAddressIndex === i}\" *ngIf=\"!address.default\">\n              <div class=\"address-header\">\n                <span class=\"address-name\">{{address?.receiverName}} ({{address?.addressType}})</span>\n                <!-- <div class=\"radio-button checked\">\n                  <div class=\"radio-inner\"></div>\n                </div> -->\n              </div>\n\n              <p class=\"address-text\">{{address?.addressLine1}}, {{address?.cityName}},\n                {{defaultAddress?.stateName}}</p>\n\n              <p class=\"mobile-text\">\n                <strong>Mobile: {{address.receiverPhone}}</strong>\n              </p>\n\n              <div class=\"address-actions\">\n                <button class=\"action-btn delete-btn other-address-btn\" (click)=\"deleteAddress(i)\" *ngIf=\"!deleteLoading\">\n                  DELETE\n                </button>\n                <button class=\"action-btn delete-btn loading-btn\" *ngIf=\"deleteLoading\">\n                  <mat-spinner></mat-spinner> Loading\n                </button>\n                <button class=\"action-btn edit-btn other-address-btn\" (click)=\"addOrEditAddress(i, address)\">\n                  EDIT\n                </button>\n              </div>\n            </div>\n          </ng-container>\n        </div>\n      </ng-container>\n    </div>\n\n  </div>\n  <!-- Confirm Button -->\n  <div class=\"footer\">\n    <button class=\"confirm-btn\" *ngIf=\"!isLoading\" (click)=\"markAddressAsDefault()\">\n      CONFIRM\n    </button>\n    <button class=\"confirm-btn loading-btn\" *ngIf=\"isLoading\"><mat-spinner></mat-spinner> Loading</button>\n  </div>\n</div>\n", styles: ["*{font-family:var(--primary-font-family)}.address-selection-container{background:#fff;border-radius:12px;width:100%;max-width:500px}.header{display:flex;justify-content:space-between;align-items:center;padding:0 20px;height:60px;background-color:#f6f3f9}.content{padding:20px;height:calc(100vh - 120px);overflow:scroll}.title{font-size:18px;font-weight:600;color:#000}.close-btn{background:none;border:none;cursor:pointer;padding:4px;color:#666;font-size:24px;line-height:1;width:max-content!important}.close-btn:hover{color:#333}.add-new-address-btn{font-size:1rem!important;font-weight:700!important;padding:6px;background:#fff;border:1px solid rgb(229,221,255);border-radius:8px;color:#000;cursor:pointer;transition:all .2s;box-shadow:#0000000a 0 4px 8px;width:100%}.add-new-address-btn:hover{border-color:#fbf9ff;background-color:#faf7ff}.section-title{font-size:16px;font-weight:600;color:#000;margin-bottom:16px;margin-top:16px}.address-card{border:1px solid #e0e0e0;border-radius:12px;padding:20px;margin-bottom:16px;cursor:pointer;transition:all .2s}.other-address-card{border:1px solid rgb(238,232,255);box-shadow:#0000000a 0 4px 8px;background:#fbf9ff;border-radius:12px;padding:20px;margin-bottom:16px;cursor:pointer;transition:all .2s}.address-card.selected,.selected-address{border-color:#000}.address-card:hover{border-color:#fbf9ff}.address-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}.address-name{font-size:16px;font-weight:600;color:#000}.radio-button{width:20px;height:20px;border:2px solid #ccc;border-radius:50%;display:flex;justify-content:center;align-items:center;transition:all .2s}.radio-button.checked{border-color:#000;background-color:#000}.radio-inner{width:8px;height:8px;background-color:#fff;border-radius:50%}.address-text{color:#000;font-size:14px;line-height:1.4;margin-bottom:8px}.mobile-text{color:#000;font-size:14px;margin-bottom:16px}.address-actions{display:flex;gap:24px}.action-btn{background:none;border:none;font-size:12px;font-weight:600;cursor:pointer;padding:4px 0;transition:opacity .2s}.delete-btn,.edit-btn{box-shadow:#0000000a 0 4px 8px;background:#fbf9ff;color:#000;font-size:14px!important;border-radius:5px}.action-btn:hover{opacity:.7}.confirm-btn{font-size:1rem!important;font-weight:700!important;padding:6px;background:#fff;border:1px solid rgb(229,221,255);border-radius:8px;color:#000;cursor:pointer;transition:all .2s;box-shadow:#0000000a 0 4px 8px;width:90%!important}.confirm-btn:hover{background:#fbf9ff}@media (max-width: 480px){.title{font-size:18px}}.other-address-btn{background-color:#fff!important}.footer{display:flex;align-items:center;justify-content:center;height:60px;position:absolute;width:100%;bottom:0;box-shadow:#0000000a 0 -1px 8px}.loading-btn{display:flex;gap:10px;justify-content:center}.loading-btn mat-spinner{height:20px!important;width:20px!important}\n"] }]
        }], ctorParameters: () => [{ type: i1.MatDialog }, { type: undefined, decorators: [{
                    type: Inject,
                    args: [MAT_DIALOG_DATA]
                }] }, { type: i1.MatDialogRef }, { type: i2.StorageServiceService }, { type: i3.RestService }] });
//# sourceMappingURL=data:application/json;base64, 