import type { ScreenshotType } from "./types";

export type KnownScreenshotType = Exclude<ScreenshotType, "unknown">;

export type ScreenshotCropZone = {
  key: string;
  label: string;
  purpose: "context" | "table" | "rows";
  xPct: number;
  yPct: number;
  widthPct: number;
  heightPct: number;
};

export type ScreenshotTableColumn = {
  key: string;
  label: string;
};

export type ScreenshotCropTemplate = {
  screenshotType: KnownScreenshotType;
  label: string;
  sourceShape: "full_screen" | "wide_table_strip";
  zones: ScreenshotCropZone[];
  columns: ScreenshotTableColumn[];
};

export const SCREENSHOT_TEMPLATE_VERSION = 3;

export const SCREENSHOT_CROP_TEMPLATES: Record<
  KnownScreenshotType,
  ScreenshotCropTemplate
> = {
  highlight_list: {
    screenshotType: "highlight_list",
    label: "Highlight List",
    sourceShape: "full_screen",
    zones: [
      {
        key: "score_banner",
        label: "Score Banner",
        purpose: "context",
        xPct: 0,
        yPct: 0,
        widthPct: 100,
        heightPct: 34
      },
      {
        key: "highlight_rows",
        label: "Highlight Rows",
        purpose: "rows",
        xPct: 7,
        yPct: 34,
        widthPct: 86,
        heightPct: 63
      }
    ],
    columns: [
      { key: "period", label: "Period" },
      { key: "clock", label: "Clock" },
      { key: "team", label: "Team" },
      { key: "summary", label: "Summary" },
      { key: "score", label: "Score" }
    ]
  },
  passing_stats: {
    screenshotType: "passing_stats",
    label: "Passing Stats",
    sourceShape: "wide_table_strip",
    zones: [
      {
        key: "table_header",
        label: "Table Header",
        purpose: "context",
        xPct: 2,
        yPct: 0,
        widthPct: 96,
        heightPct: 17
      },
      {
        key: "stat_rows",
        label: "Stat Rows",
        purpose: "rows",
        xPct: 3,
        yPct: 17,
        widthPct: 94,
        heightPct: 80
      }
    ],
    columns: [
      { key: "player", label: "Player" },
      { key: "team", label: "Team" },
      { key: "rating", label: "Rating" },
      { key: "completed", label: "Comp" },
      { key: "attempts", label: "Att" },
      { key: "yards", label: "Yds" },
      { key: "completion_pct", label: "Comp%" },
      { key: "touchdowns", label: "TD" },
      { key: "interceptions", label: "INT" },
      { key: "average", label: "Avg" }
    ]
  },
  rushing_stats: {
    screenshotType: "rushing_stats",
    label: "Rushing Stats",
    sourceShape: "wide_table_strip",
    zones: [
      {
        key: "table_header",
        label: "Table Header",
        purpose: "context",
        xPct: 2,
        yPct: 0,
        widthPct: 96,
        heightPct: 15
      },
      {
        key: "stat_rows",
        label: "Stat Rows",
        purpose: "rows",
        xPct: 3,
        yPct: 11,
        widthPct: 94,
        heightPct: 86
      }
    ],
    columns: [
      { key: "player", label: "Player" },
      { key: "team", label: "Team" },
      { key: "attempts", label: "Att" },
      { key: "yards", label: "Yds" },
      { key: "average", label: "Avg" },
      { key: "touchdowns", label: "TD" },
      { key: "fumbles", label: "Fum" },
      { key: "broken_tackles", label: "BTK" },
      { key: "yards_after_contact", label: "YAC" },
      { key: "twenty_plus_yards", label: "20+Yds" },
      { key: "long", label: "LC" }
    ]
  },
  receiving_stats: {
    screenshotType: "receiving_stats",
    label: "Receiving Stats",
    sourceShape: "wide_table_strip",
    zones: [
      {
        key: "table_header",
        label: "Table Header",
        purpose: "context",
        xPct: 2,
        yPct: 0,
        widthPct: 96,
        heightPct: 15
      },
      {
        key: "stat_rows",
        label: "Stat Rows",
        purpose: "rows",
        xPct: 3,
        yPct: 10,
        widthPct: 94,
        heightPct: 87
      }
    ],
    columns: [
      { key: "player", label: "Player" },
      { key: "team", label: "Team" },
      { key: "receptions", label: "Rec" },
      { key: "yards", label: "Yds" },
      { key: "average", label: "Avg" },
      { key: "touchdowns", label: "TD" },
      { key: "rac", label: "RAC" },
      { key: "rac_average", label: "RAC Avg" },
      { key: "drops", label: "Drop" },
      { key: "long", label: "Long" }
    ]
  }
};

export function getScreenshotCropTemplate(
  screenshotType: ScreenshotType
): ScreenshotCropTemplate | null {
  if (screenshotType === "unknown") return null;
  return SCREENSHOT_CROP_TEMPLATES[screenshotType];
}
