import 'package:account_center/style/widget/my_app_bar.dart';
import 'package:account_center/widget/asset_image_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';
import 'package:flutter_clx_base/widget/my_refresh_list_public.dart';

import 'new_enterprise_record_logic.dart';

///创建企业记录
class NewEnterpriseRecordPage extends StatelessWidget {
  final logic = Get.find<NewEnterpriseRecordLogic>();
  final state = Get.find<NewEnterpriseRecordLogic>().state;

  NewEnterpriseRecordPage({super.key});

  @override
  Widget build(BuildContext context) {
    return MyScaffold(
      appBar: MyAppBar('创建企业记录'),
      body: _bodyContent(),
    );
  }

  Widget _bodyContent() {
    return MyListViewPublic(itemBuilder: (context, index, item) {
      return _itemView(item);
    }, requestData: (page, pageSize, success, error) {
      logic.enterpriseRecordList(page, pageSize, success);
    });
  }

  Widget _itemView(dynamic item) {
    return Container(
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(8)),
      margin: EdgeInsets.only(left: 10, top: 10, right: 10),
      padding: EdgeInsets.all(20),
      child: InkWell(
        borderRadius: BorderRadius.all(Radius.circular(10)),
        onTap: () {
          logic.goToEnterpriseSee(item['id']);
        },
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                AssetImageWidget(
                  width: 54,
                  height: 18,
                  imgFileName: logic.authStateIcon(
                    item['authStatus'],
                  ),
                ),
                hGap8,
                Expanded(
                    child: Text(
                  item['companyName'],
                  style: TextStyle(color: Color(0xFF171A1D), fontSize: 16),
                ))
              ],
            ),
            Visibility(
              visible: item['authStatus'] == 30 &&
                  item['authContent']?.toString().isNotEmpty == true,
              child: Container(
                width: double.infinity,
                margin: EdgeInsets.only(top: 10),
                decoration: BoxDecoration(
                  color: Color(0xFFFFF2F4),
                  borderRadius: BorderRadius.circular(4),
                ),
                padding: EdgeInsets.symmetric(vertical: 8, horizontal: 10),
                child: Text(
                  item['authContent'] ?? '-',
                  style: TextStyle(color: Color(0xFFF48182), fontSize: 12),
                ),
              ),
            ),
            _contentRow('代理人：',
                '${item['agentName'] ?? '-'}  ${item['agentMobile'] ?? '-'}'),
            _contentRow('申请时间：', item['createTime'] ?? '-'),
            _contentRow('申请编号：', item['applyNo'] ?? '-'),
          ],
        ),
      ),
    );
  }

  Widget _contentRow(String title, String content) {
    return Container(
      margin: EdgeInsets.only(top: 10),
      child: Row(
        children: [
          Text(
            title,
            style: TextStyle(fontSize: 12, color: const Color(0xFF68717C)),
          ),
          hGap5,
          Text(content),
        ],
      ),
    );
  }
}
