import 'dart:convert';
import 'dart:typed_data';

import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/utils/utils.dart';
import 'package:doctor_app_flutter/widgets/shared/card_with_bg_widget.dart';
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
import 'package:flutter/material.dart';

import '../shared/app_texts_widget.dart';
import '../shared/rounded_container_widget.dart';

class MedicineItemWidget extends StatefulWidget {
  final String label;
  final Color backgroundColor;
  final bool showBorder;
  final bool showArrow;
  final bool showPrice;
  final Color borderColor;
  final String url;
  final String price;

  MedicineItemWidget(
      {required this.label,
      this.backgroundColor = Colors.white,
      this.showBorder = true,
      this.borderColor = Colors.white,
      this.url = '',
      this.showArrow = true,
      this.showPrice = false,
      this.price = "0"});

  @override
  _MedicineItemWidgetState createState() => _MedicineItemWidgetState();
}

class _MedicineItemWidgetState extends State<MedicineItemWidget> {
  @override
  Widget build(BuildContext context) {
    return CardWithBgWidget(
      // height: SizeConfig.heightMultiplier! * 12.9,
      bgColor: Colors.transparent,
      hasBorder: false,
      widget: Padding(
        padding: const EdgeInsets.symmetric(
          vertical: 4,
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            if (widget.url != null)
              ClipRRect(
                  borderRadius: BorderRadius.circular(20.0),
                  child: Image.network(
                    widget.url,
                    height: 25,
                    width: 30,
                    errorBuilder: (BuildContext context, Object exception,
                        StackTrace? stackTrace) {
                      return Text('');
                    },
                  )),
            Expanded(
              child: Center(
                child: Padding(
                  padding: EdgeInsets.all(2.5),
                  child: Align(
                    alignment: Alignment.centerLeft,
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        AppText(
                          Utils.convertToTitleCase(widget.label ?? ''),
                          fontHeight: 1.4,
                          color: AppGlobal.appTextColor,
                          textAlign: TextAlign.start,
                          fontWeight: FontWeight.w600,
                          letterSpacing: -0.33,
                        ),
                        if (widget.showPrice)
                          AppText(
                            Utils.convertToTitleCase(widget.price ?? ''),
                            fontHeight: 1.4,
                            color: AppGlobal.appTextColor,
                            textAlign: TextAlign.start,
                            fontWeight: FontWeight.w600,
                            letterSpacing: -0.33,
                          ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            if (widget.showArrow) Icon(EvaIcons.arrowForward)
          ],
        ),
      ),
      // backgroundColor: widget.backgroundColor,
      // showBorder: widget.showBorder,
      // borderColor: widget.borderColor,
      // // margin: 4.0,
      // // margin: EdgeInsets.all(4),
      // raduis: 10,
    );
  }

  Image imageFromBase64String(String base64String) {
    return Image.memory(base64Decode(base64String));
  }

  Uint8List dataFromBase64String(String base64String) {
    return base64Decode(base64String);
  }

  String base64String(Uint8List data) {
    return base64Encode(data);
  }
}
