const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_index = require("../../../table/Actions/component/ColumnsSetting/index.js");
const require_withContainer = require("../../utils/withContainer.js");
const require_utils = require("./utils.js");
let react = require("react");
react = require_runtime.__toESM(react);
//#region src/components/pisellDataSourceContainer/components/ColumnsSetting/index.tsx
const COLUMNS_SHARED_STATE_KEYS = {
	columnsValue: (instanceId) => `${instanceId}:columns:value`,
	columnsChange: (instanceId) => `${instanceId}:columns:change`
};
const WithColumnsSetting = (0, react.forwardRef)((props, ref) => {
	const { refManager, scopeId = "table", __id } = props;
	const [value, setValue] = (0, react.useState)([]);
	(0, react.useImperativeHandle)(ref, () => ({}), []);
	(0, react.useEffect)(() => {
		return refManager.subscribeSharedState(COLUMNS_SHARED_STATE_KEYS.columnsValue(scopeId), setValue);
	}, [refManager, scopeId]);
	const onChange = (newValue) => {
		const typedValue = newValue;
		setValue(typedValue);
		refManager.setSharedState(COLUMNS_SHARED_STATE_KEYS.columnsChange(scopeId), typedValue);
		if (__id) require_utils.saveColumnSettingToLocal({
			componentId: __id,
			columnSetting: typedValue.map((col, index) => {
				var _col$sortIndex;
				return {
					key: col.key,
					dataIndex: col.dataIndex,
					title: col.title,
					titleString: col.titleString,
					isShow: col.isShow,
					sortIndex: (_col$sortIndex = col.sortIndex) !== null && _col$sortIndex !== void 0 ? _col$sortIndex : index,
					fixed: col.fixed
				};
			})
		});
	};
	return /* @__PURE__ */ react.default.createElement(require_index.default, {
		value,
		onChange
	});
});
var ColumnsSetting_default = require_withContainer.default(WithColumnsSetting, "columnsSetting");
//#endregion
exports.COLUMNS_SHARED_STATE_KEYS = COLUMNS_SHARED_STATE_KEYS;
exports.default = ColumnsSetting_default;
