import 'package:flutter/material.dart';
import 'package:flutter_paypal_payment/flutter_paypal_payment.dart';
import 'dart:io' show Platform;
import 'package:flutter_paypal/flutter_paypal.dart';
//import 'package:paypal_flutter/paypal_flutter.dart';
import 'package:flutter_paypal_payment/flutter_paypal_payment.dart';

import "package:daciapackete/logging.dart" as logging;


class FormPayPal extends StatelessWidget {
  const FormPayPal({super.key});

  @override

  setPaypal(){
    var clientID ="";
    var secretKey ="";
    if (Platform.isIOS){
      clientID = "AavaGu643froxEOY4fAMh2_hecYDburIg8gMt3lmxcgoGHfKFONRKl-D3RfbmTo9EheoYOKa_z4urN84";
      secretKey = "EFHdjCdQbRCJjwue6DBnn7LkLbnVa38Zt4RRm1JUWP9HqMbHl0d4swotKZ7D69GCSDCgspD9dGVzi5b-";
    } else if (Platform.isAndroid) {
      clientID = "AZsGy5-4gwvNhIoMZ8xj-XIlHJ0by8u4PHa7Sh1zJfdd6ido6uq8VrjxOh1mRX_P81Qdrui2X8VH3-8r";
      secretKey = "EJI6EOx6ZqTJWNjlzuhtNEWPgJjnURusX5euI_UbWCKM8fMY1Ts0oBOY1NVaZMFcjqNK72tyGBfm8eFd";
    }else if (Platform.isLinux) {

    }else if (Platform.isMacOS) {

    }else if (Platform.isWindows) {

    }
  }




  Widget build(BuildContext context) {

    return MaterialApp(
      title: 'PaypalPaymentDemp',
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: TextButton(
            onPressed: () {
              Navigator.of(context).push(MaterialPageRoute(
                builder: (BuildContext context) => PaypalCheckoutView(
                  sandboxMode: true,
                  clientId: "AavaGu643froxEOY4fAMh2_hecYDburIg8gMt3lmxcgoGHfKFONRKl-D3RfbmTo9EheoYOKa_z4urN84",
                  secretKey: "EFHdjCdQbRCJjwue6DBnn7LkLbnVa38Zt4RRm1JUWP9HqMbHl0d4swotKZ7D69GCSDCgspD9dGVzi5b-",
                  transactions: const [
                    {
                      "amount": {
                        "total": '1',
                        "currency": "EUR",
                        "details": {
                          "subtotal": '1',
                          "shipping": '0',
                          "shipping_discount": 0
                        }
                      },
                      "description": "Android",
                      // "payment_options": {
                      //   "allowed_payment_method":
                      //       "INSTANT_FUNDING_SOURCE"
                      // },
                      "item_list": {
                        "items": [
                          {
                            "name": "Cappuchino",
                            "quantity": 1,
                            "price": '1',
                            "currency": "EUR"
                          },

                        ],

                        // Optional
                        //   "shipping_address": {
                        //     "recipient_name": "Tharwat samy",
                        //     "line1": "tharwat",
                        //     "line2": "",
                        //     "city": "tharwat",
                        //     "country_code": "EG",
                        //     "postal_code": "25025",
                        //     "phone": "+00000000",
                        //     "state": "ALex"
                        //  },
                      }
                    }
                  ],
                  note: "Contact us for any questions on your order.",
                  onSuccess: (Map params) async {
                    logging.insertElement("onSuccess: $params");
                    Navigator.pop(context);
                  },
                  onError: (error) {
                    logging.insertElement("onError: $error");
                    Navigator.pop(context);
                  },
                  onCancel: () {
                    print('cancelled:');
                    Navigator.pop(context);
                  },
                ),
              ));
            },
            child: const Text('Pay with paypal'),
          ),


        ),
      ),
    );
  }
}


