const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_utils = require("../clientName/utils.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
const require_index = require("../../utils/index.js");
const require_locales = require("./locales.js");
const require_serve = require("./serve.js");
const require_index$1 = require("./components/PermissionManager/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let ahooks = require("ahooks");
let _ant_design_icons = require("@ant-design/icons");
require("./index.less");
//#region src/plus/saasRole/index.tsx
const AntdLayout = antd.Layout;
const AntdSider = antd.Layout.Sider;
const AntdContent = antd.Layout.Content;
const AntdTag = antd.Tag;
const AntdDrawer = antd.Drawer;
const RoleCard = ({ role, isSelected, onSelect, onEdit, onDelete, getText, getLocaleText }) => {
	const menuItems = [{
		key: "edit",
		label: getText("pisell2.saas.role.edit"),
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.EditOutlined, null),
		onClick: (e) => {
			e.domEvent.stopPropagation();
			onEdit === null || onEdit === void 0 || onEdit();
		}
	}, {
		key: "delete",
		label: getText("pisell2.saas.role.delete"),
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.DeleteOutlined, null),
		danger: true,
		onClick: (e) => {
			e.domEvent.stopPropagation();
			onDelete === null || onDelete === void 0 || onDelete();
		}
	}];
	return /* @__PURE__ */ react.default.createElement("div", { onClick: onSelect }, /* @__PURE__ */ react.default.createElement(antd.Card, {
		className: (0, classnames.default)("saas-role-card", { "saas-role-card-selected": isSelected }),
		hoverable: true
	}, /* @__PURE__ */ react.default.createElement("div", {
		className: "saas-role-card-content",
		style: { position: "relative" }
	}, /* @__PURE__ */ react.default.createElement("h4", {
		className: "saas-role-card-title",
		style: { paddingRight: 24 }
	}, getLocaleText(role.name)), /* @__PURE__ */ react.default.createElement("p", { className: "saas-role-card-count" }, role.tenant_account_count || 0, " ", getText("pisell2.saas.role.members-text"))), /* @__PURE__ */ react.default.createElement(antd.Dropdown, {
		menu: { items: menuItems },
		trigger: ["click"],
		placement: "bottomRight"
	}, /* @__PURE__ */ react.default.createElement("div", {
		onClick: (e) => e.stopPropagation(),
		style: {
			fontSize: 16,
			cursor: "pointer",
			display: "inline-flex",
			alignItems: "center",
			padding: "0 4px"
		}
	}, /* @__PURE__ */ react.default.createElement(_ant_design_icons.MoreOutlined, null)))));
};
/**
* SaasRole 角色管理组件
*
* 提供完整的角色管理功能，包括：
* - 角色的创建、编辑、删除
* - 角色成员管理
* - 角色权限配置
* - 角色字段配置
*/
const SaasRole = ({ className, style }) => {
	var _context$appHelper, _context$engine;
	const context = require_useEngineContext.default();
	const utils = (context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
	if (utils === null || utils === void 0 ? void 0 : utils.request) require_index.request.setRequest(utils.request);
	_pisell_utils.locales.init(require_locales.default, (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || "en");
	const getText = _pisell_utils.locales.getText;
	const getLocaleText = (0, react.useCallback)((text) => {
		var _context$appHelper2;
		if (!text) return "";
		if (typeof text === "string") return text;
		const { translation } = (context === null || context === void 0 || (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 ? void 0 : _context$appHelper2.utils) || {};
		return translation(text);
	}, [context]);
	const [selectedRoleId, setSelectedRoleId] = (0, react.useState)(null);
	const [addMemberDrawerVisible, setAddMemberDrawerVisible] = (0, react.useState)(false);
	const [selectedMemberIds, setSelectedMemberIds] = (0, react.useState)([]);
	const [memberFilterKeyword, setMemberFilterKeyword] = (0, react.useState)("");
	const [activeTab, setActiveTab] = (0, react.useState)("members");
	const [createModalVisible, setCreateModalVisible] = (0, react.useState)(false);
	const [createForm] = antd.Form.useForm();
	const [roleForEdit, setRoleForEdit] = (0, react.useState)(null);
	const [editForm] = antd.Form.useForm();
	const [modal, contextHolder] = antd.Modal.useModal();
	const { data: roles = [], loading: rolesLoading, run: refreshRoles } = (0, ahooks.useRequest)(require_serve.getRoles, { onSuccess: (data) => {
		if (data.length > 0 && !selectedRoleId) setSelectedRoleId(data[0].id);
		else if (data.length === 0) setSelectedRoleId(null);
	} });
	const selectedRole = (0, react.useMemo)(() => roles.find((role) => role.id === selectedRoleId), [roles, selectedRoleId]);
	const { data: { list: extensionFormList = [] } = {} } = (0, ahooks.useRequest)(require_serve.getExtensionFormList, { defaultParams: [{
		skip: 0,
		num: 499,
		type: "custom"
	}] });
	const extensionTableOptions = (0, react.useMemo)(() => {
		const disabledExtensionFormIds = roleForEdit ? roles.filter((role) => {
			var _role$metadata;
			return role.id !== roleForEdit.id && ((_role$metadata = role.metadata) === null || _role$metadata === void 0 ? void 0 : _role$metadata.extension_form_id);
		}).map((role) => {
			var _role$metadata2;
			return (_role$metadata2 = role.metadata) === null || _role$metadata2 === void 0 ? void 0 : _role$metadata2.extension_form_id;
		}) : [];
		return (extensionFormList === null || extensionFormList === void 0 ? void 0 : extensionFormList.map((item) => {
			return {
				label: item.title,
				value: item.id,
				disabled: disabledExtensionFormIds.includes(item.id)
			};
		})) || [];
	}, [
		extensionFormList,
		roles,
		roleForEdit
	]);
	(0, react.useEffect)(() => {
		document.body.id = "body";
	}, [className, style]);
	const { data: membersData, loading: membersLoading, run: refreshMembers } = (0, ahooks.useRequest)(require_asyncToGenerator._asyncToGenerator(function* () {
		if (!selectedRoleId) return {
			list: [],
			count: 0
		};
		return require_serve.getRoleMembers({
			tenant_role_ids: [selectedRoleId],
			with: ["account", "roles"],
			page: 1,
			size: 499
		});
	}), {
		refreshDeps: [selectedRoleId],
		ready: !!selectedRoleId
	});
	const { data: availablePermissions = {} } = (0, ahooks.useRequest)(require_serve.getRolePermission, {});
	const { data: allMembersData, loading: allMembersLoading, run: fetchAllMembers } = (0, ahooks.useRequest)(require_serve.getAllMembers, {
		defaultParams: [{
			page: 1,
			size: 100
		}],
		manual: true
	});
	const { runAsync: createRoleRun, loading: createRoleLoading } = (0, ahooks.useRequest)(require_serve.createRole, { manual: true });
	const { runAsync: updateRoleRun, loading: updateRoleLoading } = (0, ahooks.useRequest)(require_serve.updateRole, { manual: true });
	const { runAsync: deleteRoleRun, loading: deleteRoleLoading } = (0, ahooks.useRequest)(require_serve.deleteRole, { manual: true });
	const { runAsync: updateRoleMembersRun, loading: updateRoleMembersLoading } = (0, ahooks.useRequest)(require_serve.updateRoleMembers, { manual: true });
	const { runAsync: removeRoleMemberRun, loading: removeRoleMemberLoading } = (0, ahooks.useRequest)(require_serve.removeRoleMember, { manual: true });
	/**
	* 打开创建角色对话框
	*/
	const handleOpenCreateModal = () => {
		createForm.resetFields();
		setCreateModalVisible(true);
	};
	/**
	* 创建角色
	*/
	const handleCreateRole = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			try {
				const newRole = yield createRoleRun(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, yield createForm.validateFields()), {}, { permission: ["*"] }));
				setCreateModalVisible(false);
				createForm.resetFields();
				refreshRoles();
				setSelectedRoleId(newRole.id);
			} catch (error) {}
		});
		return function handleCreateRole() {
			return _ref.apply(this, arguments);
		};
	}();
	/**
	* 打开编辑角色对话框
	*/
	const handleOpenEditModal = (role) => {
		editForm.setFieldsValue({
			name: role.name,
			code: role.code,
			description: role.description,
			metadata: role.metadata
		});
		setRoleForEdit(role);
	};
	/**
	* 编辑角色
	*/
	const handleEditRole = function() {
		var _ref2 = require_asyncToGenerator._asyncToGenerator(function* () {
			if (!roleForEdit) return;
			try {
				const values = yield editForm.validateFields();
				yield updateRoleRun(roleForEdit.id, values);
				setRoleForEdit(null);
				refreshRoles();
			} catch (error) {}
		});
		return function handleEditRole() {
			return _ref2.apply(this, arguments);
		};
	}();
	/**
	* 删除角色
	*/
	const handleDeleteRole = function() {
		var _ref3 = require_asyncToGenerator._asyncToGenerator(function* (role) {
			if (roles.length < 2) {
				modal.warning({ title: getText("pisell2.saas.role.at-least-one-role") });
				return;
			}
			if (!(role === null || role === void 0 ? void 0 : role.id)) return;
			if (Number(role === null || role === void 0 ? void 0 : role.tenant_account_count) > 0) {
				modal.warning({ title: getText("pisell2.saas.role.role-has-members") });
				return;
			}
			const roleId = role.id;
			try {
				yield deleteRoleRun(roleId);
				if (roleId === selectedRoleId) setSelectedRoleId(null);
				refreshRoles();
			} catch (error) {}
		});
		return function handleDeleteRole(_x) {
			return _ref3.apply(this, arguments);
		};
	}();
	/**
	* 打开添加成员 Drawer
	*/
	const handleOpenAddMemberDrawer = function() {
		var _ref4 = require_asyncToGenerator._asyncToGenerator(function* () {
			if (!selectedRoleId) return;
			try {
				yield fetchAllMembers({
					page: 1,
					size: 100
				});
				setSelectedMemberIds([]);
				setAddMemberDrawerVisible(true);
			} catch (error) {}
		});
		return function handleOpenAddMemberDrawer() {
			return _ref4.apply(this, arguments);
		};
	}();
	/**
	* 添加成员
	*/
	const handleAddMembers = function() {
		var _ref5 = require_asyncToGenerator._asyncToGenerator(function* () {
			if (!selectedRoleId || selectedMemberIds.length === 0) return;
			try {
				const existingMemberIds = (membersData === null || membersData === void 0 ? void 0 : membersData.list.map((m) => m.id)) || [];
				yield updateRoleMembersRun(selectedRoleId, [...new Set([...selectedMemberIds, ...existingMemberIds])]);
				setAddMemberDrawerVisible(false);
				refreshMembers();
				refreshRoles();
			} catch (error) {}
		});
		return function handleAddMembers() {
			return _ref5.apply(this, arguments);
		};
	}();
	/**
	* 移除成员
	*/
	const handleRemoveMember = function() {
		var _ref6 = require_asyncToGenerator._asyncToGenerator(function* (member) {
			if (!selectedRoleId) return;
			try {
				yield removeRoleMemberRun(selectedRoleId, member.id);
				refreshMembers();
				refreshRoles();
			} catch (error) {}
		});
		return function handleRemoveMember(_x2) {
			return _ref6.apply(this, arguments);
		};
	}();
	/**
	* 更新角色权限
	*/
	const handlePermissionChange = function() {
		var _ref7 = require_asyncToGenerator._asyncToGenerator(function* (permissions) {
			if (!selectedRole) return;
			try {
				yield updateRoleRun(selectedRole.id, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, selectedRole), {}, { permission: permissions }));
				refreshRoles();
			} catch (error) {
				console.error("Update permission error:", error);
			}
		});
		return function handlePermissionChange(_x3) {
			return _ref7.apply(this, arguments);
		};
	}();
	const memberColumns = [
		{
			title: getText("pisell2.saas.role.member-name"),
			dataIndex: "nickname",
			key: "nickname",
			width: 150,
			render: (text, record) => {
				var _record$account;
				return record.nickname || ((_record$account = record.account) === null || _record$account === void 0 ? void 0 : _record$account.name) || "-";
			}
		},
		{
			title: getText("pisell2.saas.role.member-id"),
			dataIndex: "member_id",
			key: "member_id",
			width: 120,
			render: (text) => text || "-"
		},
		{
			title: getText("pisell2.saas.role.member-email"),
			key: "email",
			width: 250,
			render: (_, record) => {
				var _record$account2;
				return ((_record$account2 = record.account) === null || _record$account2 === void 0 ? void 0 : _record$account2.email) || "-";
			}
		},
		{
			title: getText("pisell2.saas.role.member-mobile"),
			key: "mobile",
			width: 120,
			render: (_, record) => {
				var _record$account3;
				return ((_record$account3 = record.account) === null || _record$account3 === void 0 ? void 0 : _record$account3.phone) || "-";
			}
		},
		{
			title: getText("pisell2.saas.role.actions"),
			key: "actions",
			width: 100,
			fixed: "right",
			render: (_, record) => {
				let tip = getText("pisell2.saas.role.confirm-remove-member");
				if (tip.includes("{name}")) tip = /* @__PURE__ */ react.default.createElement("span", null, tip.split("{name}")[0], /* @__PURE__ */ react.default.createElement("span", { style: { fontWeight: "bold" } }, require_utils.getClientName(record.account)), tip.split("{name}")[1]);
				return /* @__PURE__ */ react.default.createElement(antd.Button, {
					type: "text",
					danger: true,
					icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, { type: "pisell2-user-minus-01" }),
					onClick: (e) => {
						e.stopPropagation();
						antd.Modal.confirm({
							title: getText("pisell2.saas.role.remove-member"),
							content: tip,
							okText: getText("pisell2.saas.role.confirm"),
							cancelText: getText("pisell2.saas.role.cancel"),
							onOk: () => handleRemoveMember(record),
							okButtonProps: { danger: true }
						});
					}
				});
			}
		}
	];
	const availableMemberColumns = [
		{
			title: getText("pisell2.saas.role.member-name"),
			dataIndex: "nickname",
			key: "nickname",
			render: (text, record) => {
				var _record$account4;
				return record.nickname || ((_record$account4 = record.account) === null || _record$account4 === void 0 ? void 0 : _record$account4.name) || "-";
			}
		},
		{
			title: getText("pisell2.saas.role.member-id"),
			dataIndex: "member_id",
			key: "member_id",
			render: (text) => text || "-"
		},
		{
			title: getText("pisell2.saas.role.member-current-roles"),
			dataIndex: "roles",
			key: "roles",
			width: 200,
			render: (roles) => /* @__PURE__ */ react.default.createElement("span", null, roles === null || roles === void 0 ? void 0 : roles.map((role) => /* @__PURE__ */ react.default.createElement(AntdTag, { key: role.id }, getLocaleText(role.name))))
		}
	];
	const renderContent = () => {
		if (!selectedRole) return /* @__PURE__ */ react.default.createElement("div", { className: "saas-role-empty" }, /* @__PURE__ */ react.default.createElement(antd.Empty, { description: getText("pisell2.saas.role.no-role-selected") }));
		const tabItems = [{
			key: "members",
			label: getText("pisell2.saas.role.members"),
			children: /* @__PURE__ */ react.default.createElement("div", { className: "saas-role-members" }, /* @__PURE__ */ react.default.createElement("div", { className: "saas-role-members-header" }, /* @__PURE__ */ react.default.createElement(antd.Input, {
				prefix: /* @__PURE__ */ react.default.createElement(_ant_design_icons.SearchOutlined, null),
				placeholder: getText("pisell2.saas.role.search"),
				allowClear: true,
				style: { width: 300 },
				onChange: (e) => setMemberFilterKeyword(e.target.value)
			}), /* @__PURE__ */ react.default.createElement(antd.Button, {
				type: "primary",
				icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.PlusOutlined, null),
				onClick: handleOpenAddMemberDrawer
			}, getText("pisell2.saas.role.add-member"))), /* @__PURE__ */ react.default.createElement(antd.Table, {
				columns: memberColumns,
				dataSource: membersData === null || membersData === void 0 ? void 0 : membersData.list.filter((member) => {
					var _member$nickname, _member$account, _member$member_id;
					return memberFilterKeyword ? ((_member$nickname = member.nickname) === null || _member$nickname === void 0 ? void 0 : _member$nickname.toLowerCase().includes(memberFilterKeyword.toLowerCase())) || ((_member$account = member.account) === null || _member$account === void 0 || (_member$account = _member$account.email) === null || _member$account === void 0 ? void 0 : _member$account.toLowerCase().includes(memberFilterKeyword.toLowerCase())) || ((_member$member_id = member.member_id) === null || _member$member_id === void 0 ? void 0 : _member$member_id.toLowerCase().includes(memberFilterKeyword.toLowerCase())) : true;
				}),
				rowKey: "id",
				loading: membersLoading,
				pagination: {
					total: (membersData === null || membersData === void 0 ? void 0 : membersData.count) || 0,
					showSizeChanger: true
				},
				scroll: { x: "max-content" },
				locale: { emptyText: getText("pisell2.saas.role.no-members-in-role") }
			}))
		}, {
			key: "permissions",
			label: getText("pisell2.saas.role.permissions"),
			children: /* @__PURE__ */ react.default.createElement(require_index$1.default, {
				availablePermissions,
				currentPermissions: (selectedRole === null || selectedRole === void 0 ? void 0 : selectedRole.permission) || [],
				onChange: handlePermissionChange,
				getLocaleText,
				getText,
				updating: updateRoleLoading
			})
		}];
		return /* @__PURE__ */ react.default.createElement("div", { className: "saas-role-detail" }, /* @__PURE__ */ react.default.createElement("div", { className: "saas-role-detail-header" }, /* @__PURE__ */ react.default.createElement("div", { className: "saas-role-detail-title" }, /* @__PURE__ */ react.default.createElement("h2", null, getLocaleText(selectedRole.name))), /* @__PURE__ */ react.default.createElement("p", { className: "saas-role-detail-description" }, getLocaleText(selectedRole.description))), /* @__PURE__ */ react.default.createElement(antd.Tabs, {
			activeKey: activeTab,
			onChange: setActiveTab,
			items: tabItems
		}));
	};
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("saas-role", className),
		style
	}, /* @__PURE__ */ react.default.createElement(AntdLayout, { className: "saas-role-layout" }, /* @__PURE__ */ react.default.createElement(AntdSider, {
		width: 300,
		className: "saas-role-sider",
		theme: "light"
	}, /* @__PURE__ */ react.default.createElement("div", { className: "saas-role-header" }, /* @__PURE__ */ react.default.createElement("h3", null, getText("pisell2.saas.role.title")), /* @__PURE__ */ react.default.createElement(antd.Button, {
		type: "primary",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.PlusOutlined, null),
		onClick: handleOpenCreateModal
	}, getText("pisell2.saas.role.create"))), /* @__PURE__ */ react.default.createElement("div", { className: "saas-role-list" }, roles.map((role) => /* @__PURE__ */ react.default.createElement(RoleCard, {
		key: role.id,
		role,
		isSelected: role.id === selectedRoleId,
		onSelect: () => setSelectedRoleId(role.id),
		onEdit: () => handleOpenEditModal(role),
		onDelete: () => handleDeleteRole(role),
		getText,
		getLocaleText
	})))), /* @__PURE__ */ react.default.createElement(AntdContent, { className: "saas-role-content" }, renderContent())), /* @__PURE__ */ react.default.createElement(antd.Modal, {
		title: getText("pisell2.saas.role.create-role"),
		open: createModalVisible,
		onOk: handleCreateRole,
		onCancel: () => setCreateModalVisible(false),
		confirmLoading: createRoleLoading,
		okText: getText("pisell2.saas.role.save"),
		cancelText: getText("pisell2.saas.role.cancel"),
		width: 600,
		styles: { header: { padding: "0px 0px 8px 0px" } }
	}, /* @__PURE__ */ react.default.createElement(antd.Form, {
		form: createForm,
		layout: "vertical",
		size: "large"
	}, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: getText("pisell2.saas.role.name"),
		name: "name",
		rules: [{
			required: true,
			message: getText("pisell2.saas.role.enter-role-name")
		}]
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.BaseTranslation, {
		placeholder: getText("pisell2.saas.role.enter-role-name"),
		maxLength: 100
	})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: getText("pisell2.saas.role.code"),
		name: "code",
		rules: [{
			required: true,
			message: getText("pisell2.saas.role.enter-role-code")
		}, {
			pattern: /^[a-z0-9\-_.]+$/,
			message: getText("pisell2.saas.role.role-code-format")
		}],
		extra: getText("pisell2.saas.role.role-code-format")
	}, /* @__PURE__ */ react.default.createElement(antd.Input, { placeholder: getText("pisell2.saas.role.enter-role-code") })), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: getText("pisell2.saas.role.description"),
		name: "description"
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.BaseTranslation, {
		placeholder: getText("pisell2.saas.role.enter-role-description"),
		type: "textarea",
		rows: 4,
		showCount: true,
		maxLength: 500
	})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: getText("pisell2.saas.role.extension-table"),
		name: ["metadata", "extension_form_id"],
		extra: getText("pisell2.saas.role.select-extension-table")
	}, /* @__PURE__ */ react.default.createElement(antd.Select, {
		placeholder: getText("pisell2.saas.role.select-extension-table"),
		options: extensionTableOptions,
		allowClear: true
	})))), /* @__PURE__ */ react.default.createElement(antd.Modal, {
		title: getText("pisell2.saas.role.edit-role"),
		open: !!roleForEdit,
		onOk: handleEditRole,
		onCancel: () => setRoleForEdit(null),
		confirmLoading: updateRoleLoading,
		okText: getText("pisell2.saas.role.save"),
		cancelText: getText("pisell2.saas.role.cancel"),
		width: 600,
		styles: { header: { padding: "0px 0px 8px 0px" } }
	}, /* @__PURE__ */ react.default.createElement(antd.Form, {
		form: editForm,
		layout: "vertical",
		size: "large"
	}, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: getText("pisell2.saas.role.name"),
		name: "name",
		rules: [{
			required: true,
			message: getText("pisell2.saas.role.enter-role-name")
		}]
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.BaseTranslation, {
		placeholder: getText("pisell2.saas.role.enter-role-name"),
		maxLength: 100
	})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: getText("pisell2.saas.role.code"),
		name: "code"
	}, /* @__PURE__ */ react.default.createElement(antd.Input, {
		placeholder: getText("pisell2.saas.role.enter-role-code"),
		disabled: true
	})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: getText("pisell2.saas.role.description"),
		name: "description"
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.BaseTranslation, {
		placeholder: getText("pisell2.saas.role.enter-role-description"),
		type: "textarea",
		rows: 4,
		showCount: true,
		maxLength: 500
	})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: getText("pisell2.saas.role.extension-table"),
		name: ["metadata", "extension_form_id"],
		extra: getText("pisell2.saas.role.select-extension-table")
	}, /* @__PURE__ */ react.default.createElement(antd.Select, {
		placeholder: getText("pisell2.saas.role.select-extension-table"),
		options: extensionTableOptions,
		allowClear: true,
		showSearch: true,
		optionFilterProp: "label",
		filterSort: (optionA, optionB) => {
			var _optionA$label, _optionB$label;
			return ((_optionA$label = optionA === null || optionA === void 0 ? void 0 : optionA.label) !== null && _optionA$label !== void 0 ? _optionA$label : "").toLowerCase().localeCompare(((_optionB$label = optionB === null || optionB === void 0 ? void 0 : optionB.label) !== null && _optionB$label !== void 0 ? _optionB$label : "").toLowerCase());
		}
	})))), /* @__PURE__ */ react.default.createElement(AntdDrawer, {
		title: getText("pisell2.saas.role.add-members-to-role"),
		open: addMemberDrawerVisible,
		onClose: () => setAddMemberDrawerVisible(false),
		width: 600,
		footer: /* @__PURE__ */ react.default.createElement("div", { style: {
			textAlign: "right",
			padding: "8px 0px"
		} }, /* @__PURE__ */ react.default.createElement(antd.Button, {
			onClick: () => setAddMemberDrawerVisible(false),
			style: { marginRight: 8 }
		}, getText("pisell2.saas.role.cancel")), /* @__PURE__ */ react.default.createElement(antd.Button, {
			onClick: handleAddMembers,
			type: "primary",
			loading: updateRoleMembersLoading,
			disabled: selectedMemberIds.length === 0
		}, getText("pisell2.saas.role.add")))
	}, /* @__PURE__ */ react.default.createElement(antd.Input, {
		placeholder: getText("pisell2.saas.role.search"),
		allowClear: true,
		style: { marginBottom: 16 },
		prefix: /* @__PURE__ */ react.default.createElement(_ant_design_icons.SearchOutlined, null),
		onChange: (e) => {
			fetchAllMembers({
				page: 1,
				size: 100,
				search: e.target.value
			});
		}
	}), /* @__PURE__ */ react.default.createElement(antd.Table, {
		tableLayout: "fixed",
		columns: availableMemberColumns,
		dataSource: ((allMembersData === null || allMembersData === void 0 ? void 0 : allMembersData.list) || []).filter((m) => !(membersData === null || membersData === void 0 ? void 0 : membersData.list.some((existing) => existing.id === m.id))),
		rowKey: "id",
		rowSelection: {
			preserveSelectedRowKeys: true,
			selectedRowKeys: selectedMemberIds,
			onChange: (selectedKeys) => {
				setSelectedMemberIds(selectedKeys);
				console.log(selectedKeys);
			}
		},
		loading: allMembersLoading,
		pagination: false,
		size: "middle",
		bordered: false,
		locale: { emptyText: getText("pisell2.saas.role.all-members-in-role") }
	}))), /* @__PURE__ */ react.default.createElement(antd.ConfigProvider, { prefixCls: "pisell-lowcode" }, contextHolder));
};
//#endregion
exports.default = SaasRole;
