import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../../app.dart';

final double appbarHeight = 96.h;

class FilterAppbarWidget extends StatelessWidget implements PreferredSizeWidget {
  const FilterAppbarWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<FilterController>(
      builder: (fc) => PreferredSize(
        preferredSize: Size.fromHeight(appbarHeight), // Set this height
        child: Container(
          padding: const EdgeInsets.all(8),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(5.0),
            color: Colors.white,
            boxShadow: [
              BoxShadow(
                color: Colors.grey,
                offset: Offset(0.0, 1.0), //(x,y)
                blurRadius: 2.0,
              ),
            ],
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              SizedBox(height: MediaQuery.of(context).padding.top),
              Row(
                children: [
                  // Icon(Icons.close, size: 24.sp, color: Colors.black),
                  Material(
                    color: Colors.transparent,
                    shape: CircleBorder(side: BorderSide(color: Colors.white)),
                    child: InkWell(
                      splashColor: Theme.of(context).splashColor,
                      borderRadius: BorderRadius.circular(50),
                      onTap: fc.onFilterPageClosed,
                      child: Container(
                        padding: const EdgeInsets.all(8),
                        decoration: new BoxDecoration(
                          shape: BoxShape.circle,
                        ),
                        child: Icon(
                          Icons.close,
                          size: 20.sp,
                          color: Colors.black,
                        ),
                      ),
                    ),
                  ),
                  SizedBox(width: 12),
                  Text(
                    'filter'.tr,
                    style: new TextStyle(
                      color: Colors.black,
                      fontSize: 20.sp,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ],
              ),
              SizedBox(height: 8.h),
              Row(
                children: [
                  SizedBox(width: 6),
                  CircleNumberWidget(number: fc.state.totalAppliedFilter.value),
                  SizedBox(width: 12),
                  Text(
                    'applied'.tr,
                    style: new TextStyle(
                      fontSize: 14.sp,
                      color: ThemeColor.color717278,
                    ),
                  ),
                  Spacer(),
                  fc.state.totalAppliedFilter.value != 0 && !fc.state.isFiltersLoading.value
                      ? SizedBox(
                          height: 30.h,
                          child: TextButton(
                            child: Text('clear'.tr),
                            style: TextButton.styleFrom(foregroundColor: ThemeColor.mainColor),
                            onPressed: fc.clearAllFilters,
                          ),
                        )
                      : SizedBox.shrink(),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(appbarHeight);
}
