import ColumnsSetting from "../../../table/Actions/component/ColumnsSetting/index.js";
import withContainer from "../../utils/withContainer.js";
import { saveColumnSettingToLocal } from "./utils.js";
import React, { forwardRef, useEffect, useImperativeHandle, useState } from "react";
//#region src/components/pisellDataSourceContainer/components/ColumnsSetting/index.tsx
const COLUMNS_SHARED_STATE_KEYS = {
	columnsValue: (instanceId) => `${instanceId}:columns:value`,
	columnsChange: (instanceId) => `${instanceId}:columns:change`
};
var ColumnsSetting_default = withContainer(forwardRef((props, ref) => {
	const { refManager, scopeId = "table", __id } = props;
	const [value, setValue] = useState([]);
	useImperativeHandle(ref, () => ({}), []);
	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) 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.createElement(ColumnsSetting, {
		value,
		onChange
	});
}), "columnsSetting");
//#endregion
export { COLUMNS_SHARED_STATE_KEYS, ColumnsSetting_default as default };
