<div class="flex flex-col md:flex-row">
  <!-- Filter Panel for Desktop -->
  <div class="hidden md:block w-full md:w-1/4 h-full bg-white shadow-lg p-6 overflow-y-auto z-10">
    <app-search-modal-commercial [isModal]="false"></app-search-modal-commercial>
  </div>

  <!-- Main Content -->
  <div class="w-full p-4">
    <div class="container mx-auto">
      <!-- Breadcrumbs -->
      <div class="mb-4">
        <app-breadcrumbs [breadcrumbs]="breadcrumbs"></app-breadcrumbs>
      </div>

      <!-- SEO-optimized heading -->
      <div class="mb-6">
        <h1 class="text-3xl md:text-4xl font-bold text-neutral-900 mb-2">Commercial Properties for Sale</h1>
        <p class="text-lg text-neutral-600">Discover selected investment properties and commercial spaces. Connect with verified sellers and brokers to find your next asset.</p>
        <div class="mt-4 text-base text-neutral-700 max-w-4xl">
          <p>BizMatch presents commercial real estate opportunities for sale or lease. View investment properties with detailed information on square footage, zoning, pricing, and location. Our platform connects property buyers and investors directly with sellers and commercial real estate brokers, focusing on transparent and valuable transactions.</p>
        </div>
      </div>

      @if(listings?.length > 0) {
      <h2 class="text-2xl font-semibold text-neutral-800 mb-4">Available Commercial Property Listings</h2>
      <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
        @for (listing of listings; track listing.id) {
        <div class="bg-white rounded-lg drop-shadow-custom-bg-mobile md:drop-shadow-custom-bg overflow-hidden flex flex-col h-full group relative">
          <!-- Quick Actions Overlay -->
          <div class="absolute top-4 right-4 z-10 flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity duration-200">
            @if(user) {
            <button
              class="bg-white rounded-full p-2 shadow-lg transition-colors"
              [class.bg-red-50]="isFavorite(listing)"
              [class.opacity-100]="isFavorite(listing)"
              [attr.aria-label]="isFavorite(listing) ? 'Remove from favorites' : 'Save to favorites'"
              (click)="toggleFavorite($event, listing)">
              <i [class]="isFavorite(listing) ? 'fas fa-heart text-red-500' : 'far fa-heart text-red-500 hover:scale-110 transition-transform'"></i>
            </button>
            }
            <button type="button" class="bg-white rounded-full p-2 shadow-lg hover:bg-blue-50 transition-colors"
              aria-label="Share property" (click)="shareProperty($event, listing)">
              <i class="fas fa-share-alt text-blue-500 hover:scale-110 transition-transform"></i>
            </button>
          </div>
          @if (listing.imageOrder?.length>0){
          <img [appLazyLoad]="env.imageBaseUrl + '/pictures/property/' + listing.imagePath + '/' + listing.serialId + '/' + listing.imageOrder[0]"
               [alt]="altText.generatePropertyListingAlt(listing)"
               class="w-full h-48 object-cover"
               width="400"
               height="192" />
          } @else {
          <img [appLazyLoad]="'assets/images/placeholder_properties.jpg'"
               [alt]="'Commercial property placeholder - ' + listing.title"
               class="w-full h-48 object-cover"
               width="400"
               height="192" />
          }
          <div class="p-4 flex flex-col flex-grow">
            <span [class]="selectOptions.getTextColorTypeOfCommercial(listing.type)" class="text-sm font-semibold"
              ><i [class]="selectOptions.getIconAndTextColorTypeOfCommercials(listing.type)" class="mr-1"></i> {{ selectOptions.getCommercialProperty(listing.type) }}</span
            >
            <div class="flex items-center justify-between my-2">
              <span class="bg-neutral-200 text-neutral-700 text-xs font-semibold px-2 py-1 rounded">{{ selectOptions.getState(listing.location.state) }}</span>
              <p class="text-sm text-neutral-600 mb-4">
                <strong>{{ getDaysListed(listing) }} days listed</strong>
              </p>
            </div>
            <h3 class="text-lg font-semibold mb-2">
              {{ listing.title }}
              @if(listing.draft){
              <span class="bg-red-100 text-red-800 text-sm font-medium me-2 ml-2 px-2.5 py-0.5 rounded dark:bg-red-900 dark:text-red-300">Draft</span>
              }
            </h3>
            <p class="text-neutral-600 mb-2">{{ listing.location.name ? listing.location.name : listing.location.county }}</p>
            <p class="text-xl font-bold mb-4">{{ listing.price | currency : 'USD' : 'symbol' : '1.0-0' }}</p>
            <div class="flex-grow"></div>
            <button [routerLink]="['/commercial-property', listing.slug || listing.id]" class="bg-success-500 text-white px-4 py-2 rounded-full w-full hover:bg-success-600 transition duration-300 mt-auto">
              View Full Listing <i class="fas fa-arrow-right ml-1"></i>
            </button>
          </div>
        </div>
        }
      </div>
      } @else if (listings?.length === 0){
      <div class="w-full flex items-center flex-wrap justify-center gap-10">
        <div class="grid gap-4 w-60">
          <svg class="mx-auto" xmlns="http://www.w3.org/2000/svg" width="154" height="161" viewBox="0 0 154 161" fill="none">
            <path
              d="M0.0616455 84.4268C0.0616455 42.0213 34.435 7.83765 76.6507 7.83765C118.803 7.83765 153.224 42.0055 153.224 84.4268C153.224 102.42 147.026 118.974 136.622 132.034C122.282 150.138 100.367 161 76.6507 161C52.7759 161 30.9882 150.059 16.6633 132.034C6.25961 118.974 0.0616455 102.42 0.0616455 84.4268Z"
              fill="#EEF2FF"
            />
            <path
              d="M96.8189 0.632498L96.8189 0.632384L96.8083 0.630954C96.2034 0.549581 95.5931 0.5 94.9787 0.5H29.338C22.7112 0.5 17.3394 5.84455 17.3394 12.4473V142.715C17.3394 149.318 22.7112 154.662 29.338 154.662H123.948C130.591 154.662 135.946 149.317 135.946 142.715V38.9309C135.946 38.0244 135.847 37.1334 135.648 36.2586L135.648 36.2584C135.117 33.9309 133.874 31.7686 132.066 30.1333C132.066 30.1331 132.065 30.1329 132.065 30.1327L103.068 3.65203C103.068 3.6519 103.067 3.65177 103.067 3.65164C101.311 2.03526 99.1396 0.995552 96.8189 0.632498Z"
              fill="white"
              stroke="#E5E7EB"
            />
            <ellipse cx="80.0618" cy="81" rx="28.0342" ry="28.0342" fill="#EEF2FF" />
            <path
              d="M99.2393 61.3061L99.2391 61.3058C88.498 50.5808 71.1092 50.5804 60.3835 61.3061C49.6423 72.0316 49.6422 89.4361 60.3832 100.162C71.109 110.903 88.4982 110.903 99.2393 100.162C109.965 89.4363 109.965 72.0317 99.2393 61.3061ZM105.863 54.6832C120.249 69.0695 120.249 92.3985 105.863 106.785C91.4605 121.171 68.1468 121.171 53.7446 106.785C39.3582 92.3987 39.3582 69.0693 53.7446 54.683C68.1468 40.2965 91.4605 40.2966 105.863 54.6832Z"
              stroke="#E5E7EB"
            />
            <path d="M110.782 119.267L102.016 110.492C104.888 108.267 107.476 105.651 109.564 102.955L118.329 111.729L110.782 119.267Z" stroke="#E5E7EB" />
            <path
              d="M139.122 125.781L139.122 125.78L123.313 109.988C123.313 109.987 123.313 109.987 123.312 109.986C121.996 108.653 119.849 108.657 118.521 109.985L118.871 110.335L118.521 109.985L109.047 119.459C107.731 120.775 107.735 122.918 109.044 124.247L109.047 124.249L124.858 140.06C128.789 143.992 135.191 143.992 139.122 140.06C143.069 136.113 143.069 129.728 139.122 125.781Z"
              fill="#A5B4FC"
              stroke="#818CF8"
            />
            <path
              d="M83.185 87.2285C82.5387 87.2285 82.0027 86.6926 82.0027 86.0305C82.0027 83.3821 77.9987 83.3821 77.9987 86.0305C77.9987 86.6926 77.4627 87.2285 76.8006 87.2285C76.1543 87.2285 75.6183 86.6926 75.6183 86.0305C75.6183 80.2294 84.3831 80.2451 84.3831 86.0305C84.3831 86.6926 83.8471 87.2285 83.185 87.2285Z"
              fill="#4F46E5"
            />
            <path
              d="M93.3528 77.0926H88.403C87.7409 77.0926 87.2049 76.5567 87.2049 75.8946C87.2049 75.2483 87.7409 74.7123 88.403 74.7123H93.3528C94.0149 74.7123 94.5509 75.2483 94.5509 75.8946C94.5509 76.5567 94.0149 77.0926 93.3528 77.0926Z"
              fill="#4F46E5"
            />
            <path
              d="M71.5987 77.0925H66.6488C65.9867 77.0925 65.4507 76.5565 65.4507 75.8945C65.4507 75.2481 65.9867 74.7122 66.6488 74.7122H71.5987C72.245 74.7122 72.781 75.2481 72.781 75.8945C72.781 76.5565 72.245 77.0925 71.5987 77.0925Z"
              fill="#4F46E5"
            />
            <rect x="38.3522" y="21.5128" width="41.0256" height="2.73504" rx="1.36752" fill="#4F46E5" />
            <rect x="38.3522" y="133.65" width="54.7009" height="5.47009" rx="2.73504" fill="#A5B4FC" />
            <rect x="38.3522" y="29.7179" width="13.6752" height="2.73504" rx="1.36752" fill="#4F46E5" />
            <circle cx="56.13" cy="31.0854" r="1.36752" fill="#4F46E5" />
            <circle cx="61.6001" cy="31.0854" r="1.36752" fill="#4F46E5" />
            <circle cx="67.0702" cy="31.0854" r="1.36752" fill="#4F46E5" />
          </svg>
          <div>
            <h2 class="text-center text-black text-xl font-semibold leading-loose pb-2">There’s no listing here</h2>
            <p class="text-center text-black text-base font-normal leading-relaxed pb-4">Try changing your filters to <br />see listings</p>
            <div class="flex gap-3">
              <button (click)="clearAllFilters()" class="w-full px-3 py-2 rounded-full border border-neutral-300 text-neutral-900 text-xs font-semibold leading-4">Clear Filter</button>
            </div>
          </div>
        </div>
      </div>
      }
    </div>
    @if(pageCount > 1) {
    <app-paginator [page]="page" [pageCount]="pageCount" (pageChange)="onPageChange($event)"></app-paginator>
    }
  </div>

  <!-- Filter Button for Mobile -->
  <button (click)="openFilterModal()" class="md:hidden fixed bottom-4 right-4 bg-primary-500 text-white p-3 rounded-full shadow-lg z-20"><i class="fas fa-filter"></i> Filter</button>
</div>
