import 'package:cheminova/models/product_manual_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cached_pdfview/flutter_cached_pdfview.dart';

// Screen to display a PDF document for a product manual
class ViewPdfScreen extends StatefulWidget {
  final ProductManualModel productManualModel;

  const ViewPdfScreen({super.key, required this.productManualModel});

  @override
  State<ViewPdfScreen> createState() => _ViewPdfScreenState();
}

class _ViewPdfScreenState extends State<ViewPdfScreen> {
  @override
  Widget build(BuildContext context) {
    // Build the PDF viewing screen
    return Scaffold(
      body: SafeArea(
        // Use the PDF widget to display the PDF document
        child: const PDF(
          fitEachPage: true, // Fit the PDF content to each page
          fitPolicy: FitPolicy.BOTH, // Adjust both width and height
          autoSpacing: false, // Disable auto spacing
        ).cachedFromUrl(
          // Fetch and cache the PDF from the provided URL
          widget.productManualModel.productManualDetail.url,
          placeholder: (progress) =>
              Center(child: Text('$progress %')), // Display loading progress
          errorWidget: (error) =>
              Center(child: Text(error.toString())), // Display error message
        ),
      ),
    );
  }
}
