(function () {
  "use strict";

  var h = React.createElement;
  var useState = React.useState;
  var useEffect = React.useEffect;
  var useRef = React.useRef;
  var useCallback = React.useCallback;

  var C = {
    bg: "#F7F7F8", surface: "#FFFFFF", blue: "#002FA7", blueSoft: "#EEF3FF",
    text: "#111827", secondary: "#667085", muted: "#98A2B3", line: "#E4E7EC",
    danger: "#D92D20", abnormal: "#98A2B3"
  };
  var STATUS_TEXT = {
    20: "等待打手接单", 30: "打手已接单，等待开启服务", 40: "服务进行中",
    60: "打手已完成服务，等待确认", 70: "交易完成", 90: "退款申请中", 91: "退款处理中",
    100: "售后处理中", 110: "已退款", 120: "已取消", 130: "订单已冻结"
  };
  var ABNORMAL_STATUS = { 90: true, 91: true, 100: true, 110: true, 120: true, 130: true };

  function icon(path, size) {
    return h("svg", { width:size || 20, height:size || 20, viewBox:"0 0 24 24", fill:"none", stroke:"currentColor", strokeWidth:1.8, strokeLinecap:"round", strokeLinejoin:"round", "aria-hidden":"true" },
      Array.isArray(path) ? path.map(function(d, i) { return h("path", { key:i, d:d }); }) : h("path", { d:path })
    );
  }
  function pad2(value) { return String(value).padStart(2, "0"); }
  function parseTimeMs(value) {
    if (!value) return NaN;
    if (value instanceof Date) return value.getTime();
    if (typeof value === "number") return value;
    var text = String(value).trim();
    if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?$/.test(text)) {
      text = text.replace(" ", "T");
    }
    return new Date(text).getTime();
  }
  function formatTime(value) {
    if (!value) return "--";
    var timeMs = parseTimeMs(value);
    if (isNaN(timeMs)) return "--";
    var date = new Date(timeMs);
    return date.getFullYear() + "-" + pad2(date.getMonth() + 1) + "-" + pad2(date.getDate()) + " " + pad2(date.getHours()) + ":" + pad2(date.getMinutes());
  }
  function formatMoney(value) {
    var amount = Number(value || 0);
    return "¥" + (Number.isFinite(amount) ? amount : 0).toFixed(2);
  }
  function formatRemaining(value) {
    var seconds = Math.max(0, Number(value || 0));
    var hours = Math.floor(seconds / 3600);
    var minutes = Math.floor((seconds % 3600) / 60);
    var secs = Math.floor(seconds % 60);
    return pad2(hours) + ":" + pad2(minutes) + ":" + pad2(secs);
  }
  function normalizeDetail(payload) {
    payload = payload || {};
    var order = payload.order && typeof payload.order === "object" ? payload.order : {};
    return Object.assign({}, order, payload, { order:null });
  }

  function EscortOrderDetailPage() {
    var params = NK.Store.get("pageParams") || {};
    var orderId = Number(params.orderId || params.id || 0);
    var initialRole = params.role === "booster" ? "booster" : "buyer";
    var _order = useState(null), order = _order[0], setOrder = _order[1];
    var _loading = useState(true), loading = _loading[0], setLoading = _loading[1];
    var _error = useState(""), error = _error[0], setError = _error[1];
    var _remaining = useState(null), remaining = _remaining[0], setRemaining = _remaining[1];
    var _submitting = useState(""), submitting = _submitting[0], setSubmitting = _submitting[1];
    var _files = useState([]), files = _files[0], setFiles = _files[1];
    var _showUpload = useState(false), showUpload = _showUpload[0], setShowUpload = _showUpload[1];
    var _coverFailed = useState(false), coverFailed = _coverFailed[0], setCoverFailed = _coverFailed[1];
    var _chatConnecting = useState(false), chatConnecting = _chatConnecting[0], setChatConnecting = _chatConnecting[1];
    var _cancelConfirmVisible = useState(false), cancelConfirmVisible = _cancelConfirmVisible[0], setCancelConfirmVisible = _cancelConfirmVisible[1];
    var countdownRef = useRef({ remaining:null, clientAt:0, paused:false });
    var requestRef = useRef(0);
    var zeroRefreshRef = useRef(false);
    var supportNavigationRef = useRef(false);

    var applyCountdown = function(detail) {
      var raw = detail.remainingSeconds;
      var seconds = raw === null || raw === undefined ? null : Number(raw);
      if ((seconds === null || !Number.isFinite(seconds)) && detail.buyerConfirmDeadlineAt) {
        var serverMs = detail.serverNow ? parseTimeMs(detail.serverNow) : Date.now();
        var deadlineMs = parseTimeMs(detail.buyerConfirmDeadlineAt);
        if (!isNaN(serverMs) && !isNaN(deadlineMs)) seconds = Math.max(0, Math.floor((deadlineMs - serverMs) / 1000));
      }
      if (seconds !== null && !Number.isFinite(seconds)) seconds = null;
      countdownRef.current = { remaining:seconds, clientAt:Date.now(), paused:!!detail.countdownPaused };
      if (seconds === null || seconds > 0) zeroRefreshRef.current = false;
      setRemaining(seconds);
    };

    var loadDetail = useCallback(function(silent) {
      if (!orderId) { setLoading(false); setError("订单参数无效，请返回后重试"); return Promise.resolve(); }
      var seq = ++requestRef.current;
      if (!silent) setLoading(true);
      return NK.Api.Escort.orderDetail(orderId).then(function(res) {
        if (seq !== requestRef.current) return;
        if (!res || res.code !== 0 || !res.data) throw new Error("订单加载失败，请稍后重试");
        var detail = normalizeDetail(res.data);
        setOrder(detail); setError(""); applyCountdown(detail);
      }).catch(function() {
        if (seq === requestRef.current && !order) setError("订单加载失败，请稍后重试");
      }).finally(function() { if (seq === requestRef.current) setLoading(false); });
    }, [orderId]);

    useEffect(function() { loadDetail(false); }, [loadDetail]);
    useEffect(function() {
      if (!orderId || !window.history || typeof window.history.replaceState !== "function") return;
      var originalUrl = window.location.pathname + window.location.search + window.location.hash;
      var routeParams = new URLSearchParams(window.location.search || "");
      var cleanupUrl = originalUrl;
      if (routeParams.get("page") === "escortOrderDetail") {
        var cleanupParams = new URLSearchParams(routeParams.toString());
        cleanupParams.delete("page"); cleanupParams.delete("orderId"); cleanupParams.delete("role");
        cleanupUrl = window.location.pathname + (cleanupParams.toString() ? "?" + cleanupParams.toString() : "") + window.location.hash;
      }
      routeParams.set("page", "escortOrderDetail");
      routeParams.set("orderId", String(orderId));
      routeParams.set("role", initialRole);
      window.history.replaceState(null, "", window.location.pathname + "?" + routeParams.toString());
      return function() { window.history.replaceState(null, "", cleanupUrl); };
    }, [orderId, initialRole]);
    useEffect(function() {
      var refreshTimer = setInterval(function() { loadDetail(true); }, 30000);
      var onVisible = function() { if (document.visibilityState === "visible") loadDetail(true); };
      document.addEventListener("visibilitychange", onVisible);
      window.addEventListener("focus", onVisible);
      return function() { clearInterval(refreshTimer); document.removeEventListener("visibilitychange", onVisible); window.removeEventListener("focus", onVisible); };
    }, [loadDetail]);
    useEffect(function() {
      if (typeof NK.UserImSocket === "undefined") return;
      var timer = null;
      var off = NK.UserImSocket.on("escort:order_updated", function(payload) {
        if (Number(payload && payload.order_id || 0) !== orderId) return;
        if (timer) clearTimeout(timer);
        timer = setTimeout(function() { timer = null; loadDetail(true); }, 180);
      });
      return function() {
        if (timer) clearTimeout(timer);
        if (typeof off === "function") off();
      };
    }, [orderId, loadDetail]);
    useEffect(function() {
      var timer = setInterval(function() {
        var anchor = countdownRef.current;
        if (anchor.remaining === null || anchor.paused) return;
        var next = Math.max(0, anchor.remaining - Math.floor((Date.now() - anchor.clientAt) / 1000));
        setRemaining(next);
        if (next === 0 && !zeroRefreshRef.current) {
          zeroRefreshRef.current = true;
          loadDetail(true);
        }
      }, 1000);
      return function() { clearInterval(timer); };
    }, [loadDetail]);

    var status = Number(order && order.status || 0);
    var role = order && order.currentRole === "booster" ? "booster" : order && order.currentRole === "buyer" ? "buyer" : initialRole;
    var isAbnormal = !!(order && (order.countdownPaused || ABNORMAL_STATUS[status]));
    var canStart = !!(order && order.canStart && !isAbnormal && role === "buyer");
    var canBuyerComplete = !!(order && order.canBuyerComplete && !isAbnormal && role === "buyer" && Number(remaining || 0) > 0);
    var canBoosterComplete = !!(order && order.canBoosterComplete && !isAbnormal && role === "booster");
    var hasBooster = !!(order && Number(order.boosterUserId || order.booster_user_id || 0) > 0);
    var serviceStartedAt = order && (order.serviceStartedAt || order.service_started_at);
    var canDirectCancel = !!(order && !isAbnormal && role === "buyer" && (status === 20 || status === 30) && !serviceStartedAt);

    function goBack() { NK.Store.back(role === "booster" ? "boosterCenter" : "orders"); }
    function openChat() {
      if (chatConnecting) return;
      if (!hasBooster) {
        alert("暂未有打手接单");
        return;
      }
      setChatConnecting(true);
      NK.Api.Im.escortOrderConversation({ order_id:orderId }).then(function(res) {
        var data = res && res.data || {};
        var conversationId = Number(data.conversation_id || data.id || 0);
        if (!res || res.code !== 0 || !conversationId || isNaN(conversationId)) {
          throw new Error((res && res.message) || "订单会话连接失败");
        }
        var next = { orderId:orderId, role:role, conversationId:conversationId, conversationData:data, source:"escortOrderDetail" };
        if (NK.Store.openNativePage && NK.Store.openNativePage("pages/escort/order-chat", next)) return;
        NK.Store.navigate("escortOrderChat", next);
      }).catch(function(err) {
        alert((err && err.message) || "订单会话连接失败，请稍后重试");
      }).finally(function() {
        setChatConnecting(false);
      });
    }
    function openSupport(consultationType) {
      if (supportNavigationRef.current) return;
      supportNavigationRef.current = true;
      try {
        NK.Store.navigate("supportChat", {
          orderId:orderId,
          role:role,
          source:"escort_order",
          serviceType:"aftersale",
          consultationType:consultationType === "escort_cancel" ? "escort_cancel" : "order_support"
        });
      } finally {
        window.setTimeout(function() { supportNavigationRef.current = false; }, 800);
      }
    }
    function showCancelConfirm() {
      if (submitting || !canDirectCancel) return;
      setCancelConfirmVisible(true);
    }
    function closeCancelConfirm() {
      if (!submitting) setCancelConfirmVisible(false);
    }
    function confirmCancelOrder() {
      if (submitting || !canDirectCancel) return;
      setCancelConfirmVisible(false);
      openSupport("escort_cancel");
    }
    function openProduct() {
      if (!order || !order.serviceId) { alert("商品信息缺失，暂时无法查看"); return; }
      if (order.serviceAvailable === false) { alert("该服务已下架"); return; }
      NK.Store.navigate("escortDetail", { id:order.serviceId, source:"escortOrderDetail" });
    }
    function mutate(kind, question, request, successText) {
      if (submitting || !confirm(question)) return;
      setSubmitting(kind);
      request().then(function(res) {
        if (!res || res.code !== 0) throw new Error((res && res.message) || "操作失败");
        return loadDetail(true).then(function() { alert(successText); });
      }).catch(function(err) { alert((err && err.message) || "操作失败，请稍后重试"); })
        .finally(function() { setSubmitting(""); });
    }
    function startService() {
      mutate("start", "确认现在开始护航服务吗？", function() { return NK.Api.Escort.startOrder(orderId); }, "护航服务已开始");
    }
    function confirmComplete() {
      mutate("complete", "确认打手已完成本次服务吗？确认后订单将完成并进入结算。", function() { return NK.Api.Escort.completeOrder(orderId, {}); }, "订单已确认完成");
    }
    function chooseFiles(event) {
      var selected = Array.prototype.slice.call(event.target.files || []);
      event.target.value = "";
      if (!selected.length) return;
      for (var i = 0; i < selected.length; i++) {
        if (!/^image\//i.test(selected[i].type || "")) { alert("请选择图片格式的服务凭证"); return; }
        if (selected[i].size > 5 * 1024 * 1024) { alert("单张图片不能超过5MB"); return; }
      }
      setFiles(selected.slice(0, 5));
      if (selected.length > 5) alert("最多选择5张图片");
    }
    function submitBoosterComplete() {
      if (submitting) return;
      if (!files.length) { alert("请先上传服务完成截图"); return; }
      if (!confirm("确认提交服务完成凭证吗？提交后将等待买家确认。")) return;
      setSubmitting("boosterComplete");
      Promise.all(files.map(function(file) {
        return NK.Api.Upload.image(file).then(function(res) {
          var url = res && res.data && (res.data.url || res.data.path);
          if (!res || res.code !== 0 || !url) throw new Error((res && res.message) || "图片上传失败");
          return url;
        });
      })).then(function(urls) { return NK.Api.Escort.boosterCompleteOrder(orderId, { screenshotUrls:urls }); })
        .then(function(res) {
          if (!res || res.code !== 0) throw new Error((res && res.message) || "提交失败");
          setShowUpload(false); setFiles([]);
          return loadDetail(true).then(function() { alert("服务完成凭证已提交"); });
        }).catch(function(err) { alert((err && err.message) || "提交失败，请稍后重试"); })
        .finally(function() { setSubmitting(""); });
    }

    function progressStage() {
      if (status === 70) return 3;
      if (status === 40 || status === 60) return 2;
      return 1;
    }
    function renderProgress() {
      var current = progressStage();
      var steps = ["已付款", "服务中", "交易完成"];
      return h("div", { style:{ display:"grid", gridTemplateColumns:"1fr 1fr 1fr", padding:"22px 20px 20px", background:C.surface, borderBottom:"1px solid " + C.line } },
        steps.map(function(label, index) {
          var step = index + 1;
          var active = step <= current;
          var tone = isAbnormal ? C.abnormal : active ? C.blue : C.line;
          return h("div", { key:label, style:{ position:"relative", textAlign:"center", color:isAbnormal ? C.muted : active ? C.text : C.muted } },
            index > 0 ? h("span", { style:{ position:"absolute", height:1, background:tone, left:"-50%", right:"50%", top:14 } }) : null,
            h("span", { style:{ position:"relative", zIndex:1, margin:"0 auto 8px", width:28, height:28, borderRadius:"50%", display:"flex", alignItems:"center", justifyContent:"center", boxSizing:"border-box", border:"1px solid " + tone, background:active && !isAbnormal ? C.blue : C.surface, color:active && !isAbnormal ? "#FFFFFF" : tone, fontSize:11, fontWeight:700, fontVariantNumeric:"tabular-nums" } }, "0" + step),
            h("div", { style:{ position:"relative", zIndex:1, fontSize:12, fontWeight:active ? 600 : 400 } }, label)
          );
        })
      );
    }
    function copyText(value) {
      var text = String(value || "");
      if (!text) return;
      var fallbackCopy = function() {
        var textarea = document.createElement("textarea");
        textarea.value = text;
        textarea.setAttribute("readonly", "readonly");
        textarea.style.position = "fixed";
        textarea.style.opacity = "0";
        document.body.appendChild(textarea);
        textarea.select();
        try { document.execCommand("copy"); alert("订单编号已复制"); }
        catch (err) { alert("复制失败，请长按订单编号复制"); }
        document.body.removeChild(textarea);
      };
      if (navigator.clipboard && window.isSecureContext) {
        navigator.clipboard.writeText(text).then(function() { alert("订单编号已复制"); }).catch(fallbackCopy);
      } else {
        fallbackCopy();
      }
    }
    function row(label, value, action) {
      return h("div", { style:{ display:"flex", justifyContent:"space-between", gap:20, padding:"13px 0", borderBottom:"1px solid " + C.line, fontSize:13 } },
        h("span", { style:{ color:C.secondary, flexShrink:0 } }, label),
        h("span", { style:{ color:C.text, textAlign:"right", wordBreak:"break-all", display:"flex", alignItems:"center", justifyContent:"flex-end", gap:8 } },
          h("span", null, value || "--"),
          action ? h("button", { onClick:action, style:{ border:"1px solid " + C.line, background:C.surface, color:C.blue, padding:"3px 7px", fontSize:11, cursor:"pointer", flexShrink:0 } }, "复制") : null
        )
      );
    }

    if (loading && !order) {
      return h("div", { style:{ minHeight:"100vh", background:C.bg, display:"flex", alignItems:"center", justifyContent:"center", color:C.secondary, fontFamily:"-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif" } }, "订单加载中...");
    }
    if (!order) {
      return h("div", { style:{ minHeight:"100vh", background:C.bg, fontFamily:"-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif" } },
        h("header", { style:{ height:48, display:"flex", alignItems:"center", background:C.surface, borderBottom:"1px solid " + C.line, padding:"0 12px" } },
          h("button", { onClick:goBack, style:{ border:0, background:"transparent", color:C.text, padding:8, display:"flex" }, "aria-label":"返回" }, icon("m15 18-6-6 6-6", 22)),
          h("strong", { style:{ fontSize:16 } }, "护航订单详情")
        ),
        h("div", { style:{ padding:"96px 24px", textAlign:"center" } },
          h("div", { style:{ color:C.secondary, fontSize:14, marginBottom:18 } }, error || "订单不存在"),
          h("button", { onClick:function() { loadDetail(false); }, style:{ border:0, background:C.blue, color:"#fff", padding:"10px 24px", fontSize:14 } }, "重新加载")
        )
      );
    }

    var title = order.serviceTitle || order.serviceName || "护航服务";
    var rawRemark = order.remark !== null && order.remark !== undefined ? order.remark : order.buyerRemark;
    var remarkText = String(rawRemark || "").trim() || "无";
    var placeholderCover = "/images/escort-placeholder.svg";
    var cover = coverFailed ? placeholderCover : (order.coverImage || placeholderCover);
    var statusText = order.statusText || STATUS_TEXT[status] || ("状态" + status);
    var statusNote = status === 20 ? "订单已付款，平台正在等待打手接单" :
      status === 30 ? "仅买家可以开启本次护航服务" :
      status === 40 ? "打手完成服务后将提交服务凭证" :
      status === 60 ? (order.countdownPaused ? "订单处于异常处理中，确认倒计时已暂停" : "打手已提交服务完成，等待买家确认") :
      status === 70 ? "订单已完成，服务款项已按平台规则结算" :
      status === 130 ? "订单已冻结，当前无法继续服务或确认完成" : statusText;
    if (isAbnormal && order.statusDescription) statusNote = order.statusDescription;
    var countdownText = null;
    if (order.countdownPaused && remaining !== null) {
      countdownText = "确认倒计时已暂停 · 剩余 " + formatRemaining(remaining);
    } else if (status === 60 && remaining !== null) {
      countdownText = remaining > 0 ? "买家确认剩余 " + formatRemaining(remaining) : "等待系统完成，请稍后刷新";
    } else if (status === 60 && !order.buyerConfirmDeadlineAt) {
      countdownText = "等待买家确认";
    }
    var primary = canStart ? { label:submitting === "start" ? "开启中..." : "开始服务", onClick:startService } :
      canBuyerComplete ? { label:submitting === "complete" ? "确认中..." : "服务完成", onClick:confirmComplete } :
      canBoosterComplete ? { label:"提交服务完成", onClick:function() { setShowUpload(true); } } : null;
    var buyerWaitingMatch = role === "buyer" && !isAbnormal && status === 20;
    var buyerWaitingStart = role === "buyer" && !isAbnormal && status === 30;
    var footerButtonBase = { flex:1, minWidth:0, height:46, display:"flex", alignItems:"center", justifyContent:"center", boxSizing:"border-box", whiteSpace:"nowrap", fontSize:12, fontWeight:600 };
    var footerSecondary = Object.assign({}, footerButtonBase, { border:"1px solid " + C.line, background:C.surface, color:C.secondary, cursor:"pointer" });
    var footerDanger = Object.assign({}, footerButtonBase, { border:"1px solid #FDA29B", background:C.surface, color:C.danger, cursor:"pointer" });
    var footerPrimary = Object.assign({}, footerButtonBase, { border:0, background:submitting ? "#8CA3D8" : C.blue, color:"#fff", fontSize:14, fontWeight:700, cursor:submitting ? "not-allowed" : "pointer" });
    var footerDisabled = Object.assign({}, footerButtonBase, { border:0, background:C.bg, color:C.secondary });
    var footerActions = buyerWaitingMatch ? [
      h("button", { key:"support", onClick:function() { openSupport("order_support"); }, disabled:!!submitting, style:footerSecondary }, "联系客服"),
      canDirectCancel ? h("button", { key:"cancel", onClick:showCancelConfirm, style:footerDanger }, "取消订单") : null,
      h("div", { key:"waiting", "aria-disabled":"true", style:footerDisabled }, "等待打手接单")
    ] : buyerWaitingStart ? [
      h("button", { key:"chat", onClick:openChat, disabled:chatConnecting || !hasBooster, style:Object.assign({}, footerSecondary, { color:chatConnecting || !hasBooster ? C.muted : C.secondary, background:hasBooster ? C.surface : C.bg, cursor:chatConnecting || !hasBooster ? "not-allowed" : "pointer" }) }, chatConnecting ? "连接中" : "联系打手"),
      canDirectCancel ? h("button", { key:"cancel", onClick:showCancelConfirm, style:footerDanger }, "取消订单") : null,
      h("button", { key:"start", onClick:startService, disabled:!!submitting || !canStart, style:Object.assign({}, footerPrimary, { background:submitting || !canStart ? "#8CA3D8" : C.blue }) }, submitting === "start" ? "开启中..." : "开始服务")
    ] : [
      h("button", { key:"support", onClick:function() { openSupport("order_support"); }, disabled:!!submitting, style:footerSecondary }, "联系客服"),
      hasBooster ? h("button", { key:"chat", onClick:openChat, disabled:chatConnecting, style:Object.assign({}, footerSecondary, { color:chatConnecting ? C.muted : C.secondary, cursor:chatConnecting ? "not-allowed" : "pointer" }) }, chatConnecting ? "连接中" : role === "booster" ? "联系买家" : "联系打手") : null,
      primary
        ? h("button", { key:"primary", onClick:primary.onClick, disabled:!!submitting, style:footerPrimary }, primary.label)
        : null
    ];
    footerActions = footerActions.filter(Boolean);

    return h("div", { style:{ minHeight:"100vh", background:C.bg, color:C.text, fontFamily:"-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif", paddingBottom:"calc(84px + env(safe-area-inset-bottom, 0px))" } },
      h("header", { style:{ position:"sticky", top:0, zIndex:20, height:48, display:"grid", gridTemplateColumns:"44px 1fr 44px", alignItems:"center", background:C.surface, borderBottom:"1px solid " + C.line } },
        h("button", { onClick:goBack, style:{ border:0, background:"transparent", color:C.text, padding:10, display:"flex", cursor:"pointer" }, "aria-label":"返回" }, icon("m15 18-6-6 6-6", 22)),
        h("strong", { style:{ fontSize:16, textAlign:"center", fontWeight:650 } }, "护航订单详情"), h("span", null)
      ),
      h("main", { style:{ maxWidth:500, margin:"0 auto" } },
        h("section", { style:{ padding:"24px 20px 20px", background:C.surface, borderBottom:"1px solid " + C.line } },
          h("div", { style:{ display:"flex", justifyContent:"space-between", alignItems:"flex-start", gap:14 } },
            h("div", { style:{ flex:1, minWidth:0 } },
              h("div", { style:{ fontSize:22, lineHeight:1.25, fontWeight:750, color:isAbnormal ? C.secondary : C.text, marginBottom:8 } }, statusText),
              h("div", { style:{ color:C.secondary, fontSize:13, lineHeight:1.55 } }, statusNote)
            ),
            role === "buyer"
              ? h("img", {
                src:"/images/escort-buyer-figure.png",
                alt:"",
                "aria-hidden":"true",
                style:{ width:"min(100px, 27vw)", height:"auto", maxHeight:125, aspectRatio:"453 / 560", objectFit:"contain", flexShrink:0, alignSelf:"flex-end", margin:"-18px 12px -22px 0", opacity:isAbnormal ? 0.72 : 1 }
              })
              : h("span", { style:{ flexShrink:0, fontSize:11, color:isAbnormal ? C.secondary : C.blue, border:"1px solid " + (isAbnormal ? C.line : C.blue), padding:"4px 8px" } }, "打手端")
          ),
          countdownText ? h("div", { style:{ marginTop:16, padding:"11px 12px", background:isAbnormal ? C.bg : C.blueSoft, borderLeft:"3px solid " + (isAbnormal ? C.abnormal : C.blue), color:isAbnormal ? C.secondary : C.blue, fontSize:14, fontWeight:700, fontVariantNumeric:"tabular-nums" } }, countdownText) : null
        ),
        renderProgress(),
        h("section", { style:{ marginTop:12, background:C.surface, borderTop:"1px solid " + C.line, borderBottom:"1px solid " + C.line } },
          h("div", { style:{ padding:"15px 16px 11px", fontSize:14, fontWeight:700 } }, "服务商品"),
          h("button", { onClick:openProduct, style:{ width:"100%", display:"flex", gap:12, alignItems:"center", padding:"4px 16px 16px", border:0, background:"transparent", textAlign:"left", color:C.text, cursor:"pointer" } },
            h("img", { src:cover, alt:"护航服务商品封面", onError:function() { if (cover !== placeholderCover) setCoverFailed(true); }, style:{ width:76, height:76, objectFit:"cover", flexShrink:0, border:"1px solid " + C.line, background:C.bg } }),
            h("div", { style:{ flex:1, minWidth:0 } },
              h("div", { style:{ fontSize:15, fontWeight:700, lineHeight:1.45, marginBottom:6, overflow:"hidden", textOverflow:"ellipsis", display:"-webkit-box", WebkitLineClamp:2, WebkitBoxOrient:"vertical" } }, title),
              h("div", { style:{ color:C.secondary, fontSize:12, lineHeight:1.7 } },
                order.specName ? h("div", null, "规格：" + order.specName) : null,
                order.gameServer ? h("div", null, "区服：" + order.gameServer) : null,
                h("div", { style:{ display:"-webkit-box", overflow:"hidden", textOverflow:"ellipsis", WebkitLineClamp:2, WebkitBoxOrient:"vertical", lineHeight:1.5 } }, "备注：" + remarkText)
              ),
              order.serviceAvailable === false ? h("div", { style:{ color:C.danger, fontSize:12, marginTop:3 } }, "该服务已下架") : null
            ),
            h("span", { style:{ color:C.muted, display:"flex", flexShrink:0 } }, icon("m9 18 6-6-6-6", 18))
          ),
          h("div", { style:{ margin:"0 16px", padding:"13px 0", borderTop:"1px solid " + C.line, display:"flex", justifyContent:"space-between", alignItems:"baseline" } },
            h("span", { style:{ color:C.secondary, fontSize:13 } }, "实付款"),
            h("strong", { style:{ color:C.blue, fontSize:20, fontVariantNumeric:"tabular-nums" } }, formatMoney(order.amount))
          )
        ),
        h("section", { style:{ marginTop:12, padding:"0 16px", background:C.surface, borderTop:"1px solid " + C.line, borderBottom:"1px solid " + C.line } },
          h("div", { style:{ padding:"15px 0 6px", fontSize:14, fontWeight:700 } }, "订单信息"),
          row("订单编号", order.orderNo || String(order.id || orderId), function() { copyText(order.orderNo || String(order.id || orderId)); }),
          row("商品单价", order.unitPrice === null || order.unitPrice === undefined ? "--" : formatMoney(order.unitPrice)),
          row("接单打手", order.boosterName || order.boosterNickname || (status === 20 ? "等待接单" : "--")),
          row("付款时间", formatTime(order.paidAt)),
          row("开启时间", formatTime(order.serviceStartedAt)),
          row("成交时间", formatTime(order.completedAt))
        ),
        order.boosterCompletedAt ? h("section", { style:{ marginTop:12, padding:"14px 16px", background:C.surface, borderTop:"1px solid " + C.line, borderBottom:"1px solid " + C.line, display:"flex", justifyContent:"space-between", gap:16, fontSize:13 } },
          h("span", { style:{ color:C.secondary } }, "打手提交时间"), h("span", null, formatTime(order.boosterCompletedAt))
        ) : null
      ),
      h("div", { style:{ position:"fixed", left:0, right:0, bottom:0, zIndex:30, maxWidth:500, margin:"0 auto", display:"flex", gap:10, alignItems:"center", padding:"10px 12px calc(10px + env(safe-area-inset-bottom, 0px))", background:C.surface, borderTop:"1px solid " + C.line, boxSizing:"border-box" } },
        h("div", { style:{ flex:1, minWidth:0, display:"flex", gap:8, justifyContent:"flex-end" } }, footerActions)
      ),
      cancelConfirmVisible ? h("div", {
        onClick:function(event) { if (event.target === event.currentTarget) closeCancelConfirm(); },
        style:{ position:"fixed", inset:0, zIndex:90, background:"rgba(17,24,39,.48)", display:"flex", alignItems:"center", justifyContent:"center", padding:24, boxSizing:"border-box" }
      },
        h("div", { role:"dialog", "aria-modal":"true", "aria-labelledby":"escort-cancel-title", style:{ width:"100%", maxWidth:360, background:C.surface, borderRadius:18, border:"1px solid " + C.line, padding:"24px 20px 18px", boxSizing:"border-box", boxShadow:"0 18px 48px rgba(17,24,39,.18)" } },
          h("strong", { id:"escort-cancel-title", style:{ display:"block", fontSize:18, lineHeight:1.4, marginBottom:10, textAlign:"center" } }, "确认取消订单？"),
          h("div", { style:{ color:C.secondary, fontSize:14, lineHeight:1.65, textAlign:"center" } }, "当前订单需由平台客服核验后处理。确认后将进入客服并提交本次取消订单信息，订单不会立即取消或退款。"),
          h("div", { style:{ marginTop:16, padding:"12px 14px", borderRadius:12, background:C.bg, fontSize:12, lineHeight:1.9 } },
            h("div", { style:{ display:"flex", justifyContent:"space-between", gap:14 } }, h("span", { style:{ color:C.secondary } }, "订单编号"), h("span", { style:{ color:C.text, textAlign:"right", wordBreak:"break-all" } }, order.orderNo || String(order.id || orderId))),
            h("div", { style:{ display:"flex", justifyContent:"space-between", gap:14 } }, h("span", { style:{ color:C.secondary } }, "商品标题"), h("span", { style:{ color:C.text, textAlign:"right" } }, title)),
            h("div", { style:{ display:"flex", justifyContent:"space-between", gap:14 } }, h("span", { style:{ color:C.secondary } }, "当前状态"), h("span", { style:{ color:C.text } }, statusText)),
            h("div", { style:{ display:"flex", justifyContent:"space-between", gap:14 } }, h("span", { style:{ color:C.secondary } }, "实付款"), h("span", { style:{ color:C.text } }, formatMoney(order.amount))),
            h("div", { style:{ display:"flex", justifyContent:"space-between", gap:14 } }, h("span", { style:{ color:C.secondary } }, "咨询类型"), h("strong", { style:{ color:C.danger } }, "用户取消订单"))
          ),
          h("div", { style:{ display:"grid", gridTemplateColumns:"1fr 1fr", gap:10, marginTop:22 } },
            h("button", { onClick:closeCancelConfirm, disabled:!!submitting, style:{ height:44, border:"1px solid " + C.line, borderRadius:10, background:C.surface, color:C.secondary, fontSize:14, fontWeight:600, opacity:submitting ? .55 : 1 } }, "暂不取消"),
            h("button", { onClick:confirmCancelOrder, disabled:!!submitting, style:{ height:44, border:0, borderRadius:10, background:C.danger, color:"#fff", fontSize:14, fontWeight:700, opacity:submitting ? .55 : 1 } }, "确认取消")
          )
        )
      ) : null,
      showUpload ? h("div", { onClick:function(e) { if (e.target === e.currentTarget && !submitting) { setShowUpload(false); setFiles([]); } }, style:{ position:"fixed", inset:0, zIndex:80, background:"rgba(17,24,39,.45)", display:"flex", alignItems:"flex-end", justifyContent:"center" } },
        h("div", { style:{ width:"100%", maxWidth:500, background:C.surface, padding:"18px 16px calc(18px + env(safe-area-inset-bottom, 0px))", boxSizing:"border-box" } },
          h("div", { style:{ display:"flex", justifyContent:"space-between", alignItems:"center", marginBottom:14 } },
            h("strong", { style:{ fontSize:16 } }, "提交服务完成"),
            h("button", { onClick:function() { if (!submitting) { setShowUpload(false); setFiles([]); } }, style:{ border:0, background:"transparent", color:C.secondary, padding:6, display:"flex" }, "aria-label":"关闭" }, icon(["M18 6 6 18", "m6 6 12 12"], 20))
          ),
          h("div", { style:{ color:C.secondary, fontSize:13, lineHeight:1.6, marginBottom:12 } }, "请上传1—5张真实服务完成截图，提交后将开始24小时买家确认倒计时。"),
          h("label", { style:{ minHeight:70, border:"1px dashed " + C.blue, background:C.blueSoft, color:C.blue, display:"flex", alignItems:"center", justifyContent:"center", gap:8, fontSize:13, cursor:"pointer" } },
            icon(["M12 16V4", "m7 9 5-5 5 5", "M5 20h14"], 20), h("span", null, files.length ? "重新选择截图" : "选择服务完成截图"),
            h("input", { type:"file", accept:"image/*", multiple:true, onChange:chooseFiles, style:{ display:"none" } })
          ),
          files.length ? h("div", { style:{ marginTop:10, color:C.secondary, fontSize:12, lineHeight:1.8 } }, files.map(function(file, index) { return h("div", { key:index, style:{ whiteSpace:"nowrap", overflow:"hidden", textOverflow:"ellipsis" } }, (index + 1) + ". " + file.name); })) : null,
          h("button", { onClick:submitBoosterComplete, disabled:!!submitting || !files.length, style:{ width:"100%", height:46, marginTop:16, border:0, background:submitting || !files.length ? "#B8C4DE" : C.blue, color:"#fff", fontSize:14, fontWeight:700 } }, submitting === "boosterComplete" ? "提交中..." : "确认提交")
        )
      ) : null
    );
  }

  window.NK = window.NK || {};
  NK.EscortOrderDetailPage = EscortOrderDetailPage;
})();
