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/plus/saleDetail/components/LineItem/components/BookingHeader.tsx
var BookingHeader_exports = {};
__export(BookingHeader_exports, {
  default: () => BookingHeader_default
});
module.exports = __toCommonJS(BookingHeader_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_icons = require("@ant-design/icons");
var import_materials = require("@pisell/materials");
var import_constants = require("../constants");
var import_render = require("../utils/render");
var getStatusOption = (status, statusOptions = []) => {
  return statusOptions.find((option) => option.key === status) || statusOptions[0] || {
    key: status || "",
    label: status || "-",
    color: import_constants.DEFAULT_STATUS_COLOR
  };
};
var getReadableTextColor = (color) => {
  if (!color) return void 0;
  const normalizedColor = color.trim();
  const hex = normalizedColor.length === 4 ? normalizedColor.replace(
    /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i,
    "#$1$1$2$2$3$3"
  ) : normalizedColor;
  const match = /^#([0-9a-f]{6})$/i.exec(hex);
  if (!match) return void 0;
  const red = Number.parseInt(match[1].slice(0, 2), 16);
  const green = Number.parseInt(match[1].slice(2, 4), 16);
  const blue = Number.parseInt(match[1].slice(4, 6), 16);
  const luminance = (red * 299 + green * 587 + blue * 114) / 1e3;
  return luminance > 150 ? "#101828" : "#ffffff";
};
var BookingHeader = ({
  booking,
  source,
  statusOptions = [],
  statusLoading,
  statusDisabled,
  isShowDelete,
  onBookingStatusChange,
  onDelete
}) => {
  const currentStatus = getStatusOption(booking.status, statusOptions);
  const headerTextColor = getReadableTextColor(currentStatus.color);
  const statusMenuItems = statusOptions.filter((option) => option.key !== currentStatus.key).map((option) => ({
    key: option.key,
    label: option.label,
    danger: option.danger
  }));
  const canChangeStatus = Boolean(
    onBookingStatusChange && !statusDisabled && !statusLoading && (statusMenuItems == null ? void 0 : statusMenuItems.length)
  );
  const statusButton = /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      className: `${import_constants.PREFIX}__status`,
      type: "button",
      disabled: !canChangeStatus,
      onClick: import_render.stopPropagation
    },
    /* @__PURE__ */ import_react.default.createElement("span", null, currentStatus.label),
    canChangeStatus ? /* @__PURE__ */ import_react.default.createElement(import_icons.DownOutlined, null) : null
  );
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `${import_constants.PREFIX}__booking-header`,
      style: {
        "--pisell-line-item-booking-accent": currentStatus.color || import_constants.DEFAULT_STATUS_COLOR,
        "--pisell-line-item-booking-bg": currentStatus.color || import_constants.DEFAULT_STATUS_COLOR,
        "--pisell-line-item-booking-text": headerTextColor || "var(--pisell-line-item-header-text)",
        "--pisell-line-item-booking-sub-text": headerTextColor ? `${headerTextColor}cc` : "var(--pisell-line-item-header-sub-text)"
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__booking-header-main` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__booking-headline` }, booking.bookingId ? /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_constants.PREFIX}__booking-id` }, booking.bookingId) : null, booking.timeText ? /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_constants.PREFIX}__booking-time` }, booking.timeText) : null), /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__booking-header-actions` }, canChangeStatus ? /* @__PURE__ */ import_react.default.createElement(
      import_antd.Dropdown,
      {
        menu: {
          items: statusMenuItems,
          onClick: ({ key }) => onBookingStatusChange == null ? void 0 : onBookingStatusChange(String(key), source)
        },
        trigger: ["click"]
      },
      statusButton
    ) : statusButton, isShowDelete ? /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        className: `${import_constants.PREFIX}__header-delete`,
        type: "button",
        onClick: (event) => {
          (0, import_render.stopPropagation)(event);
          onDelete == null ? void 0 : onDelete(source);
        }
      },
      /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-trash-01" })
    ) : null)),
    booking.title ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__booking-title` }, booking.title) : null
  );
};
var BookingHeader_default = BookingHeader;
