#!/usr/bin/env bash
# Flutter Wisetronic — Web 构建脚本
# 用法:
#   ./build_web.sh          # 构建 release 版本到 build/web/
#   ./build_web.sh run      # 构建并在 Chrome 中运行调试版
#
# 说明:
#   - 构建(release)必须 --no-tree-shake-icons: 项目中有 24 处 IconData(codePoint)
#     使用来自 JSON/API 的动态 code point(非 const), icon tree-shaking 无法处理。
#     注意: --no-tree-shake-icons 仅 build 支持; flutter run(debug)不做 tree-shaking,
#     因此 run 分支不带该 flag。
#   - Dart SDK: 本地 Flutter 3.29.3 / Dart 3.7.2(未升级全局 SDK)。
set -e
cd "$(dirname "$0")"

if [ "$1" = "run" ]; then
  echo ">>> flutter run -d chrome"
  flutter run -d chrome
else
  echo ">>> flutter build web --no-tree-shake-icons"
  flutter build web --no-tree-shake-icons
  echo ""
  echo "✓ 构建完成: build/web/  (main.dart.js: $(du -h build/web/main.dart.js | cut -f1))"
  echo "  本地预览: python3 -m http.server --directory build/web 8080"
  echo "  然后访问 http://localhost:8080/"
fi
