import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tone_snap/components/keep_alive_wrapper.dart';
import 'package:tone_snap/components/my_custom_indicator.dart';
import 'package:tone_snap/modules/sidea/widgets/head_label.dart';
import 'package:tone_snap/generated/assets.dart';
import 'package:tone_snap/modules/sidea/me/me_controller.dart';

class MeView extends GetView<MeController> {
  const MeView({super.key});

  @override
  Widget build(BuildContext context) {
    Get.put(MeController());

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        HeadLabel(
          assets: Assets.sideATheMonster1,
          width: 135.w,
          height: 51.h,
        ),
        _buildTabBar(),
        _buildTabBarView(),
      ],
    );
  }

  Widget _buildTabBar() {
    return TabBar(
      controller: controller.tabController,
      tabAlignment: TabAlignment.center,
      dividerHeight: 0,
      padding: const EdgeInsets.symmetric(horizontal: 8).w,
      labelPadding: const EdgeInsets.symmetric(horizontal: 16).w,
      labelStyle: TextStyle(
        color: Colors.white,
        fontSize: 20.sp,
        fontWeight: FontWeight.w600,
      ),
      unselectedLabelStyle: TextStyle(
        color: const Color(0x4DFFFFFF),
        fontSize: 20.sp,
        fontWeight: FontWeight.w600,
      ),
      indicatorPadding: EdgeInsets.fromLTRB(0, 4.h, 0, 0),
      indicator: MyCustomIndicator(
        indWidth: 16.w,
        indHeight: 4.h,
        radius: 3.5.r,
      ),
      tabs: controller.labels.map((e) => Tab(text: e)).toList(),
    );
  }

  Widget _buildTabBarView() {
    return Expanded(
      child: TabBarView(
        controller: controller.tabController,
        children: controller.pages.map((e) => KeepAliveWrapper(child: e)).toList(),
      ),
    );
  }
}
