
import 'package:cpt_property/modules/news/vm/property_news_vm.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:flutter/cupertino.dart';
import 'package:plugin_platform/engine/toast/toast_engine.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:shared/utils/log_utils.dart';

import '../../ioan/property_ioan_page.dart';
import '../../news/page/property_news_page.dart';
import '../../rent/page/property_rent_page.dart';
import '../../sale/page/property_sale_page.dart';
import '../page/property_page.dart';
import '../page/property_page_state.dart';

part 'property_vm.g.dart';

@riverpod
class PropertyVm extends _$PropertyVm {
  get topSectionsData => state.topSectionsData;

  Map<String, dynamic> _newsQueryMap = {
    "isCollection": 0, // 0 全部 1 已收藏
  };

  PropertyVmState initState() {
    return PropertyVmState();
  }

  @override
  PropertyVmState build(){
    final state = initState();
    Log.d("--------------------------build---------------------");

    // 初始时导航到子路由
    WidgetsBinding.instance.addPostFrameCallback((_) {
    });

    return state;
  }

  tabsRouterChange(){
    // 设置当前导航栏的 图标 等状态
    Log.d("----tabsRouterChange---${tabsRouterKey.currentState?.controller?.activeIndex}-");
    state = state.copyWith(currentPageViewIdx: tabsRouterKey.currentState?.controller?.activeIndex ?? 0);
  }

  // 点击了导航的 搜索 进行筛选
  handlerCollectionFilter(BuildContext? context, int isCollection ){
    _newsQueryMap['isCollection'] = isCollection;

    // 重新加载数据
    final newsPageVm = ref.read(propertyNewsVmProvider.notifier);
    newsPageVm..changeQueryMap({
      "isCollection": _newsQueryMap['isCollection'],
    })..retryRequest();
  }

}

