function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
// @ts-nocheck
import React from 'react';
import { formatHourLabel, getBookingDetailData } from "../utils/bookingCalendarDateUtils";
import { tCal } from "../calendarI18n";

/** 拖拽改期后的确认弹窗（Court / 日期 / 起止时间） */
export function MoveConfirmModal(_ref) {
  var _detail$customer, _detail$customer2, _detail$customer3, _courts$find, _courts$find2, _moveDraft$targetHour;
  var moveConfirm = _ref.moveConfirm,
    moveDraft = _ref.moveDraft,
    setMoveDraft = _ref.setMoveDraft,
    panelRef = _ref.panelRef,
    isLight = _ref.isLight,
    courts = _ref.courts,
    visibleCourts = _ref.visibleCourts,
    hourSlots = _ref.hourSlots,
    isBusinessHour = _ref.isBusinessHour,
    firstTimelineHour = _ref.firstTimelineHour,
    endTimelineExclusive = _ref.endTimelineExclusive,
    onConfirm = _ref.onConfirm,
    onClose = _ref.onClose;
  if (!moveConfirm) return null;
  var detail = getBookingDetailData(moveConfirm.item, courts);
  var currentCustomer = {
    name: ((_detail$customer = detail.customer) === null || _detail$customer === void 0 ? void 0 : _detail$customer.name) || detail.headerSummary.customerName,
    phone: ((_detail$customer2 = detail.customer) === null || _detail$customer2 === void 0 ? void 0 : _detail$customer2.phone) || '',
    email: ((_detail$customer3 = detail.customer) === null || _detail$customer3 === void 0 ? void 0 : _detail$customer3.email) || ''
  };
  var originalCourtName = ((_courts$find = courts.find(function (c) {
    return c.id === moveConfirm.item.courtId;
  })) === null || _courts$find === void 0 ? void 0 : _courts$find.name) || detail.headerSummary.resourceLabel || tCal('pisell2.recordBoard.calendar.move.courtFallback');
  var nextCourtName = ((_courts$find2 = courts.find(function (c) {
    return c.id === ((moveDraft === null || moveDraft === void 0 ? void 0 : moveDraft.targetCourtId) || moveConfirm.targetCourtId);
  })) === null || _courts$find2 === void 0 ? void 0 : _courts$find2.name) || tCal('pisell2.recordBoard.calendar.move.courtFallback');
  var originalDate = moveConfirm.item.date;
  var originalStart = formatHourLabel(moveConfirm.item.startHour);
  var originalEnd = formatHourLabel(moveConfirm.item.endHour);
  var nextDate = (moveDraft === null || moveDraft === void 0 ? void 0 : moveDraft.targetDate) || moveConfirm.targetDate;
  var nextStartHour = (_moveDraft$targetHour = moveDraft === null || moveDraft === void 0 ? void 0 : moveDraft.targetHour) !== null && _moveDraft$targetHour !== void 0 ? _moveDraft$targetHour : moveConfirm.targetHour;
  var duration = moveConfirm.item.endHour - moveConfirm.item.startHour;
  var nextEndHour = nextStartHour + duration;
  var changed = originalDate !== nextDate || moveConfirm.item.courtId !== ((moveDraft === null || moveDraft === void 0 ? void 0 : moveDraft.targetCourtId) || moveConfirm.targetCourtId) || moveConfirm.item.startHour !== nextStartHour;
  var isDragScenario = moveConfirm.item.date !== moveConfirm.targetDate || moveConfirm.item.startHour !== moveConfirm.targetHour || moveConfirm.item.courtId !== moveConfirm.targetCourtId;
  var slotDisabledLabel = function slotDisabledLabel(hour) {
    return tCal('pisell2.recordBoard.calendar.move.slotDisabled', {
      time: formatHourLabel(hour)
    });
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "fixed inset-0 z-[72] bg-black/45 backdrop-blur-sm flex items-center justify-center p-4"
  }, /*#__PURE__*/React.createElement("div", {
    ref: panelRef,
    className: "w-full max-w-[980px] rounded-3xl border p-6 shadow-2xl ".concat(isLight ? 'theme-panel theme-border soft-shadow' : 'border-zinc-700 bg-[#121217]')
  }, /*#__PURE__*/React.createElement("div", {
    className: "text-[22px] font-semibold"
  }, tCal('pisell2.recordBoard.calendar.move.title')), /*#__PURE__*/React.createElement("div", {
    className: "mt-2 text-sm ".concat(isLight ? 'theme-text-muted' : 'text-zinc-400')
  }, tCal('pisell2.recordBoard.calendar.move.subtitle')), /*#__PURE__*/React.createElement("div", {
    className: "mt-5 space-y-4"
  }, /*#__PURE__*/React.createElement("div", {
    className: "rounded-3xl border p-5 ".concat(isLight ? 'theme-panel-alt theme-border' : 'border-zinc-700 bg-[#171820]')
  }, /*#__PURE__*/React.createElement("div", {
    className: "min-w-0 flex-1"
  }, /*#__PURE__*/React.createElement("div", {
    className: "text-xs uppercase tracking-[0.14em] ".concat(isLight ? 'theme-text-muted' : 'text-zinc-500')
  }, tCal('pisell2.recordBoard.calendar.move.customer')), /*#__PURE__*/React.createElement("div", {
    className: "mt-3 text-[20px] font-semibold ".concat(isLight ? 'theme-text' : 'text-white')
  }, currentCustomer.name), /*#__PURE__*/React.createElement("div", {
    className: "mt-2 text-sm ".concat(isLight ? 'theme-text-muted' : 'text-zinc-400')
  }, currentCustomer.phone || tCal('pisell2.recordBoard.calendar.move.noPhone')), /*#__PURE__*/React.createElement("div", {
    className: "mt-1 text-sm ".concat(isLight ? 'theme-text-muted' : 'text-zinc-400')
  }, currentCustomer.email || tCal('pisell2.recordBoard.calendar.move.noEmail')))), /*#__PURE__*/React.createElement("div", {
    className: "grid min-w-0 gap-4 md:grid-cols-2"
  }, /*#__PURE__*/React.createElement("div", {
    className: "min-w-0"
  }, /*#__PURE__*/React.createElement("label", {
    className: "mb-2 block text-sm ".concat(isLight ? 'theme-text-muted' : 'text-zinc-400')
  }, tCal('pisell2.recordBoard.calendar.move.court')), /*#__PURE__*/React.createElement("select", {
    value: (moveDraft === null || moveDraft === void 0 ? void 0 : moveDraft.targetCourtId) || moveConfirm.targetCourtId,
    onChange: function onChange(e) {
      return setMoveDraft(function (prev) {
        return _objectSpread(_objectSpread({}, prev || {}), {}, {
          targetCourtId: e.target.value
        });
      });
    },
    className: "min-w-0 w-full rounded-2xl px-4 py-4 outline-none ".concat(isLight ? 'theme-input theme-text' : 'border border-zinc-700 bg-[#171820] text-white')
  }, visibleCourts.map(function (court) {
    return /*#__PURE__*/React.createElement("option", {
      key: court.id,
      value: court.id
    }, court.name);
  }))), /*#__PURE__*/React.createElement("div", {
    className: "min-w-0"
  }, /*#__PURE__*/React.createElement("label", {
    className: "mb-2 block text-sm ".concat(isLight ? 'theme-text-muted' : 'text-zinc-400')
  }, tCal('pisell2.recordBoard.calendar.move.newDate')), /*#__PURE__*/React.createElement("input", {
    type: "date",
    value: (moveDraft === null || moveDraft === void 0 ? void 0 : moveDraft.targetDate) || moveConfirm.targetDate,
    onChange: function onChange(e) {
      return setMoveDraft(function (prev) {
        return _objectSpread(_objectSpread({}, prev || {}), {}, {
          targetDate: e.target.value
        });
      });
    },
    className: "min-w-0 w-full rounded-2xl py-4 pl-4 pr-11 outline-none [color-scheme:dark] [&::-webkit-calendar-picker-indicator]:ml-auto [&::-webkit-calendar-picker-indicator]:mr-1 ".concat(isLight ? 'theme-input theme-text [color-scheme:light]' : 'border border-zinc-700 bg-[#171820] text-white')
  }))), /*#__PURE__*/React.createElement("div", {
    className: "grid min-w-0 gap-4 md:grid-cols-2"
  }, /*#__PURE__*/React.createElement("div", {
    className: "min-w-0"
  }, /*#__PURE__*/React.createElement("label", {
    className: "mb-2 block text-sm ".concat(isLight ? 'theme-text-muted' : 'text-zinc-400')
  }, tCal('pisell2.recordBoard.calendar.move.newStartTime')), /*#__PURE__*/React.createElement("select", {
    value: nextStartHour,
    onChange: function onChange(e) {
      return setMoveDraft(function (prev) {
        return _objectSpread(_objectSpread({}, prev || {}), {}, {
          targetHour: Number(e.target.value)
        });
      });
    },
    className: "min-w-0 w-full rounded-2xl px-4 py-4 outline-none ".concat(isLight ? 'theme-input theme-text' : 'border border-zinc-700 bg-[#171820] text-white')
  }, hourSlots.filter(isBusinessHour).map(function (hour) {
    var disabled = hour + duration > endTimelineExclusive;
    return /*#__PURE__*/React.createElement("option", {
      key: hour,
      value: hour,
      disabled: disabled
    }, disabled ? slotDisabledLabel(hour) : formatHourLabel(hour));
  }))), /*#__PURE__*/React.createElement("div", {
    className: "min-w-0"
  }, /*#__PURE__*/React.createElement("label", {
    className: "mb-2 block text-sm ".concat(isLight ? 'theme-text-muted' : 'text-zinc-400')
  }, tCal('pisell2.recordBoard.calendar.move.newEndTime')), /*#__PURE__*/React.createElement("select", {
    value: nextEndHour,
    onChange: function onChange(e) {
      var nextEnd = Number(e.target.value);
      setMoveDraft(function (prev) {
        return _objectSpread(_objectSpread({}, prev || {}), {}, {
          targetHour: nextEnd - duration
        });
      });
    },
    className: "min-w-0 w-full rounded-2xl px-4 py-4 outline-none ".concat(isLight ? 'theme-input theme-text' : 'border border-zinc-700 bg-[#171820] text-white')
  }, hourSlots.filter(isBusinessHour).map(function (hour) {
    var startHour = hour - duration;
    var disabled = startHour < firstTimelineHour;
    return /*#__PURE__*/React.createElement("option", {
      key: "end-".concat(hour),
      value: hour,
      disabled: disabled
    }, disabled ? slotDisabledLabel(hour) : formatHourLabel(hour));
  })))), changed && /*#__PURE__*/React.createElement("div", {
    className: "rounded-3xl border p-5 ".concat(isLight ? 'theme-panel-alt theme-border' : 'border-zinc-700 bg-[#171820]')
  }, /*#__PURE__*/React.createElement("div", {
    className: "text-xs uppercase tracking-[0.14em] ".concat(isLight ? 'theme-text-muted' : 'text-zinc-500')
  }, tCal('pisell2.recordBoard.calendar.move.previousInfo')), /*#__PURE__*/React.createElement("div", {
    className: "mt-3 grid gap-3 md:grid-cols-2"
  }, /*#__PURE__*/React.createElement("div", {
    className: "rounded-2xl p-4 ".concat(isLight ? 'theme-panel' : 'bg-[#101117]')
  }, /*#__PURE__*/React.createElement("div", {
    className: "text-xs ".concat(isLight ? 'theme-text-muted' : 'text-zinc-500')
  }, tCal('pisell2.recordBoard.calendar.move.original')), /*#__PURE__*/React.createElement("div", {
    className: "mt-2 text-sm ".concat(isLight ? 'theme-text-soft' : 'text-zinc-300')
  }, originalCourtName), /*#__PURE__*/React.createElement("div", {
    className: "mt-1 text-sm ".concat(isLight ? 'theme-text-soft' : 'text-zinc-300')
  }, originalDate), /*#__PURE__*/React.createElement("div", {
    className: "mt-1 text-sm ".concat(isLight ? 'theme-text-soft' : 'text-zinc-300')
  }, originalStart, " - ", originalEnd)), /*#__PURE__*/React.createElement("div", {
    className: "rounded-2xl p-4 ".concat(isLight ? 'theme-brand-surface border border-[var(--brand-light)]' : 'bg-violet-600/10 border border-violet-500/30')
  }, /*#__PURE__*/React.createElement("div", {
    className: "text-xs ".concat(isLight ? 'theme-brand-text' : 'text-violet-300')
  }, isDragScenario ? tCal('pisell2.recordBoard.calendar.move.dropTarget') : tCal('pisell2.recordBoard.calendar.move.updated')), /*#__PURE__*/React.createElement("div", {
    className: "mt-2 text-sm ".concat(isLight ? 'theme-text' : 'text-white')
  }, nextCourtName), /*#__PURE__*/React.createElement("div", {
    className: "mt-1 text-sm ".concat(isLight ? 'theme-text' : 'text-white')
  }, nextDate), /*#__PURE__*/React.createElement("div", {
    className: "mt-1 text-sm ".concat(isLight ? 'theme-text' : 'text-white')
  }, formatHourLabel(nextStartHour), " -", ' ', formatHourLabel(nextEndHour)))))), /*#__PURE__*/React.createElement("div", {
    className: "mt-6 flex justify-end gap-3"
  }, /*#__PURE__*/React.createElement("button", {
    type: "button",
    onClick: onClose,
    className: "rounded-2xl px-5 py-3 ".concat(isLight ? 'btn-neutral' : 'border border-zinc-700 text-zinc-300')
  }, tCal('pisell2.recordBoard.calendar.common.cancel')), /*#__PURE__*/React.createElement("button", {
    type: "button",
    onClick: onConfirm,
    className: "rounded-2xl bg-violet-600 px-6 py-3 font-semibold text-white"
  }, tCal('pisell2.recordBoard.calendar.move.confirm')))));
}