import CSSClient from '../cssClient.js';
import InfoDisplayer from '../infoDisplayer.js';
export default class ImageInfoDisplayer {
    cssClient;
    imageName;
    constructor(imageName) {
        this.cssClient = new CSSClient();
        this.imageName = imageName;
    }
    async displayInfo() {
        const images = await this.cssClient.get('/images', { name: this.imageName });
        if (!images || images.length === 0 || images[0].name !== this.imageName) {
            throw new Error(`Image with name "${this.imageName}" not found.`);
        }
        const targetImage = images[0];
        let imageStatus = { available: false };
        try {
            imageStatus = await this.cssClient.get(`/images/${targetImage.id}/status`);
        }
        catch {
            // If we can't get the status, we assume it's not available.
        }
        /* eslint-disable perfectionist/sort-maps */
        const infoDisplayer = new InfoDisplayer(new Map([
            ['Image name', this.imageName],
            ['Image ID', targetImage.id],
            ['Public', targetImage.isPublic ? 'Yes' : 'No'],
            ['Available', imageStatus.available ? 'Yes' : 'No'],
            ['Last updated', new Date(targetImage.updatedAt).toLocaleString()]
        ]));
        /* eslint-enable perfectionist/sort-maps */
        infoDisplayer.displayAsTable();
    }
}
