<app-header></app-header>
 <main class="container mx-auto px-4 pb-6 lg:px-6 lg:py-8">
        <!-- Hero Section -->
        <section class="mt-4 mb-8 lg:mb-12">
            <div class="bg-gradient-to-r from-wattpad-primary to-wattpad-secondary rounded-xl p-6 lg:p-8 text-white">
                <div class="flex flex-col lg:flex-row gap-6">
                    <div class="lg:w-1/6">
                        <div class="bg-gray-200 h-64 w-full rounded-lg flex items-center justify-center img100"  *ngIf="storyDetail">
                            <img *ngIf="storyDetail.story_image" [src]="storyImgPath + '/' + storyDetail.story_image" alt="{{ storyDetail.story_title }}">
                            <div *ngIf="!storyDetail.story_image" class="w-full h-full flex items-center justify-center">
                                <i class="fas fa-book text-gray-400 text-2xl"></i>
                            </div>
                        </div>
                    </div>
                    <div class="lg:w-2/3">
                        <h1 class="text-2xl lg:text-4xl font-bold mb-2" *ngIf="storyDetail">{{ storyDetail.story_title }}</h1>
                        
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="bg-white/20 px-3 py-1 rounded-full text-sm">{{storyDetail.categoryName}}</span>
                             <!-- <span class="bg-white/20 px-3 py-1 rounded-full text-sm" *ngIf="!storyDetail.language">{{storyDetail.language}}</span> -->

                             <span class="bg-white/20 px-3 py-1 rounded-full text-sm" *ngIf="storyDetail.language">{{storyDetail.language}}</span>
                            
                        </div>
                        
                        <p class="text-sm lg:text-base mb-6" *ngIf="storyDetail" [innerHtml]="storyDetail.description">
                           
                        </p>
                        
                        <div class="flex flex-wrap items-center gap-4 mb-6">
                            
                               
 <div class="flex items-center" *ngIf="storyDetail">
    
<i class="fas fa-star mx-0.5 "></i>

  


 <span class="ml-1 text-sm text-white">
    {{ storyDetail?.average_rating || 0 }} ({{ storyDetail?.total_ratings || 0 }})
  </span>
</div>
                            <div class="flex items-center">
                                <i class="fas fa-clock mr-1"></i>
                                <span >{{ formatTotalReadTime(getTotalReadingTime()) }}</span>
                            </div>
                            <div class="flex items-center">
                                <i class="fas fa-eye mr-1"></i>
                                <span>{{ getTotalViews() }} Reader</span>
                            </div>
                        </div>
                    
 <div *ngIf="libraryMessage" class="fixed top-4 right-4 bg-green-500 text-white px-4 py-2 rounded shadow z-50">
    {{ libraryMessage }}
  </div>
                        <div class="flex flex-wrap gap-4">
                            <button (click)="scrollToChapters()"  class="bg-white text-wattpad-primary px-6 py-2 rounded-full font-medium hover:bg-gray-100 transition-colors">
                                {{t('READ_NOW')}}
                            </button>
                            

                            <button 
  (click)="addToLibrary(storyDetail.id)"
  class="border border-white text-white pointer px-6 py-2 rounded-full font-medium hover:bg-white/10 transition-colors"
  [title]="likedStories.includes(storyDetail.id) ? 'Remove from Library' : 'Add to Library'"
  [disabled]="isLoading">
  
  <span *ngIf="isLoading">
    <i class="fas fa-spinner fa-spin"></i> Loading...
  </span>
  
  <span *ngIf="!isLoading">
    <span *ngIf="likedStories.includes(storyDetail.id)">
      <i class="fa fa-minus-circle"></i> {{t('REMOVE_FROM_LIBRARY')}}
    </span>
    <span *ngIf="!likedStories.includes(storyDetail.id)">
      <i class="fas fa-plus mr-2"></i> {{t('ADD_TO_LIBRARY')}}
    </span>
  </span>
</button>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Writer Profile -->
        <section class="mb-8 lg:mb-12">
            <div class="flex items-center justify-between bg-white dark:bg-gray-800 rounded-xl p-4 shadow-sm">
                <div class="flex items-center space-x-4">
                    <div class="bg-gray-200 overflow-h w-16 h-16 rounded-full flex-shrink-0 flex items-center justify-center">
                        
                       
  <ng-container *ngIf="authorProfileUrl; else authorInitialTpl">
  <img [src]="authorProfileUrl" 
       alt="Author" 
       class="w-full h-full object-cover"
       (error)="onImageError()" />
</ng-container>
<ng-template #authorInitialTpl>
  <div class="flex items-center justify-center w-full h-full bg-gray-200 rounded-full">
    <span class="text-2xl font-medium text-gray-700">{{ authorInitial }}</span>
  </div>
</ng-template>

                    </div>
                    <div>
                        <h3 class="font-bold pointer" (click)="viewProfile(storyDetail.user_id)">{{ storyDetail.author_name || 'Unknown Author' }}</h3>
                        <p class="text-sm text-wattpad-light">{{ formatCount(followerCount) }} {{t('FOLLOWERS')}}</p>
                    </div>
                </div>
               <div *ngIf="storyDetail && storyDetail.author_id !== userId">
  <!-- Show followers initials if available -->
  <div *ngIf="followerUsers.length > 0" class="flex items-center space-x-2 mb-4 followers">
  <div class="flex -space-x-2">
    <div 
      *ngFor="let user of followerUsers.slice(0, 5)" 
      class="w-8 h-8 rounded-full bg-gray-200 dark:bg-gray-600 flex items-center justify-center text-sm font-medium text-gray-700 dark:text-gray-200 border-2 border-white dark:border-gray-800"
    >
    
      {{ user.name.charAt(0).toUpperCase() }}
    </div>
  </div>
