import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:url_launcher/url_launcher_string.dart';

import '../../app_style/app_color.dart';

class ContactUsBottomSheet extends StatelessWidget {
  const ContactUsBottomSheet({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // String contactNumber = "+966 546345567";
    String contactNumber = "";
    return Container(
      clipBehavior: Clip.antiAlias,
      decoration: BoxDecoration(
        color: Theme.of(context).scaffoldBackgroundColor,
        borderRadius: const BorderRadius.only(
          topRight: Radius.circular(30),
          topLeft: Radius.circular(30),
        ),
      ),
      padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            width: 40.toScreenWidth,
            height: 5.toScreenHeight,
            decoration: BoxDecoration(color: AppColor.neutral40, borderRadius: BorderRadius.circular(30)),
          ),
          16.height,
          Align(
            alignment: AlignmentDirectional.centerStart,
            child: Text(
              context.translation.contact,
              style: AppTextStyles.heading3.copyWith(fontWeight: FontWeight.w600, color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
            ),
          ),
          16.height,
          // Row(
          //   children: [
          //     contactItem(context, context.isDark, "phone", context.translation.callUs, contactNumber).onPress(() {
          //
          //       return;
          //       launchUrlString("tel://$contactNumber");
          //     }).expanded,
          //     16.width,
          //     contactItem(context, context.isDark, "whatsapp", context.translation.liveChat, context.translation.openWhatsapp).onPress(() {
          //       _launchWhatsapp(contactNumber);
          //     }).expanded,
          //   ],
          // ),
          32.height,
        ],
      ),
    );
  }

  void _launchWhatsapp(String number) async {
    var whatsappUrl = "https://wa.me/$number/?text=${Uri.parse("Hi, I need some help")}";
    try {
      if (await canLaunchUrlString(whatsappUrl)) {
        await launchUrlString(whatsappUrl);
      } else {
        throw 'Could not launch $whatsappUrl';
      }
    } catch (e) {
      print('Error launching WhatsApp: $e');
    }
  }

  Widget contactItem(BuildContext context, bool isDark, String iconName, String title, String subtitle) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SvgPicture.asset(
          "assets/images/$iconName.svg",
          width: 32.toScreenWidth,
          color: isDark ? AppColor.primary40 : AppColor.primary70,
        ),
        30.height,
        Text(
          title,
          style: AppTextStyles.heading6.copyWith(color: isDark ? AppColor.neutral30 : AppColor.neutral50),
        ),
        Text(
          subtitle,
          style: AppTextStyles.bodyText.copyWith(color: isDark ? AppColor.neutral10 : AppColor.neutral20),
        ),
      ],
    ).toShadowContainer(context);
  }
}
