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/ticketBooking/components/bookingDataPanel/bookingList/index.tsx
var bookingList_exports = {};
__export(bookingList_exports, {
  default: () => bookingList_default
});
module.exports = __toCommonJS(bookingList_exports);
var import_materials = require("@pisell/materials");
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_serve = require("../../../serve");
var import_utils2 = require("./utils");
var import_constants = require("../constants");
var import_index = require("./index.less");
var BookingList = (0, import_react.forwardRef)(
  (props, ref) => {
    const { bookingTimeStartBetween, onBookingClick, bookingId } = props;
    const [bookingList, setBookingList] = (0, import_react.useState)([]);
    const [search, setSearch] = (0, import_react.useState)("");
    const [sort, setSort] = (0, import_react.useState)("");
    const [listSelectType, setListSelectType] = (0, import_react.useState)("all");
    const [open, setOpen] = (0, import_react.useState)(false);
    const params = (0, import_react.useMemo)(() => {
      return {
        ["with"]: [
          "order",
          "order.customer",
          "contacts",
          "item",
          "appointmentForm.formRecord",
          "holder.formRecord"
        ],
        /** 创建时间范围 */
        booking_time_start_between: bookingTimeStartBetween,
        child_booking: 1,
        skip: 1,
        num: 1e3
      };
    }, [bookingTimeStartBetween]);
    (0, import_react.useEffect)(() => {
      getBookingList(params);
    }, [params]);
    (0, import_react.useImperativeHandle)(ref, () => ({
      refresh: () => {
        getBookingList(params);
      }
    }));
    const showList = (0, import_react.useMemo)(() => {
      return (0, import_utils2.formatShowList)(bookingList, {
        search,
        listSelectType,
        sort
      });
    }, [bookingList, search, listSelectType, sort]);
    const getBookingList = async (params2) => {
      const res = await (0, import_serve.getBookingList2)(params2);
      setBookingList(res.list);
    };
    const sortProps = (0, import_react.useMemo)(() => {
      return {
        list: [
          {
            label: import_utils.locales.getText("pisell2.ticket-booking.start-time"),
            name: "startDateTime",
            type: "date",
            isCustom: false
          },
          {
            label: import_utils.locales.getText("pisell2.ticket-booking.create-time"),
            name: "created_at",
            type: "date",
            isCustom: false
          },
          {
            label: import_utils.locales.getText("pisell2.ticket-booking.customer"),
            name: "customer",
            type: "string",
            isCustom: false
          },
          {
            label: import_utils.locales.getText("pisell2.ticket-booking.total"),
            name: "total_amount",
            type: "number",
            isCustom: false
          }
        ],
        value: sort,
        onChange: (value) => {
          setSort(value);
        }
      };
    }, [sort]);
    const handleBookingClick = (booking) => {
      if ((0, import_utils2.getBookingType)(booking) === "pisell1") {
        setOpen(true);
        return;
      }
      onBookingClick(booking);
    };
    return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-ticket-booking-list" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-ticket-booking-list-header" }, /* @__PURE__ */ import_react.default.createElement(
      import_materials.Input,
      {
        size: "large",
        placeholder: import_utils.locales.getText("pisell2.ticket-booking.search"),
        value: search,
        onChange: (e) => setSearch(e.target.value)
      }
    ), /* @__PURE__ */ import_react.default.createElement(import_materials.Sort, { ...sortProps })), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-ticket-booking-list-content" }, /* @__PURE__ */ import_react.default.createElement(
      BookingListTable,
      {
        list: showList,
        onBookingClick: handleBookingClick,
        bookingId
      }
    )), /* @__PURE__ */ import_react.default.createElement(
      import_materials.PisellModal.Information,
      {
        title: import_utils.locales.getText("pisell2.ticket-booking.inform"),
        describe: import_utils.locales.getText("pisell2.ticket-booking.check-management"),
        okText: import_utils.locales.getText("pisell2.ticket-booking.confirm"),
        open,
        okVisible: true,
        footerDivider: true,
        closable: true,
        cancelVisible: false,
        onOk: () => {
          setOpen(false);
        },
        onCancel: () => {
          setOpen(false);
        }
      }
    ));
  }
);
var BookingListTable = (0, import_react.memo)(
  (props) => {
    const { list, onBookingClick, bookingId } = props;
    const renderCustomerName = (record) => {
      var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
      const display_name = (((_b = (_a = record == null ? void 0 : record.order) == null ? void 0 : _a.customer) == null ? void 0 : _b.display_name) || "").trim();
      const nickname = (((_d = (_c = record == null ? void 0 : record.order) == null ? void 0 : _c.customer) == null ? void 0 : _d.nickname) || "").trim();
      if (!((_e = record == null ? void 0 : record.order) == null ? void 0 : _e.customer) || [0, 1].includes((_g = (_f = record == null ? void 0 : record.order) == null ? void 0 : _f.customer) == null ? void 0 : _g.id)) {
        return /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-ticket-booking-list-customer-walk-in" }, "Walk-In");
      }
      return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-ticket-booking-list-customer-name" }, display_name || nickname), /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-ticket-booking-list-customer-contact" }, (_i = (_h = record == null ? void 0 : record.order) == null ? void 0 : _h.customer) == null ? void 0 : _i.phone), /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-ticket-booking-list-customer-contact" }, (_k = (_j = record == null ? void 0 : record.order) == null ? void 0 : _j.customer) == null ? void 0 : _k.email));
    };
    const renderPaymentStatus = (record) => {
      var _a, _b;
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: "pisell-ticket-booking-list-payment-status",
          style: {
            backgroundColor: import_constants.payStatusColorMap[(_a = record.order) == null ? void 0 : _a.payment_status]
          }
        },
        (0, import_constants.getPayStatusMap)()[(_b = record.order) == null ? void 0 : _b.payment_status]
      );
    };
    return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-ticket-booking-list-table" }, !list.length ? /* @__PURE__ */ import_react.default.createElement(import_materials.PisellEmpty, null) : list.map((item) => {
      var _a, _b;
      const isActive = bookingId === item.order.id;
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          key: item.id,
          className: "pisell-ticket-booking-list-table-item",
          onClick: () => onBookingClick(item),
          style: {
            backgroundColor: isActive ? "#fff" : "rgba(255, 255, 255, 0.07)",
            zIndex: isActive ? 10 : 1,
            color: isActive ? "#000" : "#fff"
          }
        },
        /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-ticket-booking-list-table-item-left" }, /* @__PURE__ */ import_react.default.createElement("div", null, item.start_time), /* @__PURE__ */ import_react.default.createElement("div", null, renderCustomerName(item))),
        /* @__PURE__ */ import_react.default.createElement("div", null, renderPaymentStatus(item)),
        /* @__PURE__ */ import_react.default.createElement("div", null, `${((_a = item == null ? void 0 : item.order) == null ? void 0 : _a.currency_symbol) || "-"}${((_b = item == null ? void 0 : item.order) == null ? void 0 : _b.total_amount) || "0.00"}`)
      );
    }));
  }
);
var bookingList_default = BookingList;
