import { Component, Inject, OnInit, OnDestroy } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { AuctionserviceService } from '../Service/auctionservice.service';
@Component({
selector: 'app-auctiontypedialog',
templateUrl: './auctiontypedialog.component.html',
styleUrls: ['./auctiontypedialog.component.scss']
})
export class AuctiontypedialogComponent implements OnInit, OnDestroy {
companyId: number | null = null;
employeeLoginId: number | null = null;
auctionTypeName: string = 'Forward Auction';
dps: { x: number; y: number; label?: string }[] = [];
intervalId: any;
rowData: any = [];
Bids: any;
chartOptions: any = {
animationEnabled: true,
theme: "light2",
title: {
text: "Forward Auction"
},
axisX: {
title: "Time",
interval: 1,
titleFontColor: "#c02e48",
labelFontColor: "black",
lineColor: "#c02e48",
tickColor: "#c02e48",
},
axisY: {
title: "Price",
minimum: 0,
titleFontColor: "#c02e48",
labelFontColor: "black",
lineColor: "#c02e48",
tickColor: "#c02e48",
},
data: [{
type: "line",
name: "Auction Price",
showInLegend: true,
yValueFormatString: "#,###$",
titleFontColor: "#c02e48",
labelFontColor: "black",
lineColor: "#c02e48",
tickColor: "#c02e48",
color: "#c02e48",
dataPoints: []
}]
};
constructor(
public dialogRef: MatDialogRef<AuctiontypedialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
private auctionService: AuctionserviceService
) {}
ngOnInit(): void {
const storedData = localStorage.getItem('user_details') ?? "{}";
const userDetails = JSON.parse(storedData);
if (userDetails && userDetails.companyId) {
this.companyId = userDetails.companyId;
this.employeeLoginId = userDetails.employeeId;
}
this.getAuctionDetails();
}
ngOnDestroy(): void {
if (this.intervalId) clearInterval(this.intervalId);
}
closePage() {
if (this.intervalId) clearInterval(this.intervalId);
this.dialogRef.close();
}
getAuctionDetails() {
this.auctionService.getAuctionBidDetails(this.data?.auction_id).subscribe(
(res: any) => {
if (res.body) {
console.log(res.body, 'ATTTTTTTTS')
this.rowData = res.body.vendorBidDetails;
this.Bids = res.body.bids[0];
const filteredData = res.body.vendorBidDetails.filter(
(auction: any) => auction.AuctionType_name === "Forward Auction"
);
this.dps = filteredData.map((auction: any, index: number) => ({
x: index + 1,
y: Number(auction.total_bid_amount), // Ensure it's a number
label: auction.supplierName || "No Vendor",
}));
this.chartOptions = {
...this.chartOptions,
data: [{
type: "line",
name: "Auction Price Time Graph",
showInLegend: true,
yValueFormatString: "#,###$",
dataPoints: this.dps
}]
};
}
},
(err) => {
console.error("Error fetching auction details", err);
}
);
}
}