import 'package:electronic_assistant/data/bean/agenda.dart';
import 'package:electronic_assistant/utils/expand.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../resource/assets.gen.dart';
import '../../resource/colors.gen.dart';
import '../../resource/string.gen.dart';
import '../../utils/common_style.dart';

Widget taskItemView(Agenda item,
    {VoidCallback? onCheckClick,
    VoidCallback? onThinkingClick,
    bool? isShowAnalyse,
    bool isLimitLines = true}) {
  return Container(
    padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 17).w,
    margin: const EdgeInsets.only(left: 12, right: 12, bottom: 8).w,
    decoration: BoxDecoration(
      color: Colors.white,
      borderRadius: BorderRadius.circular(8),
    ),
    child: Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        GestureDetector(
          onTap: onCheckClick,
          child: _buildCheckBox(item.agendaStatus?.value),
        ),
        Visibility(
          visible: item.isExample.isTrue,
          child: Container(
            decoration: BoxDecoration(
              color: "#B2BAC4".toColor(),
              borderRadius: BorderRadius.circular(4),
            ),
            padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3).w,
            child: Text(
              StringName.homeTalkExample.tr,
              style:
                  TextStyle(fontSize: 12.sp, color: ColorName.white, height: 1),
            ),
          ),
        ),
        SizedBox(width: 6.w),
        Expanded(
          child: Padding(
            padding: const EdgeInsets.only(right: 12).w,
            child: Text(item.content ?? '',
                maxLines: isLimitLines ? 1 : null,
                overflow: isLimitLines ? TextOverflow.ellipsis : null,
                style: TextStyle(
                    fontSize: 15.sp,
                    fontWeight: FontWeight.bold,
                    color: ColorName.primaryTextColor)),
          ),
        ),
        Visibility(
          visible: isShowAnalyse ?? true,
          child: GestureDetector(
            onTap: onThinkingClick,
            child: Container(
              decoration: getPrimaryBtnDecoration(6),
              padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 5).w,
              child: Text(
                StringName.homeTalkThinking.tr,
                style: TextStyle(fontSize: 13.sp, color: ColorName.white),
              ),
            ),
          ),
        )
      ],
    ),
  );
}

Widget _buildCheckBox(AgendaStatus? status) {
  if (status == AgendaStatus.todo) {
    return Container(
        margin: EdgeInsets.only(right: 6.w),
        width: 20.w,
        height: 20.w,
        child: Assets.images.iconAgentUnderway.image());
  } else if (status == AgendaStatus.done) {
    return Container(
        margin: EdgeInsets.only(right: 6.w),
        width: 20.w,
        height: 20.w,
        child: Assets.images.iconAgentDone.image());
  } else {
    return Container();
  }
}
