var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/organizationTenantSwitcher/index.tsx
var organizationTenantSwitcher_exports = {};
__export(organizationTenantSwitcher_exports, {
  default: () => organizationTenantSwitcher_default
});
module.exports = __toCommonJS(organizationTenantSwitcher_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_classnames = __toESM(require("classnames"));
var import_Check = __toESM(require("@pisell/icon/es/Check"));
var import_ChevronDown = __toESM(require("@pisell/icon/es/ChevronDown"));
var import_defaultLogo = __toESM(require("./defaultLogo.png"));
var import_index = require("./index.less");
var Logo = ({ logo, className }) => {
  return /* @__PURE__ */ import_react.default.createElement(
    "img",
    {
      src: logo || import_defaultLogo.default,
      alt: "logo",
      className: (0, import_classnames.default)(
        "organization-tenant-switcher-item-logo",
        className
      )
    }
  );
};
var OrganizationTenantSwitcher = ({
  onChange,
  value,
  options,
  showLogo = true,
  showName = true,
  readOnly = false,
  onClick
}) => {
  const getCurrentOrg = () => {
    return options.find((opt) => (opt == null ? void 0 : opt.value) === value);
  };
  const items = [
    ...options.map((opt) => ({
      key: opt == null ? void 0 : opt.value,
      label: /* @__PURE__ */ import_react.default.createElement("div", { className: "organization-tenant-switcher-item" }, /* @__PURE__ */ import_react.default.createElement(Logo, { logo: opt == null ? void 0 : opt.logo }), /* @__PURE__ */ import_react.default.createElement("div", { className: "organization-tenant-switcher-item-name", title: opt == null ? void 0 : opt.label }, opt == null ? void 0 : opt.label), (opt == null ? void 0 : opt.value) === value && /* @__PURE__ */ import_react.default.createElement(import_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 ? void 0 : onChange(selectedOption.value, selectedOption);
      }
    }
  };
  const currentOrg = getCurrentOrg();
  return /* @__PURE__ */ import_react.default.createElement(
    import_antd.Dropdown,
    {
      overlayClassName: "organization-tenant-switcher-overlay",
      menu: {
        items,
        onClick: handleMenuClick,
        selectedKeys: [value],
        style: {
          maxHeight: 370,
          overflow: "auto"
        }
      },
      trigger: readOnly ? [] : ["click"],
      disabled: readOnly
    },
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)("organization-tenant-switcher-switch", {
          "organization-tenant-switcher-switch-readonly": readOnly
        }),
        style: !showLogo ? { paddingLeft: 16 } : {},
        onClick
      },
      showLogo && /* @__PURE__ */ import_react.default.createElement(
        Logo,
        {
          logo: currentOrg == null ? void 0 : currentOrg.logo,
          className: "organization-tenant-switcher-switch-logo"
        }
      ),
      /* @__PURE__ */ import_react.default.createElement("div", { className: "organization-tenant-switcher-switch-name", title: currentOrg == null ? void 0 : currentOrg.label }, showName && (currentOrg == null ? void 0 : currentOrg.label)),
      !readOnly && /* @__PURE__ */ import_react.default.createElement(import_ChevronDown.default, { className: "organization-tenant-switcher-switch-chevron" })
    )
  );
};
var organizationTenantSwitcher_default = OrganizationTenantSwitcher;
