#!/usr/bin/env python3
"""Initialize the captured Meowven palette without overwriting user choices."""
import os
from pathlib import Path
import shutil

home = Path.home()
config = home / '.config/chroma'
state = home / '.local/state/chroma'
state.mkdir(parents=True, exist_ok=True)
wall = home / 'Pictures/Themes/meowven.png'
wall.parent.mkdir(parents=True, exist_ok=True)
if not wall.exists() and not wall.is_symlink():
    wall.symlink_to('/usr/share/meowven/wallpaper.png')
for source in (config / 'defaults').iterdir():
    target = state / source.name
    if target.exists():
        continue
    if source.suffix == '.png':
        shutil.copyfile(source, target)
    else:
        target.write_text(source.read_text().replace('@WALLPAPER@', str(wall)))
if not (state / 'wallpaper').exists():
    (state / 'wallpaper').write_text(str(wall) + '\n')
for toolkit in ('gtk-3.0', 'gtk-4.0'):
    target = home / '.config' / toolkit / 'gtk.css'
    target.parent.mkdir(parents=True, exist_ok=True)
    if not target.exists():
        target.write_text('/* Meowven Chroma wallpaper colors */\n@import url("' + (state / 'gtk.css').as_uri() + '");\n')
