All files / apps/web/src/frontoffice/components PageViewerModal.jsx

0% Statements 0/13
0% Branches 0/19
0% Functions 0/6
0% Lines 0/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99                                                                                                                                                                                                     
import { useState } from 'react'
import { X, ChevronLeft, ChevronRight } from 'lucide-react'
 
export default function PageViewerModal({ isOpen, onClose, pages, title }) {
  const [currentPage, setCurrentPage] = useState(0)
  
  if (!isOpen || !pages || pages.length === 0) return null
  
  const goToPage = (index) => {
    if (index >= 0 && index < pages.length) {
      setCurrentPage(index)
    }
  }
  
  const goToPrevious = () => goToPage(currentPage - 1)
  const goToNext = () => goToPage(currentPage + 1)
  
  return (
    <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4">
      <div className="bg-white rounded-xl shadow-2xl max-w-6xl w-full max-h-[90vh] overflow-hidden flex flex-col">
        {/* Header */}
        <div className="flex items-center justify-between p-4 border-b">
          <div className="flex items-center gap-4">
            <h3 className="text-lg font-semibold text-gray-900">{title || 'Aperçu'}</h3>
            <span className="text-sm text-gray-500">
              Page {currentPage + 1} / {pages.length}
            </span>
          </div>
          <button 
            onClick={onClose} 
            className="p-2 hover:bg-gray-100 rounded-full"
          >
            <X className="w-6 h-6 text-gray-500" />
          </button>
        </div>
        
        {/* Main content - Image viewer */}
        <div className="flex-1 bg-gray-100 flex items-center justify-center p-4 relative">
          {/* Previous button */}
          {pages.length > 1 && (
            <button
              onClick={goToPrevious}
              disabled={currentPage === 0}
              className="absolute left-4 p-2 bg-white/80 hover:bg-white rounded-full shadow-lg disabled:opacity-30 disabled:cursor-not-allowed z-10"
            >
              <ChevronLeft className="w-6 h-6" />
            </button>
          )}
          
          {/* Current image */}
          <img 
            src={pages[currentPage].url} 
            alt={`Page ${currentPage + 1}`}
            className="max-w-full max-h-[60vh] object-contain shadow-lg rounded-lg"
          />
          
          {/* Next button */}
          {pages.length > 1 && (
            <button
              onClick={goToNext}
              disabled={currentPage === pages.length - 1}
              className="absolute right-4 p-2 bg-white/80 hover:bg-white rounded-full shadow-lg disabled:opacity-30 disabled:cursor-not-allowed z-10"
            >
              <ChevronRight className="w-6 h-6" />
            </button>
          )}
        </div>
        
        {/* Thumbnails */}
        {pages.length > 1 && (
          <div className="p-4 border-t bg-gray-50">
            <div className="flex gap-2 overflow-x-auto pb-2">
              {pages.map((page, index) => (
                <button
                  key={index}
                  onClick={() => goToPage(index)}
                  className={`flex-shrink-0 relative rounded-lg overflow-hidden border-2 transition-all ${
                    index === currentPage 
                      ? 'border-purple-500 ring-2 ring-purple-200' 
                      : 'border-gray-200 hover:border-gray-300'
                  }`}
                >
                  <img 
                    src={page.url} 
                    alt={`Miniature ${index + 1}`}
                    className="w-20 h-28 object-cover"
                  />
                  <span className="absolute bottom-1 right-1 text-xs bg-black/50 text-white px-1.5 py-0.5 rounded">
                    {index + 1}
                  </span>
                </button>
              ))}
            </div>
          </div>
        )}
      </div>
    </div>
  )
}