import re
import sys
import argparse
import os
import stat
from dataclasses import dataclass
from typing import List, Union, Tuple
import shutil
from pathlib import Path


# One element per monitor
# swaybar: background
sway_color_bar_background = 0
# swaybar: statusline
sway_color_bar_statusline = 1
#swaybar: focused_background
sway_color_bar_focused_background = 2
#swaybar: focused_statusbar
sway_color_bar_focused_statusline = 3
#swaybar: focused_workspace
sway_color_bar_workspace_focused_border = 4
sway_color_bar_workspace_focused_background = 5
sway_color_bar_workspace_focused_text = 6
#swaybar: active_workspace
sway_color_bar_workspace_active_border = 7
sway_color_bar_workspace_active_background = 8
sway_color_bar_workspace_active_text = 9
#swaybar: inactive_workspace
sway_color_bar_workspace_inactive_border = 10
sway_color_bar_workspace_inactive_background = 11
sway_color_bar_workspace_inactive_text = 12
#swaybar: urgent_workspace
sway_color_bar_workspace_urgent_border = 13
sway_color_bar_workspace_urgent_background = 14
sway_color_bar_workspace_urgent_text = 15
#swaybar: binding_mode
sway_color_bar_mode_indicator_border = 16
sway_color_bar_mode_indicator_background = 17
sway_color_bar_mode_indicator_text = 18
# n when constructing my ColorSchemeSearchConf
sway_color_n = 19


if __name__ == "__main__":
    arg_parser = argparse.ArgumentParser(description="Activate a precompiled colorscheme for sway")
    # todo: continue from here (We almost finished)
    arg_parser.add_argument('wallpaper_path')
    arg_parser.add_argument('themes_path', help='Path to the colorscheme file')
    arg_parser.add_argument('config_output_path', help='Path for the output config file')
    arg_parser.add_argument('bar_name', help="Which bar to configure", nargs='?', default='*')

    # Optional flag arguments (no arguments)
    arg_parser.add_argument('--message', action='store_true', help='Use swaymsg to send colorscheme immediately')
    args = arg_parser.parse_args()

    with open(args.colorscheme_path, 'r') as f:
        colors = list(filter(lambda line: len(line) > 0, f.readlines()))

    config_text = f"""bar {args.bar_name} colors """
    assert len(colors) == sway_color_n

