import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/colors.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/constant/style.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';

class FeedBackController extends GetxController {
  bool isLoading = false;
  final formKey = GlobalKey<FormState>();
  final feedbackController = TextEditingController();

  void addFeedBack() async {
    isLoading = true;
    update();
    var res = await CRUD().post(link: AppLink.addFeedBack, payload: {
      'passengerId': box.read(BoxName.passengerID).toString(),
      'feedBack': feedbackController.text
    });
    var d = jsonDecode(res);
    if (d['status'].toString() == 'success') {
      Get.defaultDialog(
          title: 'Success'.tr,
          titleStyle: AppStyle.title,
          middleText: 'Feedback data saved successfully'.tr,
          middleTextStyle: AppStyle.title,
          confirm: MyElevatedButton(
              kolor: AppColor.greenColor,
              title: 'Ok'.tr,
              onPressed: () {
                Get.back();
                Get.back();
              }));
    }

    isLoading = false;
    update();
  }
}
