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/PisellContactBrief/PisellContactBrief.tsx
var PisellContactBrief_exports = {};
__export(PisellContactBrief_exports, {
  PisellContactBrief: () => PisellContactBrief,
  PisellContactBriefCreateButton: () => PisellContactBriefCreateButton
});
module.exports = __toCommonJS(PisellContactBrief_exports);
var import_react = __toESM(require("react"));
var import_icons = require("@ant-design/icons");
var import_utils = require("@pisell/utils");
var import_pisellEntityCard = require("../pisellEntityCard");
var import_components = require("./components");
var import_locales = __toESM(require("./locales"));
var import_PisellContactBrief = require("./PisellContactBrief.less");
function ensureLocales() {
  var _a, _b;
  try {
    const current = ((_b = (_a = import_utils.locales).getLocale) == null ? void 0 : _b.call(_a)) ?? "en";
    const locale = current === "zh-TW" ? "zh-HK" : current;
    import_utils.locales.init(import_locales.default, locale);
  } catch {
  }
}
function PisellContactBrief({
  name,
  phone,
  email,
  avatar,
  extraData = {},
  extraFields = [],
  onSubmit,
  onDelete,
  swipeToDelete = false,
  layout = "horizontal",
  showAvatar = true,
  showPhone = true,
  showEmail = true,
  primaryLineClamp,
  secondaryLineClamp,
  className,
  style,
  hoverStyle,
  activeStyle,
  disabledStyle,
  clickable = true,
  disabled = false,
  onClick
}) {
  const [editModalVisible, setEditModalVisible] = (0, import_react.useState)(false);
  (0, import_react.useEffect)(() => {
    ensureLocales();
  }, []);
  const media = (0, import_react.useMemo)(() => {
    if (!showAvatar) return void 0;
    return {
      type: "avatar",
      src: avatar,
      alt: name,
      size: 32,
      shape: "circle"
    };
  }, [showAvatar, avatar, name]);
  const secondaryTexts = (0, import_react.useMemo)(() => {
    const list = [];
    if (showEmail && email) list.push({ text: email });
    extraFields.forEach((f) => {
      const v = extraData[f.key];
      if (v) list.push({ text: v });
    });
    return list;
  }, [showEmail, email, extraFields, extraData]);
  const editAction = (0, import_react.useMemo)(
    () => ({
      type: "icon",
      icon: /* @__PURE__ */ import_react.default.createElement(import_icons.EditOutlined, { className: "pisell-contact-brief-action-edit" }),
      onClick: () => {
        setEditModalVisible(true);
      }
    }),
    []
  );
  const initialEditValues = (0, import_react.useMemo)(
    () => ({
      name,
      phone,
      email,
      ...extraData
    }),
    [name, phone, email, extraData]
  );
  const handleEditSubmit = (0, import_react.useCallback)(
    (values) => {
      onSubmit == null ? void 0 : onSubmit(values);
      setEditModalVisible(false);
    },
    [onSubmit]
  );
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-contact-brief-wrap" }, /* @__PURE__ */ import_react.default.createElement(
    import_pisellEntityCard.PisellEntityCard,
    {
      className,
      style,
      hoverStyle,
      activeStyle,
      disabledStyle,
      clickable,
      disabled,
      onClick,
      media,
      primaryText: name,
      subtitleText: showPhone && phone ? phone : void 0,
      secondaryTexts,
      showMedia: showAvatar,
      showPrimaryText: true,
      showSubtitle: showPhone,
      showSecondaryText: true,
      showTags: false,
      showActions: true,
      actions: [editAction],
      density: "B2",
      layout,
      width: "content",
      swipeToDelete,
      onDelete,
      primaryLineClamp,
      secondaryLineClamp
    }
  )), /* @__PURE__ */ import_react.default.createElement(
    import_components.ContactFormModal,
    {
      visible: editModalVisible,
      onCancel: () => setEditModalVisible(false),
      onSubmit: handleEditSubmit,
      mode: "edit",
      initialValues: initialEditValues,
      extraFields
    }
  ));
}
function PisellContactBriefCreateButton({
  extraFields = [],
  onCreate,
  onClick: onClickProp,
  className,
  style
}) {
  const [createModalVisible, setCreateModalVisible] = (0, import_react.useState)(false);
  (0, import_react.useEffect)(() => {
    ensureLocales();
  }, []);
  const handleClick = (0, import_react.useCallback)(
    (e) => {
      if (onClickProp) {
        onClickProp(e);
        return;
      }
      setCreateModalVisible(true);
    },
    [onClickProp]
  );
  const handleCreateSubmit = (0, import_react.useCallback)(
    (values) => {
      onCreate == null ? void 0 : onCreate(values);
      setCreateModalVisible(false);
    },
    [onCreate]
  );
  const addContactText = import_utils.locales.getText("pisell.contact.brief.addContact");
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      role: "button",
      tabIndex: 0,
      className: `pisell-contact-brief-create-btn ${className ?? ""}`.trim(),
      style,
      onClick: handleClick,
      onKeyDown: (e) => {
        if (e.key === "Enter" || e.key === " ") {
          e.preventDefault();
          handleClick(e);
        }
      }
    },
    /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-contact-brief-create-btn-avatar" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-contact-brief-create-btn-avatar-inner" })),
    /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-contact-brief-create-btn-text" }, addContactText),
    /* @__PURE__ */ import_react.default.createElement(import_icons.PlusCircleOutlined, { className: "pisell-contact-brief-create-btn-icon" })
  ), /* @__PURE__ */ import_react.default.createElement(
    import_components.ContactFormModal,
    {
      visible: createModalVisible,
      onCancel: () => setCreateModalVisible(false),
      onSubmit: handleCreateSubmit,
      mode: "create",
      extraFields
    }
  ));
}
PisellContactBrief.CreateButton = PisellContactBriefCreateButton;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PisellContactBrief,
  PisellContactBriefCreateButton
});
