/**
 * Live Tracking — Property Deal Page (replaces property-detail-drawer)
 *
 * Verifies the two core navigation behaviors after moving from a right-side
 * drawer to a dedicated CRM-style deal page at /live/[dealId]:
 *
 *  1. Property table rows link to the correct deal page URL.
 *  2. The deal page loads with the Works tab active by default.
 *
 * Reads LIVE_PORTFOLIO_SLUG from Cypress env so it runs against any seeded
 * environment without hard-coding an ID.
 */

const PORTFOLIO_SLUG = Cypress.env("LIVE_PORTFOLIO_SLUG");

describe("Property deal page", function () {
  before(function () {
    if (!PORTFOLIO_SLUG) {
      cy.log(
        "LIVE_PORTFOLIO_SLUG env var not set — skipping live tracking specs",
      );
      this.skip();
    }
  });

  it("property table row has link to deal page URL", () => {
    cy.visit(`/portfolio/${PORTFOLIO_SLUG}/your-projects/live`);
    cy.contains("button, [role=tab]", "Properties").click();
    cy.get("[data-testid=property-row-link]")
      .first()
      .should("have.attr", "href")
      .and(
        "match",
        new RegExp(
          `/portfolio/${PORTFOLIO_SLUG}/your-projects/live/[^/]+$`,
        ),
      );
  });

  it("deal page shows Works tab active by default", () => {
    cy.visit(`/portfolio/${PORTFOLIO_SLUG}/your-projects/live`);
    cy.contains("button, [role=tab]", "Properties").click();
    cy.get("[data-testid=property-row-link]").first().click();
    cy.get("[data-testid=deal-page-tab-works]").should(
      "have.attr",
      "aria-selected",
      "true",
    );
  });
});
