Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

7.4 KB
Raw Blame
import 'package:harness/shared/theme/app_icons.dart';
import 'package:flutter/material.dart';
import 'package:harness/terminal/terminal_text.dart';

import '../core/dsh_catalog.dart';
import '../shared/theme/app_theme.dart' as grid;
import '../widgets/engine_identity.dart';
import 'store_editorial.dart';
import 'store_models.dart';

/// One consistent app identity across discovery, categories, and search.
/// Vendor marks retain their aspect ratio and their light/dark treatments.
class StoreAppIcon extends StatelessWidget {
  const StoreAppIcon({super.key, required this.entry, this.size = 56});
  final DshEntry entry;
  final double size;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: size,
      height: size,
      padding: EdgeInsets.all(size * .12),
      decoration: BoxDecoration(
        color: grid.AppSurface.recess,
        borderRadius: BorderRadius.circular(size * .23),
        border: Border.all(color: grid.AppPalette.divider),
      ),
      child: EngineMark(
        engine: entry.id,
        displayName: entry.name,
        size: size * .76,
      ),
    );
  }
}

/// Icon rows are the default catalog presentation. Reserve large imagery for
/// editorial features, so tools with different output formats scan alike.
class StoreListing extends StatelessWidget {
  const StoreListing({
    super.key,
    required this.entries,
    required this.ratingFor,
    required this.onOpen,
    this.rowKeyPrefix = 'store-card',
    this.showRanks = false,
    this.actionFor,
  });
  final List<DshEntry> entries;
  final StoreRating Function(DshEntry) ratingFor;
  final ValueChanged<String> onOpen;
  final String rowKeyPrefix;
  final bool showRanks;

  /// A button at the end of a row, for an entry that acts in one click (the Store's Essentials).
  final Widget? Function(DshEntry entry)? actionFor;

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, box) {
        final scale = grid.appTextScaleOf(context);
        final columns = (box.maxWidth / (340 * scale)).floor().clamp(1, 3);
        final width = (box.maxWidth - (columns - 1) * 28) / columns;
        final reserveRating = entries.any((entry) => !ratingFor(entry).isEmpty);
        final reserveUpdate = entries.any((entry) => entry.hasUpdate);
        return Wrap(
          spacing: 28,
          children: [
            for (final entry in entries)
              SizedBox(
                width: width,
                child: _ProductRow(
                  key: ValueKey('$rowKeyPrefix:${entry.id}'),
                  rank: showRanks ? entries.indexOf(entry) + 1 : null,
                  entry: entry,
                  rating: ratingFor(entry),
                  reserveRating: reserveRating,
                  reserveUpdate: reserveUpdate,
                  onOpen: () => onOpen(entry.id),
                  action: actionFor?.call(entry),
                ),
              ),
          ],
        );
      },
    );
  }
}

class _ProductRow extends StatelessWidget {
  const _ProductRow({
    super.key,
    required this.entry,
    required this.rating,
    required this.reserveRating,
    required this.reserveUpdate,
    required this.onOpen,
    this.rank,
    this.action,
  });
  final DshEntry entry;
  final StoreRating rating;
  final bool reserveRating;
  final bool reserveUpdate;
  final VoidCallback onOpen;
  final int? rank;
  final Widget? action;

  @override
  Widget build(BuildContext context) {
    TerminalFontScope.watch(context);
    final scale = grid.appTextScaleOf(context);
    final benefit = entry.isEngine
        ? entry.tagline ??
              engineIdentity(entry.id).tagline ??
              storeBenefit(entry)
        : storeBrowseBenefit(entry);
    return Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: onOpen,
        borderRadius: BorderRadius.circular(12),
        child: Container(
          padding: const EdgeInsets.symmetric(vertical: 18, horizontal: 4),
          decoration: BoxDecoration(
            border: Border(bottom: BorderSide(color: grid.AppPalette.divider)),
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              if (rank != null) ...[
                SizedBox(
                  width: 18,
                  child: Text(
                    '$rank',
                    style: grid.AppType.label(
                      color: grid.AppPalette.textSecondary,
                    ),
                  ),
                ),
                const SizedBox(width: 6),
              ],
              StoreAppIcon(entry: entry),
              const SizedBox(width: 14),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Tooltip(
                      message: entry.name,
                      child: Text(
                        entry.name,
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        style: grid.AppType.label(
                          color: grid.AppPalette.textPrimary,
                        ),
                      ),
                    ),
                    const SizedBox(height: 4),
                    // Two lines of the description: 2 × 13 × 1.3.
                    SizedBox(
                      height: 34 * scale,
                      child: Text(
                        benefit,
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                        style: grid.AppType.body(
                          height: 1.3,
                          color: grid.AppPalette.textSecondary,
                        ),
                      ),
                    ),
                    if (reserveUpdate) ...[
                      const SizedBox(height: 4),
                      Text(
                        entry.hasUpdate ? 'Update available' : ' ',
                        style: grid.AppType.body(
                          color: grid.AppPalette.accentOnSurface,
                        ),
                      ),
                    ],
                    if (reserveRating) ...[
                      const SizedBox(height: 4),
                      SizedBox(
                        height: 14 * scale,
                        child: rating.isEmpty
                            ? null
                            : Row(
                                children: [
                                  Icon(
                                    AppIcons.star,
                                    size: 12,
                                    color: grid.AppPalette.textSecondary,
                                  ),
                                  const SizedBox(width: 3),
                                  Text(
                                    '${rating.average.toStringAsFixed(1)} · ${rating.count}',
                                    style: grid.AppType.caption(
                                      color: grid.AppPalette.textSecondary,
                                    ),
                                  ),
                                ],
                              ),
                      ),
                    ],
                  ],
                ),
              ),
              if (action != null) ...[const SizedBox(width: 12), action!],
            ],
          ),
        ),
      ),
    );
  }
}