import { checkInTimeOrDefault, checkOutTimeOrDefault } from "@/components/hotel-review/types";
import type { ResponseHotelData } from "@/types/hotel";

interface PropertyRulesSectionBusinessProps {
  propertyRules: ResponseHotelData["propertyRules"];
}

/**
 * LEIS-987 — a Business-mode fork of leisure-ui's PropertyRulesSection: same
 * check-in/out + first-rule summary card. The "Read All Property Rules"
 * expand link is left out — it opens PropertyRulesModal in leisure-ui, which
 * this pass does not port; nothing on this card links anywhere that doesn't
 * exist.
 */
export function PropertyRulesSectionBusiness({ propertyRules }: PropertyRulesSectionBusinessProps) {
  const checkInOutPolicy = propertyRules?.checkInOutPolicies?.[0];
  const checkIn = checkInTimeOrDefault(checkInOutPolicy?.checkIn);
  const checkOut = checkOutTimeOrDefault(checkInOutPolicy?.checkOut);

  const rules: string[] = [];
  propertyRules?.petsPolicies?.forEach((p) => {
    if (p.description) rules.push(p.description);
    else if (p.code?.length) rules.push(`Pet policy: ${p.code.join(", ")}`);
  });
  propertyRules?.stayRequirements?.forEach((r) => {
    if (r.text) rules.push(r.text);
  });

  return (
    <section className="propertyRules mb-4" id="property-rules">
      <div className="container webNewContent">
        <div className="row">
          <div className="col-12">
            <div className="bgColor-white shadow-sm rounded-4 p-3 p-md-4 mb-0">
              <div className="row mb-3">
                <div className="col-12">
                  <h5 className="subHeading fw-bold">Property Rules</h5>
                </div>
              </div>
              <div className="row">
                <div className="col-12">
                  <p className="m-0 text-md mb-2">
                    <strong>Check In: {checkIn}</strong> <strong>Check-out: {checkOut}</strong>
                  </p>
                  {rules.length > 0 && (
                    <ul className="mb-0">
                      <li>{rules[0]}</li>
                    </ul>
                  )}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}
