# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.

# %% auto 0
__all__ = ['create_readme', 'create_content_js', 'create_manifest', 'main']

# %% ../nbs/00_core.ipynb 3
from fastcore.script import *
from fastcore.utils import *
from pathlib import Path

def create_readme(path, name, desc, repo):
    "Create README.md with provided details"
    readme = f"""# {name}

{desc}

## Installation

1. Clone this repository:

```
git clone {repo}
```

2. Open Chrome and navigate to `chrome://extensions/`

3. Enable "Developer mode" in the top right corner

4. Click "Load unpacked" and select the directory containing the extension files

## Files

- `manifest.json` - Extension configuration
- `content.js` - The main script that handles the modifications
"""
    path.joinpath('README.md').write_text(readme)

def create_content_js(path):
    "Create content.js with basic structure"
    content = """// Run on page load
document.addEventListener('DOMContentLoaded', () => {
  // your functionality goes here
});
"""
    path.joinpath('content.js').write_text(content)

def create_manifest(path, name, desc, url):
    "Create manifest.json with provided details"
    manifest = {
        "manifest_version": 3,
        "name": name,
        "version": "1.0",
        "description": desc,
        "permissions": ["activeTab"],
        "content_scripts": [{
            "matches": [url],
            "js": ["content.js"]
        }]
    }
    path.joinpath('manifest.json').write_text(dumps(manifest, indent=2))

@call_parse
def main(
    name: Param("Name of the extension", str),
    desc: Param("Description of the extension", str)="",
    url: Param("URL pattern to match (e.g. https://example.com/*)", str)="<all_urls>",
    repo: Param("GitHub repository URL", str)="www.example.com"
):
    "Generate a new Chrome extension with basic structure"
    # Create directory
    path = Path(name)
    mkdir(path, exist_ok=True)
    
    # Create files
    create_readme(path, name, desc, repo)
    create_content_js(path)
    create_manifest(path, name, desc, url)
    
    print(f"Created Chrome extension '{name}' in directory: {path}")
