import { Command } from 'commander'
import prompts from 'prompts'
import path from 'path'
import fs from 'fs-extra'
import { zodSchema } from '../utils/schema'
import ora from 'ora'
import { bismillahConfigSchema } from '../utils/schema'

export const init = new Command()
    .name('init')
    .description('Initialize your bismillahcss project')
    .action(async () => {
        const response = await prompts([
            {
                type: 'text',
                name: 'stylePath',
                message: 'Where is your global CSS file?',
                initial: './src/index.css'
            },
            {
                type: 'toggle',
                name: 'darkMode',
                message: 'Enable dark mode?',
                initial: true,
                active: 'yes',
                inactive: 'no'
            }
        ])

        const spinner = ora('Initializing bismillahcss...').start()

        const config = {
            style: response.stylePath,
            darkMode: response.darkMode,
            theme: 'futuristic'
        }

        // Validate config
        const validated = bismillahConfigSchema.parse(config)

        await fs.writeJSON(path.join(process.cwd(), 'bismillah.config.json'), validated, { spaces: 2 })

        spinner.succeed('bismillahcss initialized successfully!')
    })
