use vize_carton::String;
use vize_carton::append;
use vize_carton::cstr;
use crate::virtual_ts::helpers::to_safe_identifier;
pub(super) fn slot_props_type(
component: Option<&str>,
slot_name: &str,
slot_name_is_static: bool,
) -> String {
match component {
Some(component) => {
let component_ref = to_safe_identifier(component);
if slot_name_is_static {
cstr!(
"typeof {component_ref} extends {{ new (): {{ $slots: infer __S }} }} ? (__S extends {{ \"{slot_name}\"?: (props: infer __P, ...args: any[]) => any }} ? __P : any) : any"
)
} else {
cstr!(
"typeof {component_ref} extends {{ new (): {{ $slots: infer __S }} }} ? ({{ [__K in keyof __S]: NonNullable<__S[__K]> extends (props: infer __P, ...args: any[]) => any ? __P : never }}[keyof __S] extends infer __P ? ([__P] extends [never] ? any : __P) : any) : any"
)
}
}
None => "any".into(),
}
}
pub(super) fn append_v_for_comment(
ts: &mut String,
indent: &str,
label: &str,
alias: &str,
source: &str,
) {
append!(*ts, "\n{indent}// {label}: {alias} in ");
for c in source.chars() {
if c == '\n' || c == '\r' {
ts.push(' ');
} else {
ts.push(c);
}
}
ts.push('\n');
}
pub(super) fn emit_v_for_loop_open(
ts: &mut String,
indent: &str,
value_alias: &str,
key_alias: Option<&str>,
index_alias: Option<&str>,
source: &str,
) {
append!(*ts, "{indent}__vForList({source}).forEach(([{value_alias}");
if let Some(key) = key_alias {
append!(*ts, ", {key}");
} else if index_alias.is_some() {
ts.push_str(", _key");
}
if let Some(index) = index_alias {
append!(*ts, ", {index}");
}
ts.push_str("]) => {\n");
}