import 'dart:io';

import 'package:e_commerce_training/src/model/repository/app_repository.dart';
import 'package:e_commerce_training/src/model/response/profile_settings_response.dart';
import 'package:e_commerce_training/src/page/profile_settings/profile_settings_state.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:image_picker/image_picker.dart';

class ProfileSettingsCubit extends Cubit<ProfileSettingsState> {
  final AppRepository repository;
  List<ProfileSettingRespone> listProfile = [];
  File? _file;

  ProfileSettingsCubit(this.repository) : super(InitialProfileSettingsState());

  Future<void> pickAvatar(bool isUploadFromCamera) async {
    emit(InitialProfileSettingsState());
    _file = File((await ImagePicker().getImage(
      source: isUploadFromCamera ? ImageSource.camera : ImageSource.gallery,
    ))!
        .path);
    emit(GetProfileSettingsSuccess(_file));
  }

  void addProduct() {
    listProfile.add(ProfileSettingRespone(
        id: "1",
        avatar: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTEIvtJWrUeg-DcpGeeeJwIxHmnQIDf39rZXA&usqp=CAU",
        nameUser: "Martha Craig",
        email: "marthacraig@gmail.com",
        image: [
          Images(
              id: "1",
              thumb:
                  "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTEIvtJWrUeg-DcpGeeeJwIxHmnQIDf39rZXA&usqp=CAU"),
          Images(
              id: "2",
              thumb:
                  "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTEIvtJWrUeg-DcpGeeeJwIxHmnQIDf39rZXA&usqp=CAU"),
          Images(
              id: "2",
              thumb:
                  "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTEIvtJWrUeg-DcpGeeeJwIxHmnQIDf39rZXA&usqp=CAU"),
          Images(
              id: "2",
              thumb:
                  "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTEIvtJWrUeg-DcpGeeeJwIxHmnQIDf39rZXA&usqp=CAU"),
          Images(
              id: "2",
              thumb:
                  "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTEIvtJWrUeg-DcpGeeeJwIxHmnQIDf39rZXA&usqp=CAU"),
        ]));
  }
}
