#!/bin/bash
# PLANNER MODULE - PRIORITY 1 FIXES
# Execute this script to fix critical blocking issues
# Estimated time: 30 minutes

set -e

echo "🔧 PLANNER MODULE - PRIORITY 1 FIXES"
echo "===================================="
echo ""

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# 1. Delete orphan StageList.vue
echo "📝 Step 1/3: Removing orphan component StageList.vue"
if [ -f "apps/web/src/modules/planner/components/StageList.vue" ]; then
    rm apps/web/src/modules/planner/components/StageList.vue
    echo -e "${GREEN}✓ Deleted StageList.vue${NC}"
else
    echo -e "${YELLOW}⚠ StageList.vue already deleted${NC}"
fi
echo ""

# 2. Create shared components directory
echo "📝 Step 2/3: Creating shared components structure"
mkdir -p apps/web/src/shared/components/ui
echo -e "${GREEN}✓ Created shared components directory${NC}"
echo ""

# 3. Create minimal BaseButton.vue
echo "📝 Step 3/3: Creating minimal shared components"

cat > apps/web/src/shared/components/BaseButton.vue << 'EOF'
<template>
  <q-btn v-bind="$attrs">
    <slot />
  </q-btn>
</template>

<script setup lang="ts">
// Wrapper around q-btn for compatibility
</script>
EOF

# Create minimal BaseCard.vue
cat > apps/web/src/shared/components/BaseCard.vue << 'EOF'
<template>
  <q-card v-bind="$attrs">
    <slot />
  </q-card>
</template>

<script setup lang="ts">
// Wrapper around q-card for compatibility
</script>
EOF

# Create minimal BaseIcon.vue
cat > apps/web/src/shared/components/BaseIcon.vue << 'EOF'
<template>
  <q-icon v-bind="$attrs">
    <slot />
  </q-icon>
</template>

<script setup lang="ts">
// Wrapper around q-icon for compatibility
</script>
EOF

# Create minimal Spinner.vue
cat > apps/web/src/shared/components/ui/Spinner.vue << 'EOF'
<template>
  <q-spinner v-bind="$attrs" />
</template>

<script setup lang="ts">
// Wrapper around q-spinner for compatibility
</script>
EOF

echo -e "${GREEN}✓ Created BaseButton.vue${NC}"
echo -e "${GREEN}✓ Created BaseCard.vue${NC}"
echo -e "${GREEN}✓ Created BaseIcon.vue${NC}"
echo -e "${GREEN}✓ Created Spinner.vue${NC}"
echo ""

echo "✅ PRIORITY 1 FIXES COMPLETE"
echo ""
echo "📋 Next steps:"
echo "  1. Fix aiStore.ts syntax errors manually (lines 255, 258, 266)"
echo "  2. Run: pnpm type-check"
echo "  3. Run: pnpm lint"
echo "  4. Proceed to Priority 2 (type consolidation)"
echo ""
echo "📄 Full report: docs/PLANNER_MODULE_VERIFICATION_REPORT.md"
