import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/widgets/search/appbar/model/search_appbar_model.dart';
import 'dart:ui';
import 'package:zhiying_comm/zhiying_comm.dart';

class SearchAppbarWidget extends StatelessWidget {
  final Map<String, dynamic> data;
  SearchAppbarModel model;

  SearchAppbarWidget(this.data, {Key key}) : super(key: key) {
    try {
      model = SearchAppbarModel.fromJson(jsonDecode(data['data']));
    } catch (e) {
      Logger.error(e);
    }
  }

  /// 返回键
  void _openPop(BuildContext context) {
    Navigator.maybePop(context);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      color: HexColor.fromHex(model?.app_bar_bg_color ?? '#FFFFFF'),
      padding: EdgeInsets.only(top: MediaQueryData.fromWindow(window).padding.top),
      child: _getMainWidget(context),
    );
  }

  /// 样式1
  Widget _getMainWidget(BuildContext context) {
    return AppBar(
      backgroundColor: Colors.transparent,
      elevation: 0,
      leading: IconButton(
        icon: Icon(
          Icons.arrow_back_ios,
          size: 22,
          color: HexColor.fromHex('#333333'),
        ),
        onPressed: () => _openPop(context),
      ),
      title: Text(
        model?.app_bar_title ?? '搜索',
        style: TextStyle(fontWeight: FontWeight.bold, color: HexColor.fromHex(model?.app_bar_title_color ?? '#333333')),
      ),
      centerTitle: true,
    );
  }
}
