const require_runtime = require("../../_virtual/_rolldown/runtime.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let _pisell_icon_es_Check = require("@pisell/icon/es/Check");
_pisell_icon_es_Check = require_runtime.__toESM(_pisell_icon_es_Check);
let _pisell_icon_es_ChevronDown = require("@pisell/icon/es/ChevronDown");
_pisell_icon_es_ChevronDown = require_runtime.__toESM(_pisell_icon_es_ChevronDown);
let src_components_organizationTenantSwitcher_defaultLogo_png = require("./defaultLogo.png");
src_components_organizationTenantSwitcher_defaultLogo_png = require_runtime.__toESM(src_components_organizationTenantSwitcher_defaultLogo_png);
require("./index.less");
//#region src/components/organizationTenantSwitcher/index.tsx
const Logo = ({ logo, className }) => {
	return /* @__PURE__ */ react.default.createElement("img", {
		src: logo || src_components_organizationTenantSwitcher_defaultLogo_png.default,
		alt: "logo",
		className: (0, classnames.default)("organization-tenant-switcher-item-logo", className)
	});
};
const OrganizationTenantSwitcher = ({ onChange, value, options, showLogo = true, showName = true, readOnly = false, onClick }) => {
	const getCurrentOrg = () => {
		return options.find((opt) => (opt === null || opt === void 0 ? void 0 : opt.value) === value);
	};
	const items = [...options.map((opt) => ({
		key: opt === null || opt === void 0 ? void 0 : opt.value,
		label: /* @__PURE__ */ react.default.createElement("div", { className: "organization-tenant-switcher-item" }, /* @__PURE__ */ react.default.createElement(Logo, { logo: opt === null || opt === void 0 ? void 0 : opt.logo }), /* @__PURE__ */ react.default.createElement("div", {
			className: "organization-tenant-switcher-item-name",
			title: opt === null || opt === void 0 ? void 0 : opt.label
		}, opt === null || opt === void 0 ? void 0 : opt.label), (opt === null || opt === void 0 ? void 0 : opt.value) === value && /* @__PURE__ */ react.default.createElement(_pisell_icon_es_Check.default, { className: "organization-tenant-switcher-item-check" }))
	}))];
	const handleMenuClick = (e) => {
		if (e.key !== "create") {
			const selectedOption = options.find((opt) => opt.value === e.key);
			if (selectedOption) onChange === null || onChange === void 0 || onChange(selectedOption.value, selectedOption);
		}
	};
	const currentOrg = getCurrentOrg();
	return /* @__PURE__ */ react.default.createElement(antd.Dropdown, {
		overlayClassName: "organization-tenant-switcher-overlay",
		menu: {
			items,
			onClick: handleMenuClick,
			selectedKeys: [value],
			style: {
				maxHeight: 370,
				overflow: "auto"
			}
		},
		trigger: readOnly ? [] : ["click"],
		disabled: readOnly
	}, /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("organization-tenant-switcher-switch", { "organization-tenant-switcher-switch-readonly": readOnly }),
		style: !showLogo ? { paddingLeft: 16 } : {},
		onClick
	}, showLogo && /* @__PURE__ */ react.default.createElement(Logo, {
		logo: currentOrg === null || currentOrg === void 0 ? void 0 : currentOrg.logo,
		className: "organization-tenant-switcher-switch-logo"
	}), /* @__PURE__ */ react.default.createElement("div", {
		className: "organization-tenant-switcher-switch-name",
		title: currentOrg === null || currentOrg === void 0 ? void 0 : currentOrg.label
	}, showName && (currentOrg === null || currentOrg === void 0 ? void 0 : currentOrg.label)), !readOnly && /* @__PURE__ */ react.default.createElement(_pisell_icon_es_ChevronDown.default, { className: "organization-tenant-switcher-switch-chevron" })));
};
//#endregion
exports.default = OrganizationTenantSwitcher;
