/**
 * amis-ui v6.14.0-beta.1
 * Copyright 2018-2025 fex
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var tslib = require('tslib');
var React = require('react');
var amisCore = require('amis-core');
var icons = require('../icons.js');
var Common = require('./Common.js');
var Item = require('./Item.js');
var FormField = require('../FormField.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
(__react_jsx__["default"] || __react_jsx__).Fragment;
var SchemaEditorItemArray = /** @class */ (function (_super) {
    tslib.__extends(SchemaEditorItemArray, _super);
    function SchemaEditorItemArray() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            collapsed: false
        };
        return _this;
    }
    SchemaEditorItemArray.prototype.toggleCollapsed = function () {
        this.setState({
            collapsed: !this.state.collapsed
        });
    };
    SchemaEditorItemArray.prototype.handleItemsChange = function (items) {
        var _a, _b;
        var value = tslib.__assign(tslib.__assign({}, this.props.value), { type: 'array', items: items });
        (_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, value);
    };
    SchemaEditorItemArray.prototype.renderItems = function () {
        var _a;
        var _b = this.props, cx = _b.classnames, value = _b.value, renderExtraProps = _b.renderExtraProps, renderModalProps = _b.renderModalProps, locale = _b.locale, __ = _b.translate, classPrefix = _b.classPrefix, disabled = _b.disabled, showInfo = _b.showInfo, types = _b.types, onTypeChange = _b.onTypeChange, enableAdvancedSetting = _b.enableAdvancedSetting, popOverContainer = _b.popOverContainer, placeholder = _b.placeholder, mobileUI = _b.mobileUI, mini = _b.mini;
        var items = (value === null || value === void 0 ? void 0 : value.items) || {
            type: 'string'
        };
        return (_J$X_("div", { className: cx('SchemaEditorProps SchemaEditorArrayProps', {
                'SchemaEditorProps--depth': showInfo !== false
            }) },
            _J$X_(Item.SchemaEditorItem, { dataName: this.props.dataName, types: types, onTypeChange: onTypeChange, label: (_a = types === null || types === void 0 ? void 0 : types.find(function (item) { return item.value === (items === null || items === void 0 ? void 0 : items.type); })) === null || _a === void 0 ? void 0 : _a.label, prefix: _J$X_("div", { className: cx('SchemaEditor-itemsLabel') }, __('JSONSchema.array_items')), value: items, onChange: this.handleItemsChange, renderExtraProps: renderExtraProps, renderModalProps: renderModalProps, locale: locale, translate: __, classnames: cx, classPrefix: classPrefix, disabled: disabled || !!(items === null || items === void 0 ? void 0 : items.$ref), enableAdvancedSetting: enableAdvancedSetting, popOverContainer: popOverContainer, placeholder: placeholder, mobileUI: mobileUI, mini: mini })));
    };
    SchemaEditorItemArray.prototype.render = function () {
        var _a = this.props, cx = _a.classnames, showInfo = _a.showInfo, formMode = _a.formMode, mini = _a.mini; _a.disabled; var mobileUI = _a.mobileUI, locale = _a.locale, classPrefix = _a.classPrefix, types = _a.types, __ = _a.translate, placeholder = _a.placeholder;
        if (formMode) {
            return this.renderForm({
                formAffixRender: function (methods) {
                    return (_J$X_(React__default["default"].Fragment, null,
                        _J$X_(FormField.Controller, { label: __('JSONSchema.array_items'), name: "items", control: methods.control, render: function (_a) {
                                var field = _a.field;
                                return (_J$X_(Item.SchemaEditorItem, tslib.__assign({}, field, { types: types, placeholder: placeholder, mobileUI: mobileUI, locale: locale, translate: __, classnames: cx, classPrefix: classPrefix, mini: false })));
                            } })));
                }
            });
        }
        return (_J$X_("div", { className: cx('SchemaEditorItem SchemaEditorArray', {
                'SchemaEditorItem--mini': mini
            }), "data-amis-name": this.props.dataName },
            showInfo !== false ? (_J$X_(React__default["default"].Fragment, null,
                mini ? null : (_J$X_("a", { className: cx('SchemaEditor-caret', {
                        'is-collapsed': this.state.collapsed
                    }), onClick: this.toggleCollapsed },
                    _J$X_(icons.Icon, { icon: "caret", className: "icon" }))),
                this.renderCommon())) : null,
            this.state.collapsed || mini ? null : this.renderItems()));
    };
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], SchemaEditorItemArray.prototype, "toggleCollapsed", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], SchemaEditorItemArray.prototype, "handleItemsChange", null);
    return SchemaEditorItemArray;
}(Common.SchemaEditorItemCommon));
Common.ITEMMAP.array = SchemaEditorItemArray;

exports.SchemaEditorItemArray = SchemaEditorItemArray;
