// tools/define-ui-contract-mobile.ts — Mobile UI contract generation (SPEC-013)
// Contains mobile-specific contract generation for SwiftUI, UIKit, Jetpack Compose,
// Android XML Views, Flutter, and React Native.
export const MOBILE_FRAMEWORKS = new Set([
    'swiftui',
    'uikit',
    'jetpack-compose',
    'compose',
    'android-views',
    'xml-views',
    'flutter',
    'react-native',
]);
export function isMobileFramework(framework) {
    return MOBILE_FRAMEWORKS.has((framework ?? '').toLowerCase());
}
export function generateMobileUIContract(screens, knowledge) {
    const fw = (knowledge.framework ?? '').toLowerCase();
    const blocks = screens.map((screen) => {
        const name = toPascalCase(screen);
        return generateMobileScreenContract(name, fw);
    });
    return blocks.join('\n\n---\n\n');
}
function generateMobileScreenContract(name, fw) {
    if (fw === 'swiftui') {
        return (`## UI Contract — SwiftUI\n\n` +
            `### View: ${name}View\n\n` +
            `**Protocol:** \`View\`\n` +
            `**State Management:**\n` +
            `- \`@State\` — local ephemeral state\n` +
            `- \`@ObservedObject\` / \`@StateObject\` — ViewModel observation\n` +
            `- \`@EnvironmentObject\` — shared app-wide state\n` +
            `- \`@Binding\` — two-way parent→child binding\n\n` +
            `**Signature:**\n` +
            `\`\`\`swift\n` +
            `struct ${name}View: View {\n` +
            `    @StateObject private var viewModel = ${name}ViewModel()\n` +
            `    var body: some View { ... }\n` +
            `}\n` +
            `\`\`\`\n\n` +
            `**Data Flow:** ViewModel → @Published → View (re-renders on change)\n` +
            `**Environment Values:** colorScheme, sizeCategory, dismiss, navigationPath`);
    }
    if (fw === 'uikit') {
        return (`## UI Contract — UIKit\n\n` +
            `### ViewController: ${name}ViewController\n\n` +
            `**Subclass:** \`UIViewController\`\n` +
            `**Lifecycle:** viewDidLoad → viewWillAppear → viewDidAppear\n` +
            `**Configuration:** \`setupUI()\`, \`bindViewModel()\`\n` +
            `**IBOutlets:** \`@IBOutlet weak var titleLabel: UILabel!\`\n` +
            `**IBActions:** \`@IBAction func primaryButtonTapped(_ sender: UIButton)\`\n` +
            `**Data Flow:** ViewModel → closures/delegates → UIViewController`);
    }
    if (fw === 'jetpack-compose' || fw === 'compose') {
        return (`## UI Contract — Jetpack Compose\n\n` +
            `### Composable: ${name}Screen\n\n` +
            `**Type:** Stateful Composable\n` +
            `**Signature:**\n` +
            `\`\`\`kotlin\n` +
            `@Composable\n` +
            `fun ${name}Screen(\n` +
            `    viewModel: ${name}ViewModel = hiltViewModel(),\n` +
            `    onNavigateBack: () -> Unit\n` +
            `) {\n` +
            `    val uiState by viewModel.uiState.collectAsStateWithLifecycle()\n` +
            `    ${name}Content(uiState = uiState, onAction = viewModel::onAction)\n` +
            `}\n` +
            `\`\`\`\n\n` +
            `**State Hoisting:** Stateless \`${name}Content\` composable receives state + lambdas\n` +
            `**Events:** Sealed \`${name}Action\` class for user interactions\n` +
            `**Side Effects:** \`LaunchedEffect\`, \`DisposableEffect\` for lifecycle-aware operations`);
    }
    if (fw === 'android-views' || fw === 'xml-views') {
        return (`## UI Contract — Android XML Views\n\n` +
            `### Fragment: ${name}Fragment\n\n` +
            `**Binding:** \`Fragment${name}Binding\` (ViewBinding)\n` +
            `**ViewModel:** \`${name}ViewModel\` via \`by viewModels()\`\n` +
            `**Observers:**\n` +
            `\`\`\`kotlin\n` +
            `viewModel.uiState.observe(viewLifecycleOwner) { state -> render(state) }\n` +
            `\`\`\`\n` +
            `**Navigation:** NavController with SafeArgs`);
    }
    if (fw === 'flutter') {
        return (`## UI Contract — Flutter\n\n` +
            `### Widget: ${name}Screen\n\n` +
            `**Type:** StatefulWidget or ConsumerWidget (Riverpod)\n` +
            `**State:** \`${name}Controller\` via StateNotifier / Cubit\n` +
            `**Navigation:** \`GoRouter\` named route\n` +
            `**Data Flow:** Provider/Riverpod → Widget rebuild on state change`);
    }
    if (fw === 'react-native') {
        return (`## UI Contract — React Native\n\n` +
            `### Screen: ${name}Screen\n\n` +
            `**Navigation:** React Navigation — Stack / Tab / Drawer\n` +
            `**State:** Zustand / Redux Toolkit / Context\n` +
            `**Signature:**\n` +
            `\`\`\`tsx\n` +
            `export function ${name}Screen(): React.JSX.Element {\n` +
            `  const { data, isLoading } = use${name}();\n` +
            `  return <${name}View data={data} isLoading={isLoading} />;\n` +
            `}\n` +
            `\`\`\`\n` +
            `**Data Flow:** Custom hook → state → presentational component`);
    }
    return `## UI Contract — Mobile (${fw})\n\n### Screen: ${name}Screen\n\nNo specific contract template available for framework: ${fw}`;
}
function toPascalCase(str) {
    return str
        .split(/[-_\s]+/)
        .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
        .join('');
}
//# sourceMappingURL=define-ui-contract-mobile.js.map