import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yumi/modules/user/my_items/theme/bags_tab_theme_page.dart';
import 'package:tancent_vap/utils/constant.dart';
import 'package:tancent_vap/widgets/vap_view.dart';

import 'package:yumi/app_localizations.dart';
import 'package:yumi/ui_kit/components/appbar/socialchat_appbar.dart';
import 'package:yumi/ui_kit/components/sc_compontent.dart';
import 'package:yumi/ui_kit/theme/socialchat_theme.dart';
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
import 'package:yumi/shared/tools/sc_path_utils.dart';
import 'package:yumi/shared/data_sources/sources/local/file_cache_manager.dart';
import 'package:yumi/ui_kit/widgets/headdress/headdress_widget.dart';
import 'package:yumi/modules/store/store_route.dart';
import 'package:yumi/modules/user/my_items/chatbox/bags_chatbox_page.dart';
import 'package:yumi/modules/user/my_items/headdress/bags_headdress_page.dart';
import 'package:yumi/modules/user/my_items/mountains/bags_mountains_page.dart';

import '../../../app/constants/sc_global_config.dart';
import '../../../shared/business_logic/usecases/sc_fixed_width_tabIndicator.dart';

class MyItemsPage extends StatefulWidget {
  @override
  _MyItemsPageState createState() => _MyItemsPageState();
}

class _MyItemsPageState extends State<MyItemsPage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  final List<Widget> _pages = [];
  final List<Widget> _tabs = [];

  @override
  void initState() {
    super.initState();
    _pages.add(BagsHeaddressPage());
    _pages.add(
      BagsMountainsPage(),
    );
    _pages.add(
      BagsTabThemePage(),
    );
    _pages.add(BagsChatboxPage());
    _tabController = TabController(length: _pages.length, vsync: this);
    _tabController.addListener(() {
    });
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    _tabs.clear();
    _tabs.add(Tab(text: SCAppLocalizations.of(context)!.headdress));
    _tabs.add(Tab(text: SCAppLocalizations.of(context)!.mountains));
    _tabs.add(Tab(text: SCAppLocalizations.of(context)!.theme));
    _tabs.add(Tab(text: SCAppLocalizations.of(context)!.chatBox));
    return Stack(
      children: [
        Image.asset(
          SCGlobalConfig.businessLogicStrategy.getLanguagePageBackgroundImage(),
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().screenHeight,
          fit: BoxFit.fill,
        ),
        Scaffold(
          backgroundColor: Colors.transparent,
          resizeToAvoidBottomInset: false,
          appBar: SocialChatStandardAppBar(
            title: SCAppLocalizations.of(context)!.myItems,
            actions: [
              GestureDetector(
                behavior: HitTestBehavior.opaque,
                child: Container(
                  padding: EdgeInsets.all(5.w),
                  margin: EdgeInsetsDirectional.only(end: 10.w),
                  child: Image.asset(
                    "sc_images/store/sc_icon_bag_shop.png",
                    width: 20.w,
                    height: 20.w,
                  ),
                ),
                onTap: () {
                  SCNavigatorUtils.push(context, StoreRoute.list, replace: true);
                },
              ),
            ],
          ),
          body: SafeArea(top:false,child: Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  TabBar(
                    tabAlignment: TabAlignment.center,
                    isScrollable: true,
                    labelColor: Colors.white,
                    unselectedLabelStyle: SCGlobalConfig.businessLogicStrategy
                        .getStorePageTabUnselectedLabelStyle()
                        .copyWith(
                      fontSize:
                      SCGlobalConfig.businessLogicStrategy
                          .getStorePageTabUnselectedLabelStyle()
                          .fontSize
                          ?.sp,
                    ),
                    // indicatorPadding: EdgeInsets.symmetric(
                    //   vertical: 5.w,
                    //   horizontal: 15.w,
                    // ),
                    indicator: SCFixedWidthTabIndicator(
                      width: 15.w,
                      color:
                      SCGlobalConfig.businessLogicStrategy
                          .getStorePageTabIndicatorColor(),
                    ),
                    dividerColor:
                    SCGlobalConfig.businessLogicStrategy
                        .getStorePageTabDividerColor(),
                    controller: _tabController,
                    tabs: _tabs,
                  ),
                ],
              ),
              SizedBox(height: 5.w),
              Expanded(
                child: TabBarView(controller: _tabController, children: _pages),
              ),
            ],
          ),),
        ),
      ],
    );
  }
}
