<script>
  (function () {
    const archiveContainer = document.getElementById("ac-archive");

    if (!archiveContainer) {
      return;
    }

    /*
      The following listings are representative placeholders.

      Replace them with accurate historical inventory before representing
      them as actual clients, transactions or businesses marketed by
      Acquire Care.
    */

    const serviceTypes = [
      {
        name: "I/DD Community Services Provider",
        group: "I/DD",
        description:
          "Community-based provider supporting individuals with intellectual and developmental disabilities through residential, day and in-home programs."
      },
      {
        name: "Non-Skilled Home Care Agency",
        group: "Home Care",
        description:
          "Established personal care operation with recurring authorization-based hours, an experienced caregiver workforce and opportunities for geographic expansion."
      },
      {
        name: "Skilled Home Health Agency",
        group: "Skilled Home Health",
        description:
          "Licensed home health provider delivering nursing and therapy services through a diversified referral and payer network."
      },
      {
        name: "Behavioral Health Platform",
        group: "Behavioral Health",
        description:
          "Outpatient behavioral health organization providing recurring clinical services through a combination of Medicaid, commercial and self-pay reimbursement."
      },
      {
        name: "I/DD Residential Services Organization",
        group: "I/DD",
        description:
          "Provider operating residential and community-support programs for individuals with intellectual and developmental disabilities."
      },
      {
        name: "Medicaid Personal Care Provider",
        group: "Home Care",
        description:
          "Medicaid-focused personal care provider with recurring service authorizations, caregiver infrastructure and an established local market presence."
      },
      {
        name: "ABA Therapy Provider",
        group: "Behavioral Health",
        description:
          "Applied behavior analysis provider serving children and families through clinic-based, school-based and in-home programs."
      },
      {
        name: "Private Duty Nursing Agency",
        group: "Skilled Home Health",
        description:
          "Provider delivering recurring nursing services for medically complex pediatric and adult patients in the home."
      },
      {
        name: "I/DD Day and Employment Program",
        group: "I/DD",
        description:
          "Community-based organization offering structured day, employment and life-skills programming for adults with developmental disabilities."
      },
      {
        name: "Multi-Site Behavioral Health Group",
        group: "Behavioral Health",
        description:
          "Multi-location behavioral health provider with psychiatry, therapy and care-management capabilities."
      },
      {
        name: "Home Infusion Provider",
        group: "Specialty",
        description:
          "Specialty infusion business coordinating pharmacy, nursing and recurring treatment services in the home."
      },
      {
        name: "Urgent Care Group",
        group: "Clinic",
        description:
          "Regional urgent care operation serving walk-in patients through a combination of commercial insurance, Medicare and self-pay."
      },
      {
        name: "Primary Care Practice",
        group: "Clinic",
        description:
          "Established primary care group with recurring patient relationships and a diversified insurance mix."
      },
      {
        name: "Diagnostic Radiology Center",
        group: "Specialty",
        description:
          "Outpatient imaging provider offering diagnostic radiology services through physician referrals and contracted payer relationships."
      },
      {
        name: "Specialty Medical Clinic",
        group: "Clinic",
        description:
          "Physician-led specialty clinic with recurring patient demand and opportunities for ancillary service growth."
      }
    ];

    /*
      Approximately:
      50% East Coast
      25% Texas, Florida, Illinois and Ohio
      25% other selected states
    */

    const locations = [
      "New Jersey",
      "Connecticut",
      "Pennsylvania",
      "Massachusetts",
      "Maryland",
      "Virginia",
      "North Carolina",
      "South Carolina",
      "Georgia",
      "New Hampshire",
      "Maine",
      "Rhode Island",

      "Texas",
      "Florida",
      "Illinois",
      "Ohio",

      "Arizona",
      "Nevada",
      "California",
      "Colorado",
      "Michigan",
      "Indiana",
      "Tennessee",
      "Missouri"
    ];

    const payerProfiles = [
      "Medicaid and managed Medicaid",
      "Medicare and commercial insurance",
      "VA Community Care Network and private pay",
      "Medicaid, Medicare and commercial plans",
      "Private pay and long-term care insurance",
      "John Hancock, MetLife and private pay",
      "Medicaid waiver programs",
      "Medicare Advantage and traditional Medicare",
      "VA, Medicaid and private pay",
      "Commercial insurance and self-pay",
      "Medicaid, state waiver and private pay",
      "Long-term care insurance and private pay",
      "Medicare, Medicaid and Veterans Affairs",
      "Managed Medicaid and commercial insurance",
      "Private pay, MetLife and John Hancock"
    ];

    const statuses = [
      "Inactive",
      "No Longer Available",
      "Off Market",
      "Archived"
    ];

    const archivePlan = {
      2026: [],
      2025: createListings(2025, 20, 0),
      2024: createListings(2024, 15, 20),
      2023: createListings(2023, 10, 35),
      2022: createListings(2022, 3, 45)
    };

    function createListings(year, count, startingIndex) {
      const listings = [];

      for (let index = 0; index < count; index += 1) {
        const globalIndex = startingIndex + index;
        const service = getService(globalIndex);
        const month = (index % 12) + 1;
        const day = 6 + ((index * 5) % 21);

        listings.push({
          date: formatDate(year, month, day),
          title: service.name,
          category: service.group,
          description: service.description,
          location: getLocation(globalIndex),
          revenue: getRevenue(globalIndex),
          payer: payerProfiles[globalIndex % payerProfiles.length],
          status: statuses[globalIndex % statuses.length],
          profile: getProfile(service.group, globalIndex)
        });
      }

      return listings;
    }

    /*
      Roughly 70% of opportunities are weighted toward:
      home care, skilled home health, behavioral health and I/DD.

      Approximately one-third of the weighted opportunities are I/DD.
    */

    function getService(index) {
      const weightedPattern = [
        0, 1, 2, 3, 4,
        5, 6, 7, 8, 9,
        0, 1, 2, 4, 5,
        8, 3, 6, 1, 0,
        10, 11, 12, 13, 14
      ];

      return serviceTypes[
        weightedPattern[index % weightedPattern.length]
      ];
    }

    function getLocation(index) {
      /*
        Pattern:
        First two out of every four are East Coast.
        Third is Texas, Florida, Illinois or Ohio.
        Fourth is another selected state.
      */

      const eastCoast = locations.slice(0, 12);
      const coreMarkets = locations.slice(12, 16);
      const otherStates = locations.slice(16);

      const position = index % 4;

      if (position === 0 || position === 1) {
        return eastCoast[index % eastCoast.length];
      }

      if (position === 2) {
        return coreMarkets[index % coreMarkets.length];
      }

      return otherStates[index % otherStates.length];
    }

    function getRevenue(index) {
      /*
        Every fifth opportunity is between $10M and $20M.
        The remaining opportunities are between $2M and $7M.
      */

      const largerRevenue = [
        "$10.8M",
        "$12.4M",
        "$14.7M",
        "$16.2M",
        "$18.6M",
        "$19.4M"
      ];

      const coreRevenue = [
        "$2.1M",
        "$2.7M",
        "$3.2M",
        "$3.8M",
        "$4.4M",
        "$4.9M",
        "$5.5M",
        "$6.1M",
        "$6.7M"
      ];

      if (index % 5 === 0) {
        return largerRevenue[
          Math.floor(index / 5) % largerRevenue.length
        ];
      }

      return coreRevenue[index % coreRevenue.length];
    }

    function getProfile(group, index) {
      const profiles = {
        "I/DD": [
          "Residential, day and community support",
          "Waiver-funded recurring services",
          "Community and in-home programs"
        ],
        "Home Care": [
          "Recurring authorized care hours",
          "Caregiver-based service model",
          "Private duty and personal care"
        ],
        "Skilled Home Health": [
          "Nursing and therapy services",
          "Recurring clinical episodes",
          "Licensed skilled-care platform"
        ],
        "Behavioral Health": [
          "Outpatient and community-based care",
          "Recurring clinical visits",
          "Multi-disciplinary treatment model"
        ],
        "Specialty": [
          "Specialty healthcare services",
          "Referral-based patient volume",
          "Clinical and ancillary services"
        ],
        "Clinic": [
          "Outpatient clinic model",
          "Recurring patient demand",
          "Physician and referral driven"
        ]
      };

      const options = profiles[group] || profiles.Specialty;

      return options[index % options.length];
    }

    function formatDate(year, month, day) {
      const date = new Date(year, month - 1, day);

      return date.toLocaleDateString("en-US", {
        month: "long",
        day: "numeric",
        year: "numeric"
      });
    }

    function renderArchive() {
      const years = [2026, 2025, 2024, 2023, 2022];

      archiveContainer.innerHTML = years
        .map(function (year) {
          const listings = archivePlan[year];

          if (!listings.length) {
            return renderTBDYear(year);
          }

          return renderCarouselYear(year, listings);
        })
        .join("");

      initializeCarousels();
    }

    function renderTBDYear(year) {
      return `
        <section class="ac-year-carousel">
          <div class="ac-year-header">
            <div class="ac-year-title-wrap">
              <h3>${year}</h3>
              <span class="ac-year-count">TBD</span>
            </div>
          </div>

          <div class="ac-tbd-card">
            <div class="ac-tbd-content">
              <span>Coming Soon</span>
              <h4>TBD</h4>
              <p>
                Inactive and archived opportunities for ${year} will be
                added as inventory changes throughout the year.
              </p>
            </div>
          </div>
        </section>
      `;
    }

    function renderCarouselYear(year, listings) {
      const slides = listings
        .map(function (listing, index) {
          return `
            <article
              class="ac-slide"
              aria-label="${listing.title}, listing ${index + 1} of ${listings.length}"
            >
              <div class="ac-deal-layout">

                <div class="ac-deal-primary">
                  <div class="ac-deal-date">
                    ${listing.date}
                  </div>

                  <h4>${listing.title}</h4>

                  <p class="ac-deal-summary">
                    ${listing.description}
                  </p>

                  <div class="ac-deal-tags">
                    <span class="ac-deal-tag">
                      ${listing.category}
                    </span>

                    <span class="ac-deal-tag">
                      ${listing.profile}
                    </span>

                    <span class="ac-deal-tag">
                      ${listing.status}
                    </span>
                  </div>
                </div>

                <div class="ac-deal-details">
                  <div class="ac-detail-row">
                    <span class="ac-detail-label">Revenue</span>
                    <span class="ac-detail-value">
                      Approximately ${listing.revenue}
                    </span>
                  </div>

                  <div class="ac-detail-row">
                    <span class="ac-detail-label">Location</span>
                    <span class="ac-detail-value">
                      ${listing.location}
                    </span>
                  </div>

                  <div class="ac-detail-row">
                    <span class="ac-detail-label">Payers</span>
                    <span class="ac-detail-value">
                      ${listing.payer}
                    </span>
                  </div>

                  <div class="ac-detail-row">
                    <span class="ac-detail-label">Status</span>
                    <span class="ac-detail-value">
                      ${listing.status}
                    </span>
                  </div>
                </div>

              </div>
            </article>
          `;
        })
        .join("");

      return `
        <section
          class="ac-year-carousel"
          data-carousel
          data-year="${year}"
        >
          <div class="ac-year-header">
            <div class="ac-year-title-wrap">
              <h3>${year}</h3>

              <span class="ac-year-count">
                ${listings.length}
                ${listings.length === 1 ? "opportunity" : "opportunities"}
              </span>
            </div>
          </div>

          <div class="ac-carousel-shell">
            <div class="ac-carousel-viewport">
              <div class="ac-carousel-track">
                ${slides}
              </div>
            </div>

            <div class="ac-carousel-footer">
              <div class="ac-carousel-arrows">
                <button
                  class="ac-carousel-button ac-carousel-prev"
                  type="button"
                  aria-label="Previous ${year} opportunity"
                >
                  ←
                </button>

                <button
                  class="ac-carousel-button ac-carousel-next"
                  type="button"
                  aria-label="Next ${year} opportunity"
                >
                  →
                </button>
              </div>

              <div class="ac-carousel-progress">
                <span class="ac-carousel-progress-bar"></span>
              </div>

              <div class="ac-carousel-position">
                1 of ${listings.length}
              </div>
            </div>
          </div>
        </section>
      `;
    }

    function initializeCarousels() {
      const carousels = document.querySelectorAll(
        "#ac-archive [data-carousel]"
      );

      carousels.forEach(function (carousel) {
        const track = carousel.querySelector(".ac-carousel-track");
        const slides = carousel.querySelectorAll(".ac-slide");
        const previousButton = carousel.querySelector(
          ".ac-carousel-prev"
        );
        const nextButton = carousel.querySelector(
          ".ac-carousel-next"
        );
        const position = carousel.querySelector(
          ".ac-carousel-position"
        );
        const progressBar = carousel.querySelector(
          ".ac-carousel-progress-bar"
        );
        const viewport = carousel.querySelector(
          ".ac-carousel-viewport"
        );

        let activeIndex = 0;
        let touchStartX = 0;
        let touchEndX = 0;

        function updateCarousel() {
          track.style.transform =
            "translateX(-" + activeIndex * 100 + "%)";

          position.textContent =
            activeIndex + 1 + " of " + slides.length;

          progressBar.style.width =
            ((activeIndex + 1) / slides.length) * 100 + "%";

          previousButton.disabled = activeIndex === 0;
          nextButton.disabled =
            activeIndex === slides.length - 1;
        }

        previousButton.addEventListener("click", function () {
          if (activeIndex > 0) {
            activeIndex -= 1;
            updateCarousel();
          }
        });

        nextButton.addEventListener("click", function () {
          if (activeIndex < slides.length - 1) {
            activeIndex += 1;
            updateCarousel();
          }
        });

        viewport.addEventListener(
          "touchstart",
          function (event) {
            touchStartX = event.changedTouches[0].screenX;
          },
          { passive: true }
        );

        viewport.addEventListener(
          "touchend",
          function (event) {
            touchEndX = event.changedTouches[0].screenX;

            const difference = touchStartX - touchEndX;

            if (
              difference > 45 &&
              activeIndex < slides.length - 1
            ) {
              activeIndex += 1;
              updateCarousel();
            }

            if (difference < -45 && activeIndex > 0) {
              activeIndex -= 1;
              updateCarousel();
            }
          },
          { passive: true }
        );

        carousel.addEventListener("keydown", function (event) {
          if (
            event.key === "ArrowRight" &&
            activeIndex < slides.length - 1
          ) {
            activeIndex += 1;
            updateCarousel();
          }

          if (event.key === "ArrowLeft" && activeIndex > 0) {
            activeIndex -= 1;
            updateCarousel();
          }
        });

        updateCarousel();
      });
    }

    renderArchive();
  })();
</script>