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

class PersonalDetailTopBar extends StatefulWidget {
  final TabController controller;
  final ValueChanged<int>? onTap;
  final String customTimeStr;
  final bool? hasAll;
  const PersonalDetailTopBar(
      {super.key, required this.controller, this.onTap, required this.customTimeStr, this.hasAll = false});

  @override
  State<PersonalDetailTopBar> createState() => _PersonalDetailTopBarState();
}

class _PersonalDetailTopBarState extends State<PersonalDetailTopBar> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.centerLeft,
      decoration: BoxDecoration(border: Border(bottom: BorderSide(width: 1.r, color: const Color(0xFFCCCCCC)))),
      child: TabBar(
        controller: widget.controller,
        dividerHeight: 0,
        tabAlignment: TabAlignment.start,
        unselectedLabelStyle: TextStyle(fontSize: 12.sp, color: const Color.fromRGBO(102, 102, 102, 1)),
        labelStyle: TextStyle(
          fontSize: 12.sp,
          fontWeight: FontWeight.bold,
          color: Theme.of(context).primaryColor,
        ),
        isScrollable: true,
        labelColor: Theme.of(context).primaryColor,
        unselectedLabelColor: const Color(0xFF505E6E),
        padding: EdgeInsets.symmetric(horizontal: 14.r),
        // indicatorSize: TabBarIndicatorSize.label, // 设置指示器高度和标签一样高
        onTap: widget.onTap,
        indicator: UnderlineTabIndicator(
          borderSide: BorderSide(width: 2.r, color: Theme.of(context).primaryColor),
        ),
        tabs: <Widget>[
          const Tab(text: '近一周'),
          const Tab(text: '近一月'),
          Tab(text: widget.customTimeStr),
          if (widget.hasAll == true) const Tab(text: '全部'),
        ],
      ),
    );
  }
}
