document.getElementById('garden-pet-calculator-form').addEventListener('submit', function(e) {
    e.preventDefault();

    var petType = document.getElementById('pet-type').value;
    var customPetName = document.getElementById('custom-pet-name').value;

    // Validation
    if (!petType) {
        alert('Please select a pet type');
        return;
    }

    if (petType === 'custom' && !customPetName) {
        alert('Please enter your custom pet name.');
        return;
    }

    // Show or hide custom pet input
    document.getElementById('custom-pet-name').style.display = petType === 'custom' ? 'inline-block' : 'none';

    var result = '';

    // Pet specific logic
    if (petType === 'dog') {
        result = `
🌿 <strong>Dog-friendly plants</strong>: Consider adding <strong>catnip</strong>, <strong>sunflowers</strong>, and <strong>mint</strong> to your garden. These plants are safe for dogs and will thrive in sunny areas of your garden. Dogs love to dig, so raised beds are ideal.
        `;
    } else if (petType === 'cat') {
        result = `
🐾 <strong>Cat-friendly plants</strong>: <strong>Catnip</strong>, <strong>cat grass</strong>, and <strong>valerian</strong> are great for cats. Avoid <strong>lilies</strong>, <strong>tulips</strong>, and <strong>azaleas</strong> as they are toxic to cats. Ensure shady areas for your cat to relax.
        `;
    } else if (petType === 'fish') {
        result = `
🐟 <strong>Fish-friendly plants</strong>: If you have an aquarium or pond, <strong>water lilies</strong>, <strong>duckweed</strong>, and <strong>anubias</strong> are safe and beneficial for your fish.
        `;
    } else if (petType === 'bird') {
        result = `
🕊️ <strong>Bird-friendly plants</strong>: Consider <strong>sunflowers</strong>, <strong>bamboo</strong>, and <strong>hibiscus</strong>. These plants will attract birds to your garden. Be mindful of other wildlife that could impact your birds.
        `;
    } else if (petType === 'rabbit') {
        result = `
🥕 <strong>Rabbit-friendly plants</strong>: Rabbits love <strong>parsley</strong>, <strong>cilantro</strong>, and <strong>carrots</strong>. Plant these herbs and vegetables in a separate patch to create a safe, edible environment.
        `;
    } else if (petType === 'guinea-pig') {
        result = `
🐹 <strong>Guinea Pig-friendly plants</strong>: <strong>Cilantro</strong>, <strong>parsley</strong>, and <strong>dandelion greens</strong> are safe for guinea pigs. Create a small herb garden just for them.
        `;
    } else if (petType === 'hamster') {
        result = `
🐹 <strong>Hamster-friendly plants</strong>: <strong>Mint</strong>, <strong>lettuce</strong>, and <strong>parsley</strong> are safe and loved by hamsters. These herbs can be grown in small pots and placed within your garden.
        `;
    } else if (petType === 'turtle') {
        result = `
🐢 <strong>Turtle-friendly plants</strong>: <strong>Water plants</strong>, such as <strong>water lilies</strong> and <strong>duckweed</strong>, are safe for turtles to nibble on.
        `;
    } else if (petType === 'reptile') {
        result = `
🌿 <strong>Reptile-friendly plants</strong>: Some reptiles enjoy <strong>pothos</strong>, <strong>aloe vera</strong>, and <strong>bamboo</strong>. Make sure the plants you use are safe for reptiles and non-toxic.
        `;
    } else if (petType === 'ferret') {
        result = `
🐾 <strong>Ferret-friendly plants</strong>: <strong>Cat grass</strong>, <strong>bamboo</strong>, and <strong>herbs</strong> are safe for ferrets. Avoid large shrubs and plants that could be a hazard to their small size.
        `;
    } else if (petType === 'horse') {
        result = `
🐴 <strong>Horse-friendly plants</strong>: <strong>Dandelions</strong>, <strong>clover</strong>, and <strong>bamboo</strong> are safe for horses. Ensure your garden provides plenty of grazing space.
        `;
    } else if (petType === 'mouse') {
        result = `
🐭 <strong>Mouse-friendly plants</strong>: <strong>Dandelions</strong>, <strong>sunflowers</strong>, and <strong>grass</strong> are safe for mice to nibble on.
        `;
    } else if (petType === 'gerbil') {
        result = `
🐹 <strong>Gerbil-friendly plants</strong>: <strong>Oats</strong>, <strong>timothy hay</strong>, and <strong>clover</strong> are safe for gerbils and can be planted in your garden.
        `;
    } else if (petType === 'tarantula') {
        result = `
🕷️ <strong>Tarantula-friendly plants</strong>: Tarantulas enjoy being surrounded by plants like <strong>moss</strong>, <strong>bamboo</strong>, and <strong>pothos</strong> for hiding spots.
        `;
    } else if (petType === 'hedgehog') {
        result = `
🦔 <strong>Hedgehog-friendly plants</strong>: <strong>Dandelions</strong>, <strong>sunflowers</strong>, and <strong>bamboo</strong> are safe for hedgehogs to interact with in the garden.
        `;
    } else if (petType === 'chinchilla') {
        result = `
🐾 <strong>Chinchilla-friendly plants</strong>: <strong>Timothy hay</strong>, <strong>dandelions</strong>, and <strong>bamboo</strong> are safe for chinchillas. Make sure your garden offers safe grazing space.
        `;
    } else if (petType === 'amphibian') {
        result = `
🐸 <strong>Amphibian-friendly plants</strong>: Consider adding <strong>water lilies</strong> and <strong>frog-friendly plants</strong> around water areas in your garden for amphibians to enjoy.
        `;
    } else if (petType === 'hermit-crab') {
        result = `
🐚 <strong>Hermit Crab-friendly plants</strong>: <strong>Pothos</strong>, <strong>bamboo</strong>, and <strong>hibiscus</strong> are great for hermit crabs to climb and interact with.
        `;
    } else if (petType === 'exotic-pet') {
        result = `
🐾 <strong>Exotic Pet-friendly plants</strong>: Always consult with a pet care guide for specific needs, but many exotic pets enjoy <strong>bamboo</strong>, <strong>pothos</strong>, and <strong>spinach</strong>.
        `;
    } else if (petType === 'cat-specific-breeds') {
        result = `
🐱 <strong>Breed-specific Cat-friendly plants</strong>: Make sure to choose plants that are non-toxic for specific breeds like <strong>Persian</strong> or <strong>Siamese</strong> cats. Avoid toxic plants like <strong>lilies</strong>.
        `;
    } else if (petType === 'custom') {
        result = `
🐾 You selected a custom pet: <strong>${customPetName}</strong>. Make sure the plants are non-toxic and suitable for your specific pet’s needs. Always check care guides for your pet’s safety.
        `;
    }

    // Display result
    document.getElementById('calculator-output').innerHTML = result;
});
