use lightningcss::printer::PrinterOptions;
use lightningcss::stylesheet::{MinifyOptions, ParserOptions, StyleSheet};
use std::error::Error;

pub fn minify(file_string: &str) -> Result<String, Box<dyn Error + '_>> {
    let mut stylesheet = StyleSheet::parse(file_string, ParserOptions::default())?;
    stylesheet.minify(MinifyOptions::default())?;

    let res = stylesheet.to_css(PrinterOptions {
        minify: true,
        ..PrinterOptions::default()
    })?;

    Ok(res.code)
}
