"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImageDetailsViewSidebar = void 0;
var react_1 = __importStar(require("react"));
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var classnames_1 = __importDefault(require("classnames"));
var Box_1 = __importDefault(require("@mui/material/Box"));
var Checkbox_1 = __importDefault(require("@mui/material/Checkbox"));
var Typography_1 = __importDefault(require("@mui/material/Typography"));
var FormControlLabel_1 = __importDefault(require("@mui/material/FormControlLabel"));
var MetaInfo_1 = require("../MetaInfo");
var MdmModuleContext_1 = require("../../../contexts/MdmModuleContext");
var styles_1 = require("./styles");
var ImageDetailsViewSidebar = function (_a) {
    var className = _a.className, attributeValue = _a.attributeValue, handleSetAsDefault = _a.handleSetAsDefault, attributeType = _a.attributeType;
    var styles = (0, styles_1.useStyles)();
    var _b = (0, react_1.useState)(false), isDefault = _b[0], setIsDefault = _b[1];
    var entity = (0, MdmModuleContext_1.useMdmEntity)() || {};
    var modifiedEntity = (0, MdmModuleContext_1.useMdmModifiedEntity)(entity === null || entity === void 0 ? void 0 : entity.uri) || {};
    var isViewMode = (0, MdmModuleContext_1.useMdmIsViewMode)();
    var imageAttributeConfig = (0, MdmModuleContext_1.useMdmImageAttributesFieldsOrder)() || {};
    var entityToShow = isViewMode ? entity : modifiedEntity;
    var imageAttributeFieldsOrder = imageAttributeConfig[entity === null || entity === void 0 ? void 0 : entity.type] || (imageAttributeConfig === null || imageAttributeConfig === void 0 ? void 0 : imageAttributeConfig.default) || {};
    (0, react_1.useEffect)(function () {
        setIsDefault((entityToShow === null || entityToShow === void 0 ? void 0 : entityToShow.defaultProfilePic) === (attributeValue === null || attributeValue === void 0 ? void 0 : attributeValue.uri));
    }, [attributeValue === null || attributeValue === void 0 ? void 0 : attributeValue.uri, entityToShow]);
    var handleChange = (0, react_1.useCallback)(function () {
        handleSetAsDefault(attributeValue.uri);
    }, [attributeValue === null || attributeValue === void 0 ? void 0 : attributeValue.uri]);
    return (react_1.default.createElement(Box_1.default, { className: (0, classnames_1.default)(styles.root, className) },
        react_1.default.createElement(Box_1.default, { className: styles.header },
            react_1.default.createElement(Typography_1.default, { className: styles.headerTitle }, ui_i18n_1.default.text('Details'))),
        react_1.default.createElement(Box_1.default, { className: styles.bodyWrapper },
            react_1.default.createElement(Box_1.default, { className: styles.body },
                react_1.default.createElement(FormControlLabel_1.default, { classes: { root: styles.formControlLabel, label: styles.checkboxLabel }, control: react_1.default.createElement(Checkbox_1.default, { className: styles.checkbox, checked: isDefault, onChange: handleChange }), label: ui_i18n_1.default.text('Set as default') }),
                react_1.default.createElement(MetaInfo_1.MetaInfo, { attributeType: attributeType, imageAttributeFieldsOrder: imageAttributeFieldsOrder, attributeValue: attributeValue })))));
};
exports.ImageDetailsViewSidebar = ImageDetailsViewSidebar;
