import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:get/get.dart';

import 'package:path/path.dart' as path;
import 'package:traderscircuit/controller/contact_us_controller.dart';

import '../utils.dart';

class FilePickerMethod {
  ContactUsController contactUsController = Get.put(ContactUsController());
  String extractFileName(String filePath) {
    return path.basename(filePath);
  }

  Future<List<File?>?> pickFile() async {
    FilePickerResult? result = await FilePicker.platform.pickFiles(
      allowMultiple: true,
      allowCompression: true,
      //compressionQuality: 50,
      type: FileType.custom,
      allowedExtensions: [
        'jpg',
        'jpeg',
        'png',
        'pdf'
      ], // Define the allowed file types
    );

    if (result != null) {
      if (contactUsController.attachmentFileList.length + result.count > 3) {
        Utils.showToast("Can Select Max 3 Files");
        return null;
      } else {
        return result.paths.map((path) => File(path!)).toList();
      }
    } else {
      return null;
    }
  }
}
