import 'package:flutter/material.dart';
import 'package:file_picker/file_picker.dart';

class MarineInfoCentreDocument extends StatefulWidget {
  @override
  State<MarineInfoCentreDocument> createState() => _MarineInfoCentreDocumentState();
}

class _MarineInfoCentreDocumentState extends State<MarineInfoCentreDocument> {
  String? selectedFileName;

  Future<void> _pickDocument() async {
    final result = await FilePicker.platform.pickFiles();
    if (result != null && result.files.isNotEmpty) {
      setState(() => selectedFileName = result.files.first.name);
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text("Document '${result.files.first.name}' selected")),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Marine Info Centre Document")),
      body: Padding(
        padding: const EdgeInsets.all(24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text("Upload or View Reference Documents", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
            SizedBox(height: 24),
            ElevatedButton.icon(
              icon: Icon(Icons.upload_file),
              label: Text("Select Document"),
              onPressed: _pickDocument,
            ),
            SizedBox(height: 16),
            if (selectedFileName != null)
              Text("Selected: $selectedFileName", style: TextStyle(fontSize: 16)),
            SizedBox(height: 24),
            ElevatedButton(
              onPressed: selectedFileName != null
                  ? () {
                // Submit logic here
                ScaffoldMessenger.of(context).showSnackBar(
                  SnackBar(content: Text("Document submitted")),
                );
              }
                  : null,
              child: Text("Submit Document"),
            ),
          ],
        ),
      ),
    );
  }
}