import 'dart:developer';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';

class PdfPage extends StatelessWidget {
  PdfPage({super.key, required this.params});
  final PdfPageParams params;
  final GlobalKey<SfPdfViewerState> _pdfViewerKey = GlobalKey();
  @override
  Widget build(BuildContext context) {
    log(params.file, name: "PdfPage");
    return Scaffold(
      appBar: AppBar(
        title: Text(params.title),
        actions: [
          IconButton(
              onPressed: () {
                _pdfViewerKey.currentState?.openBookmarkView();
              },
              icon: Icon(Icons.bookmark_add)),
        ],
      ),
      body: SfPdfViewer.file(
        key: _pdfViewerKey,
        File(params.file),
        // canShowPageLoadingIndicator: true,
        canShowScrollHead: true,
        canShowScrollStatus: true,
        enableDoubleTapZooming: true,
        initialZoomLevel: params.initialZoom,
        // maxZoomLevel: 6,
      ),
      bottomNavigationBar: (params.bottom == null)
          ? null
          : Padding(
              padding: const EdgeInsets.all(8.0),
              child: params.bottom,
            ),
    );
  }
}

class PdfPageParams {
  const PdfPageParams(
      {required this.file,
      required this.title,
      this.bottom,
      this.initialZoom = 3});
  final String title;
  final String file;
  final Widget? bottom;

  final double initialZoom;
}
