import type { RefObject } from "react";

import { HotelRatePolicyBadge } from "@/components/hotels/HotelPolicyBadge";

import { BookingSummaryHotel } from "./BookingSummaryHotel";
import { GuestDetailsCardHotel, type GuestDetailsCardHotelHandle } from "./GuestDetailsCardHotel";
import type { HotelRequestSelection } from "./types";

/**
 * LEIS-988/989 — step 2, "Review Booking": property, room + rate,
 * cancellation terms, dates/nights, AND Guest Details, all on one page —
 * matching leisure-ui's actual "Review your Booking" page (the user's own
 * reference) rather than splitting Guest Details into a step of its own.
 *
 * Guest Details still validates through `formRef` before the rail's Next
 * advances to Request approval (see HotelReviewClient.goNext), the same
 * imperative-handle pattern used when this was briefly its own step — only
 * the layout changed, not the validation gate.
 */
export function PaneReviewHotel({
  selection,
  travelerId,
  guestFormRef,
}: {
  selection: HotelRequestSelection;
  travelerId: string | null;
  guestFormRef: RefObject<GuestDetailsCardHotelHandle | null>;
}) {
  return (
    <div className="d-flex flex-column gap-3">
      <BookingSummaryHotel selection={selection} />
      {/* The verdict for the chosen rate (LEIS-1001). The approval step shows
          the SERVER's full check list; this is the same advisory badge the
          details page showed, repeated here so the traveller does not have to
          remember it across a step. The two agree because both read the same
          selection. */}
      <HotelRatePolicyBadge
        travelerId={travelerId}
        countryCode={selection.countryCode || null}
        facts={{
          nightlyRate: selection.nightlyRate,
          taxesPerNight: selection.taxesAndFeesPerNight,
          currency: selection.currency,
          starRating: selection.starRating,
          nights: selection.nights,
          checkIn: selection.checkIn,
          isRefundable: selection.isRefundable,
          propertyType: selection.propertyType,
          chainCode: selection.chainCode,
          propertyCode: selection.propertyCode,
        }}
      />
      <GuestDetailsCardHotel
        travelerId={travelerId}
        countryCode={selection.countryCode || null}
        formRef={guestFormRef}
      />
    </div>
  );
}
