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

class SingleFileUploadWidget extends StatefulWidget {
  const SingleFileUploadWidget({super.key});

  @override
  State<SingleFileUploadWidget> createState() => SingleFileUploadWidgetState();
}

class SingleFileUploadWidgetState extends State<SingleFileUploadWidget> {
  PlatformFile? selectedFile;

  Future<void> pickFile() async {
    final result = await FilePicker.platform.pickFiles(
      allowMultiple: false,
      withData: true,
      type: FileType.custom,
      allowedExtensions: ['pdf', 'png', 'jpg', 'jpeg', 'heic'],
    );

    if (result != null && result.files.isNotEmpty) {
      setState(() {
        selectedFile = result.files.first;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: pickFile,
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(12),
          border: Border.all(color: const Color(0xFFE26728)),
          boxShadow: [
            BoxShadow(
              color: Colors.grey.withOpacity(0.2),
              blurRadius: 4,
              offset: const Offset(0, 2),
            ),
          ],
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Expanded(
              child: Text(
                selectedFile != null ? selectedFile!.name : "Upload Document",
                style: const TextStyle(
                  fontSize: 14,
                  color: Colors.black,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
            ),
            const Icon(
              Icons.file_upload_outlined,
              color: Color(0xFFE26728),
              size: 22,
            ),
          ],
        ),
      ),
    );
  }
}
