import useIsMobileTable from "../hooks/useIsMobileTable.js";
import Filter from "../../filter/index.js";
import Sort from "../../sort/index.js";
import Buttons from "../Header/Buttons/index.js";
import ColumnsSetting from "./component/ColumnsSetting/index.js";
import ExportImport from "./component/ExportImport/index.js";
import GallerySetting from "./component/GallerySetting/index.js";
import Group from "./component/Group/index.js";
import ViewMode from "./component/ViewMode/index.js";
import React, { useMemo } from "react";
import { Form } from "antd";
import "./index.less";
//#region src/components/table/Actions/index.tsx
const Actions = ({ filter, sort, columnSetting, dataSourceGroup, tableId, localPagination, buttons, view, gallery, exportImport }) => {
	const form = Form.useFormInstance();
	const isMobileBool = useIsMobileTable();
	const viewMode = Form.useWatch("view_mode", {
		form,
		preserve: true
	});
	const showActions = useMemo(() => {
		if (React.isValidElement(filter) || React.isValidElement(filter === null || filter === void 0 ? void 0 : filter.dom)) return true;
		return (filter === null || filter === void 0 ? void 0 : filter.show) || (sort === null || sort === void 0 ? void 0 : sort.show) || (columnSetting === null || columnSetting === void 0 ? void 0 : columnSetting.show) || (dataSourceGroup === null || dataSourceGroup === void 0 ? void 0 : dataSourceGroup.show) || view.multiple || (exportImport === null || exportImport === void 0 ? void 0 : exportImport.show);
	}, [
		filter === null || filter === void 0 ? void 0 : filter.show,
		sort === null || sort === void 0 ? void 0 : sort.show,
		columnSetting === null || columnSetting === void 0 ? void 0 : columnSetting.show,
		dataSourceGroup === null || dataSourceGroup === void 0 ? void 0 : dataSourceGroup.show,
		view.multiple,
		exportImport === null || exportImport === void 0 ? void 0 : exportImport.show
	]);
	const filterRender = useMemo(() => {
		if (React.isValidElement(filter)) return filter;
		if (React.isValidElement(filter === null || filter === void 0 ? void 0 : filter.dom)) return filter.dom;
		return /* @__PURE__ */ React.createElement(Filter, {
			filter,
			isRenderFormContent: false,
			tableId,
			viewMode,
			isMobile: isMobileBool
		});
	}, [
		filter,
		tableId,
		viewMode,
		isMobileBool
	]);
	return showActions ? /* @__PURE__ */ React.createElement("div", { className: "materials-grid-actions" }, /* @__PURE__ */ React.createElement("div", { className: "left-wrap" }, filterRender), /* @__PURE__ */ React.createElement("div", {
		className: "right-wrap",
		style: { columnGap: isMobileBool ? 0 : 12 }
	}, view.multiple && /* @__PURE__ */ React.createElement(Form.Item, {
		name: "view_mode",
		noStyle: true
	}, /* @__PURE__ */ React.createElement(ViewMode, { view })), (exportImport === null || exportImport === void 0 ? void 0 : exportImport.show) ? /* @__PURE__ */ React.createElement(ExportImport, { exportImport }) : null, (dataSourceGroup === null || dataSourceGroup === void 0 ? void 0 : dataSourceGroup.show) && viewMode === "grid" && /* @__PURE__ */ React.createElement(Form.Item, {
		name: "group_by",
		noStyle: true
	}, /* @__PURE__ */ React.createElement(Group, { setting: dataSourceGroup })), (columnSetting === null || columnSetting === void 0 ? void 0 : columnSetting.show) && viewMode === "grid" && /* @__PURE__ */ React.createElement(Form.Item, {
		name: ["column_setting"],
		noStyle: true
	}, /* @__PURE__ */ React.createElement(ColumnsSetting, null)), (columnSetting === null || columnSetting === void 0 ? void 0 : columnSetting.show) && viewMode === "gallery" && /* @__PURE__ */ React.createElement(GallerySetting, {
		setting: gallery,
		currentViewMode: viewMode
	}), (sort === null || sort === void 0 ? void 0 : sort.show) ? /* @__PURE__ */ React.createElement(Form.Item, {
		name: "order_by",
		noStyle: true
	}, /* @__PURE__ */ React.createElement(Sort, {
		list: (sort === null || sort === void 0 ? void 0 : sort.list) || [],
		localPagination
	})) : null, !!(buttons === null || buttons === void 0 ? void 0 : buttons.length) && /* @__PURE__ */ React.createElement(Buttons, {
		list: buttons,
		style: isMobileBool ? { marginLeft: 8 } : {}
	}))) : null;
};
//#endregion
export { Actions as default };
