<template>
  <div class="demo-container">
    <v-card class="pa-6" elevation="2">
      <v-card-title class="text-h5 mb-4">
        📱 Perfect Phone Input - Like Screenshot 2
      </v-card-title>
      
      <v-row>
        <v-col cols="12" md="6">
          <PhoneInputWrapper
            v-model="phoneNumber"
            label="Phone Number"
            placeholder="Enter your phone number"
            help-text="Clean Vuetify design with compact flag dropdown"
            @phone-data="handlePhoneData"
            @country-changed="handleCountryChange"
          />
          
          <v-btn 
            color="primary" 
            class="mt-4" 
            @click="testUSNumber"
            variant="outlined"
            size="small"
          >
            Test: (917) 932-4061
          </v-btn>
          
          <v-btn 
            color="secondary" 
            class="mt-4 ml-2" 
            @click="testMonacoNumber"
            variant="outlined"
            size="small"
          >
            Test: Monaco +377
          </v-btn>
        </v-col>
        
        <v-col cols="12" md="6">
          <v-card variant="outlined" class="pa-4">
            <v-card-title class="text-subtitle-1">Live Phone Data:</v-card-title>
            <div class="mt-2">
              <p><strong>Number:</strong> <code>{{ phoneNumber }}</code></p>
              <p><strong>Valid:</strong> {{ phoneData?.isValid ? '✅ Valid' : '❌ Invalid' }}</p>
              <p><strong>Country:</strong> {{ phoneData?.country?.name }} ({{ phoneData?.country?.iso2 }})</p>
              <p><strong>Dial Code:</strong> {{ phoneData?.country?.dialCode }}</p>
            </div>
          </v-card>
        </v-col>
      </v-row>

      <v-alert type="success" variant="tonal" class="mt-6">
        <template #title>✅ Perfect Implementation:</template>
        <ul class="mt-2">
          <li><strong>Clean Design:</strong> Exactly like your screenshot - Vuetify text field with flag inside</li>
          <li><strong>Compact Dropdown:</strong> Max 240px height, not oversized</li>
          <li><strong>Real Flags:</strong> High-quality country flags from flagcdn.com</li>
          <li><strong>Monaco Priority:</strong> 🇲🇨 Monaco and 🇫🇷 France appear first</li>
          <li><strong>Smart Formatting:</strong> Uses libphonenumber-js for proper formatting</li>
          <li><strong>Search Functionality:</strong> Type to find countries quickly</li>
        </ul>
      </v-alert>

      <v-alert type="info" variant="tonal" class="mt-4">
        <template #title>🎯 Design Features:</template>
        <ul class="mt-2">
          <li>Flag size: 24x18px (perfect for text field)</li>
          <li>Dropdown: Compact with search bar</li>
          <li>Input field: Full width for phone number</li>
          <li>Validation: Real-time phone number validation</li>
          <li>Responsive: Works perfectly on mobile</li>
        </ul>
      </v-alert>
    </v-card>
  </div>
</template>

<script setup lang="ts">
import PhoneInputWrapper from './PhoneInputWrapper.vue';

const phoneNumber = ref('');
const phoneData = ref<any>(null);

const handlePhoneData = (data: any) => {
  phoneData.value = data;
  console.log('Phone data:', data);
};

const handleCountryChange = (country: any) => {
  console.log('Country changed:', country);
};

const testUSNumber = () => {
  phoneNumber.value = '+19179324061';
};

const testMonacoNumber = () => {
  phoneNumber.value = '+37799123456';
};
</script>

<style scoped>
.demo-container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
}

code {
  background: rgba(var(--v-theme-primary), 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Roboto Mono', monospace;
  font-size: 0.875rem;
}
</style>
