#!/bin/bash

# Create Next.js app with TypeScript without terminal interactions
echo "Creating Next.js app with TypeScript..."
export npm_config_legacy_peer_deps=true
cd management-frontend
yes | npx --yes create-next-app@latest . --typescript --eslint --tailwind --app --src-dir --import-alias "@/*" --use-npm --no-git --skip-instructions

# Wait for Next.js installation to complete
echo "Next.js with TypeScript installed successfully!"

# Install dependencies
echo "Installing dependencies..."
npm install @hookform/resolvers@5.0.1 \
  @radix-ui/react-checkbox@1.1.5 \
  @radix-ui/react-label@2.1.3 \
  @radix-ui/react-popover@1.1.7 \
  @radix-ui/react-select@2.2.4 \
  @radix-ui/react-slot@1.2.0 \
  class-variance-authority@0.7.1 \
  clsx@2.1.1 \
  date-fns@4.1.0 \
  flatpickr@4.6.13 \
  lucide-react@0.487.0 \
  next@15.2.4 \
  next-crypto@1.0.8 \
  react@19.0.0 \
  react-day-picker@8.10.1 \
  react-dom@19.0.0 \
  react-hook-form@7.55.0 \
  sonner@2.0.3 \
  tailwind-merge@3.2.0 \
  tw-animate-css@1.2.5 \
  zod@3.24.2 --legacy-peer-deps

# Install dev dependencies
echo "Installing dev dependencies..."
npm install --save-dev \
  @tailwindcss/postcss@4 \
  @types/node@20 \
  @types/react@19 \
  @types/react-dom@19 \
  tailwindcss@4 \
  typescript@5 --legacy-peer-deps

echo "All dependencies installed successfully!"

# Initialize shadcn with auto-confirmation
echo "Initializing shadcn..."
npx shadcn@latest init --yes \
  --legacy-peer-deps \
  --typescript \
  --tailwind \
  --react-server-components \
  --next-app \
  --style default \
  --css-variables \
  --shadcn-path components/ui \
  --base-color slate \
  --rsc

# List of all components to install
components=(
  "accordion"
  "alert"
  "alert-dialog"
  "aspect-ratio"
  "avatar"
  "badge"
  "button"
  "calendar"
  "card"
  "checkbox"
  "collapsible"
  "combobox"
  "command"
  "context-menu"
  "data-table"
  "date-picker"
  "dialog"
  "dropdown-menu"
  "form"
  "hover-card"
  "input"
  "label"
  "menubar"
  "navigation-menu"
  "popover"
  "progress"
  "radio-group"
  "scroll-area"
  "select"
  "separator"
  "sheet"
  "skeleton"
  "slider"
  "sonner"
  "switch"
  "table"
  "tabs"
  "textarea"
  "toast"
  "toggle"
  "tooltip"
)

# Loop and install each component, skipping prompts (to the extent allowed)
for component in "${components[@]}"; do
  echo "Installing $component..."
  npx --legacy-peer-deps shadcn@latest add "$component" -y || true
done

echo "✅ Next.js with TypeScript and all shadcn components installed successfully!"
