// Copyright (c) 2009-2026 SAP SE, All Rights Reserved

/**
 * @fileoverview Provides control sap.ushell.components.factsheet.controls.PictureViewerItem.
 * @deprecated since 1.22. Please use {@link sap.m.Carousel} instead.
 */
sap.ui.define([
    "sap/m/Image",
    "sap/ui/core/Control",
    "sap/ushell/utils/DeprecationLog"
], (Image, Control, DeprecationLog) => {
    "use strict";

    /**
     * Constructor for a new components/factsheet/controls/PictureViewerItem.
     *
     * @param {string} [sId] id for the new control, generated automatically if no id is given
     * @param {object} [mSettings] initial settings for the new control
     * @class Picture viewer control relying on the TileContainer control
     * @extends sap.ui.core.Control
     * @public
     * @deprecated since 1.22. Please use {@link sap.m.Carousel} instead.
     *   PictureViewerItem is used in PictureViewer control and is not meant to be consumed outside of PictureViewer usage.
     *   PictureViewer was replacing the Carousel as it wasn't supporting some versions of MS Internet Explorer.
     *   Now, the sap.m.Carousel is fully functional, please use sap.m.Carousel instead. This control will not be supported anymore.
     * @name sap.ushell.components.factsheet.controls.PictureViewerItem
     * @ui5-metamodel This control/element also will be described in the UI5 (legacy) designtime metamodel
     */
    const PictureViewerItem = Control.extend("sap.ushell.components.factsheet.controls.PictureViewerItem", /** @lends sap.ushell.components.factsheet.controls.PictureViewerItem.prototype */ {
        metadata: {
            deprecated: true,
            library: "sap.ushell",
            properties: {
                // Image source url.
                src: { type: "string", group: "Misc", defaultValue: null }
            },
            aggregations: {
                // Pass in an existing Image control to be used inside the PictureViewer
                image: { type: "sap.m.Image", multiple: false }
            }
        }
    });

    PictureViewerItem.prototype.init = function () {
        DeprecationLog.logModuleDeprecation({
            module: "sap.ushell.components.factsheet.controls.PictureViewerItem",
            successor: "sap.m.Carousel",
            since: "1.22"
        });
    };

    /**
     * Setter for property <code>src</code>.
     *
     * Default value is empty/<code>undefined</code>
     *
     * @param {string} sSrc  new value for property <code>src</code>
     * @returns {sap.ushell.components.factsheet.controls.PictureViewerItem} <code>this</code> to allow method chaining
     * @public
     * @name sap.ushell.components.factsheet.controls.PictureViewerItem#setSrc
     * @function
     * @deprecated since 1.22. Please use {@link sap.m.Carousel} instead.
     */
    PictureViewerItem.prototype.setSrc = function (sSrc) {
        this.setProperty("src", sSrc);
        // Also create or update the internal image
        let oImage = this.getImage();
        if (oImage == null) {
            oImage = new Image();
        }
        oImage.setSrc(sSrc);
        this.setImage(oImage);
        return this;
    };

    /**
     * Called when the control is destroyed
     */
    PictureViewerItem.prototype.exit = function () {
        const oImage = this.getImage();
        if (oImage) {
            oImage.destroy();
        }
    };

    return PictureViewerItem;
});
