import React from "react";
import { Dropdown } from "antd";
import classNames from "classnames";
import Check from "@pisell/icon/es/Check";
import ChevronDown from "@pisell/icon/es/ChevronDown";
import defaultLogo from "./defaultLogo.png";
import "./index.less";
//#region src/components/organizationTenantSwitcher/index.tsx
const Logo = ({ logo, className }) => {
	return /* @__PURE__ */ React.createElement("img", {
		src: logo || defaultLogo,
		alt: "logo",
		className: classNames("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.createElement("div", { className: "organization-tenant-switcher-item" }, /* @__PURE__ */ React.createElement(Logo, { logo: opt === null || opt === void 0 ? void 0 : opt.logo }), /* @__PURE__ */ React.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.createElement(Check, { 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.createElement(Dropdown, {
		overlayClassName: "organization-tenant-switcher-overlay",
		menu: {
			items,
			onClick: handleMenuClick,
			selectedKeys: [value],
			style: {
				maxHeight: 370,
				overflow: "auto"
			}
		},
		trigger: readOnly ? [] : ["click"],
		disabled: readOnly
	}, /* @__PURE__ */ React.createElement("div", {
		className: classNames("organization-tenant-switcher-switch", { "organization-tenant-switcher-switch-readonly": readOnly }),
		style: !showLogo ? { paddingLeft: 16 } : {},
		onClick
	}, showLogo && /* @__PURE__ */ React.createElement(Logo, {
		logo: currentOrg === null || currentOrg === void 0 ? void 0 : currentOrg.logo,
		className: "organization-tenant-switcher-switch-logo"
	}), /* @__PURE__ */ React.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.createElement(ChevronDown, { className: "organization-tenant-switcher-switch-chevron" })));
};
//#endregion
export { OrganizationTenantSwitcher as default };
