/**
 * DevExtreme (cjs/ui/pivot_grid/sortable/item_render.js)
 * Version: 22.1.7 (build 23032-0308)
 * Build date: Wed Feb 01 2023
 *
 * Copyright (c) 2012 - 2023 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
exports.sortableItemRender = sortableItemRender;
var _size = require("../../../core/utils/size");
var _iterator = require("../../../core/utils/iterator");
var _renderer = _interopRequireDefault(require("../../../core/renderer"));
var _const = require("./const");

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}

function getTreeViewItem($sourceItem) {
    return $sourceItem.clone().addClass(_const.SortableConst.classes.areaBox).css("width", parseInt((0, _size.getOuterWidth)($sourceItem)))
}

function getAreaBoxItem($sourceItem, target) {
    var $item = $sourceItem.clone();
    if (target === _const.SortableConst.targets.drag) {
        (0, _iterator.each)($sourceItem, (function(idx, sourceItem) {
            var width = parseInt((0, _size.getOuterWidth)(sourceItem), 10);
            $item.eq(idx).css("width", width)
        }))
    }
    return $item
}

function getDefaultItem($sourceItem) {
    return (0, _renderer.default)("<div>").addClass(_const.SortableConst.classes.areaField).addClass(_const.SortableConst.classes.areaBox).text($sourceItem.text())
}

function getItem($sourceItem, target) {
    var isAreaBox = $sourceItem.hasClass(_const.SortableConst.classes.areaBox);
    var isTreeList = $sourceItem.attr(_const.SortableConst.attrs.treeViewItem);
    if (isAreaBox) {
        return getAreaBoxItem($sourceItem, target)
    }
    if (isTreeList) {
        return getTreeViewItem($sourceItem)
    }
    return getDefaultItem($sourceItem)
}

function wrapInFieldsContainer($item) {
    return (0, _renderer.default)("<div>").addClass(_const.SortableConst.classes.fieldsContainer).addClass(_const.SortableConst.classes.widget).append($item)
}

function sortableItemRender($sourceItem, target) {
    var $item = getItem($sourceItem, target);
    return target === _const.SortableConst.targets.drag ? wrapInFieldsContainer($item) : $item
}
