/**
 * DevExtreme (esm/__internal/ui/radio_group/m_radio_collection.js)
 * Version: 23.2.9 (build 24294-0112)
 * Build date: Sun Oct 20 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import $ from "../../../core/renderer";
import {
    deferRender
} from "../../../core/utils/common";
import {
    extend
} from "../../../core/utils/extend";
import DataExpressionMixin from "../../../ui/editor/ui.data_expression";
import CollectionWidget from "../../ui/collection/edit";
var RADIO_BUTTON_CHECKED_CLASS = "dx-radiobutton-checked";
var RADIO_BUTTON_ICON_CHECKED_CLASS = "dx-radiobutton-icon-checked";
var RADIO_BUTTON_ICON_CLASS = "dx-radiobutton-icon";
var RADIO_BUTTON_ICON_DOT_CLASS = "dx-radiobutton-icon-dot";
var RADIO_VALUE_CONTAINER_CLASS = "dx-radio-value-container";
var RADIO_BUTTON_CLASS = "dx-radiobutton";
class RadioCollection extends CollectionWidget {
    _focusTarget() {
        return $(this.element()).parent()
    }
    _nullValueSelectionSupported() {
        return true
    }
    _getDefaultOptions() {
        var defaultOptions = super._getDefaultOptions();
        return extend(defaultOptions, DataExpressionMixin._dataExpressionDefaultOptions(), {
            _itemAttributes: {
                role: "radio"
            }
        })
    }
    _initMarkup() {
        super._initMarkup();
        deferRender(() => {
            this._itemElements().addClass(RADIO_BUTTON_CLASS)
        })
    }
    _keyboardEventBindingTarget() {
        return this._focusTarget()
    }
    _postprocessRenderItem(args) {
        var {
            itemData: {
                html: html
            },
            itemElement: itemElement
        } = args;
        if (!html) {
            var $radio = $("<div>").addClass(RADIO_BUTTON_ICON_CLASS);
            $("<div>").addClass(RADIO_BUTTON_ICON_DOT_CLASS).appendTo($radio);
            var $radioContainer = $("<div>").append($radio).addClass(RADIO_VALUE_CONTAINER_CLASS);
            $(itemElement).prepend($radioContainer)
        }
        super._postprocessRenderItem(args)
    }
    _processSelectableItem($itemElement, isSelected) {
        super._processSelectableItem($itemElement, isSelected);
        $itemElement.toggleClass(RADIO_BUTTON_CHECKED_CLASS, isSelected).find(".".concat(RADIO_BUTTON_ICON_CLASS)).first().toggleClass(RADIO_BUTTON_ICON_CHECKED_CLASS, isSelected);
        this.setAria("checked", isSelected, $itemElement)
    }
    _refreshContent() {
        this._prepareContent();
        this._renderContent()
    }
    _supportedKeys() {
        var parent = super._supportedKeys();
        return extend({}, parent, {
            enter(e) {
                e.preventDefault();
                return parent.enter.apply(this, arguments)
            },
            space(e) {
                e.preventDefault();
                return parent.space.apply(this, arguments)
            }
        })
    }
    _itemElements() {
        return this._itemContainer().children(this._itemSelector())
    }
    _setAriaSelectionAttribute() {}
}
export default RadioCollection;