</div>
         <button 
  *ngIf="storyDetail && storyDetail.author_id !== userId"
  (click)="toggleFollow()"
  [ngClass]="{
    'bg-wattpad-primary text-white pointer': !isFollowing,
    'bg-white text-wattpad-primary border border-wattpad-primary pointer': isFollowing
  }"
  class="px-4 py-2 rounded-full text-sm font-medium hover:bg-opacity-80 transition-colors pointer"
>
  {{ isFollowing ? 'Unfollow' : 'Follow' }}
</button>    
            </div>
            </div>
        </section>

        <!-- Chapters -->
        <section id="chapters" class="mb-8 lg:mb-12">
            <h2 class="text-xl lg:text-2xl font-bold mb-4 lg:mb-6">{{t('CHAPTERS')}}</h2>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <!-- Chapter 1 -->
                <div *ngFor="let story of stories; let i = index" 
     (click)="handleChapterClick(i, story)"
     [ngClass]="{
        'chapter-card': true,
        'bg-white dark:bg-gray-800 rounded-lg p-4 shadow-sm transition-all': true,
        'hover:shadow-md cursor-pointer': i < 1 || userId,
        'opacity-75': i >= 1 && !userId,
        'cursor-not-allowed': i >= 1 && !userId
     }">
    <h3 class="font-bold text-lg mb-2">
        Chapter {{i + 1}} - {{ story.story_title }}
        <span *ngIf="i >= 1 && !userId" class="ml-2 text-yellow-500">
            <i class="fas fa-lock"></i> Login to read
        </span>
    </h3>
                    <div class="flex flex-wrap items-center gap-4 text-sm text-wattpad-light mb-2">
                        <div class="flex items-center">
                            <i class="fas fa-eye mr-1"></i>
                            <span>{{ story.views || 0 }} {{t('VIEWS')}}</span>
                        </div>
                        <div class="flex items-center">
                            <i class="fas fa-star text-yellow-400 mr-1"></i>
                            <span>{{story.average_rating}}</span>
                        </div>
                        <div class="flex items-center">
                            <i class="fas fa-clock mr-1"></i>
                            <span>{{ story.readTime }} min read</span>
                        </div>
                    </div>
                    <p class="text-sm text-wattpad-light">Published: {{ getTimeAgo(getValidDate(story)) }}</p>
                </div>
                
               
            </div>
        </section>

        <!-- Popular Languages -->
        <!-- <section class="mb-8 lg:mb-12">
            <h2 class="text-xl lg:text-2xl font-bold mb-4 lg:mb-6">Popular Languages</h2>
            
            <div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-7 gap-3">
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-3 text-center hover:shadow-md transition-all">
                    <span class="font-medium">English</span>
                </a>
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-3 text-center hover:shadow-md transition-all">
                    <span class="font-medium">Marathi</span>
                </a>
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-3 text-center hover:shadow-md transition-all">
                    <span class="font-medium">Bengali</span>
                </a>
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-3 text-center hover:shadow-md transition-all">
                    <span class="font-medium">Malayalam</span>
                </a>
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-3 text-center hover:shadow-md transition-all">
                    <span class="font-medium">Kannada</span>
                </a>
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-3 text-center hover:shadow-md transition-all">
                    <span class="font-medium">Telugu</span>
                </a>
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-3 text-center hover:shadow-md transition-all">
                    <span class="font-medium">Tamil</span>
                </a>
            </div>
        </section> -->

        <!-- Top Genre -->
        <!-- <section class="mb-8 lg:mb-12">
            <h2 class="text-xl lg:text-2xl font-bold mb-4 lg:mb-6">Top Genre</h2>
            
            <div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3">
                <a href="search?q=romance" class="bg-white dark:bg-gray-800 rounded-lg p-4 text-center hover:shadow-md transition-all">
                    <span class="font-medium">Romance</span>
                </a>
                <a href="search?q=Suspense" class="bg-white dark:bg-gray-800 rounded-lg p-4 text-center hover:shadow-md transition-all">
                    <span class="font-medium">Suspense</span>
                </a>
                <a href="search?q=Drama" class="bg-white dark:bg-gray-800 rounded-lg p-4 text-center hover:shadow-md transition-all">
                    <span class="font-medium">Drama</span>
                </a>
                <a href="search?q=horror" class="bg-white dark:bg-gray-800 rounded-lg p-4 text-center hover:shadow-md transition-all">
                    <span class="font-medium">Horror</span>
                </a>
            </div>
        </section> -->

        <!-- Top Content -->
        <!-- <section class="mb-8 lg:mb-12">
            <h2 class="text-xl lg:text-2xl font-bold mb-4 lg:mb-6">Top Content</h2>
            
            <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-4 hover:shadow-md transition-all">
                    <h3 class="font-medium">Top Hindi Kahaniyan</h3>
                </a>
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-4 hover:shadow-md transition-all">
                    <h3 class="font-medium">Best Hindi Short Stories</h3>
                </a>
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-4 hover:shadow-md transition-all">
                    <h3 class="font-medium">Popular Hindi Stories</h3>
                </a>
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-4 hover:shadow-md transition-all">
                    <h3 class="font-medium">Top Motivational Hindi Stories</h3>
                </a>
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-4 hover:shadow-md transition-all">
                    <h3 class="font-medium">Top Short Hindi Stories</h3>
                </a>
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-4 hover:shadow-md transition-all">
                    <h3 class="font-medium">Sad Stories in Hindi</h3>
                </a>
                <a href="#" class="bg-white dark:bg-gray-800 rounded-lg p-4 hover:shadow-md transition-all">
                    <h3 class="font-medium">Horror Hindi Stories</h3>
                </a>
            </div>
        </section> -->
    </main>