#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fiche.h"
#include "liste.h"
#include "Menu.h"


void Menu()
{


    int choix;
    int verif;
    int id;
    int taille;
    int position;

    Fiche* contact;

    maillon* tete;
    tete = NULL;
    maillon* current;
    current = NULL;

    char info[100];
    char* nom = NULL;
    char* prenom = NULL;
    char* tel = NULL;


    printf ("****CONTACTS****\n\nChoississez ce que vous souhaitez faire:\n\n");
    printf( "1/ Commencer une nouvelle liste de contacts\n2/ Afficher la liste de contacts\n3/ Calculer la longueur de la liste\n4/ Ajouter un contact en tete de liste\n5/ Ajouter un contact en fin de liste\n6/ Ajouter un contact a la position desiree\n7/ Rechercher un contact\n8/ Supprimer un contact\n9/ Trier dans un ordre croissant");


   do
   {
    printf("\n Votre choix:\n");
    verif = scanf("%d", &choix);
    scanf ("%*[^\n]");
    getchar ();
    printf("\n");



   }while (verif != 1 || choix < 1 && choix < 10);


   if (choix == 1) // commencer une nouvelle liste de contacts
   {
       do
        {
            printf("Rentrez l'identifiant \n");
            printf("Id = ");
            verif = scanf("%d", &id);
            scanf ("%*[^\n]");
            getchar ();
            printf("\n");
        }
        while (verif != 1);

        printf("Rentrez le nom \n");
        printf("Nom : ");
        scanf("%s", info);
        taille = strlen(info);
        nom = malloc(taille);
        strcpy(nom, info);

void liste_afficher(maillon* tete)
{
    Fiche* affichage;

    do
    {
        affichage = tete -> next -> data;
        printf("Identifiant : %d \n", affichage -> identifiant);
        printf("Nom : %s \n", affichage -> nom);
        printf("Prenom : %s \n", affichage -> prenom);
        printf("Telephone : %s \n", affichage -> tel);
        printf("\n");
        system("pause");
        printf("\n \n");
        tete = tete -> next;
    }
    while (tete -> next != NULL);

    return;
}

        printf("\n");

        printf("Rentrez le prenom \n");
        printf("Prenom : ");
        scanf("%s", info);
        taille = strlen(info);
        prenom = malloc(taille);
        strcpy(prenom, info);

        printf("\n");

        printf("Rentrez le numero de telephone \n");
        printf("Tel : ");
        scanf("%s", info);
        taille = strlen(info);
        tel = malloc(taille);
        strcpy(tel, info);

        printf("\n");

        contact = fiche_creer(id, nom, prenom, tel);
        current = liste_creer_maillon(contact);
        liste_ajout_tete(tete, current);

         Menu();
    }




   if (choix == 2) // afficher la liste de contacts
   {
      liste_afficher(tete);
      Menu();
   }



   if (choix == 3) // calculer la longueur de la liste
   {
       Menu();
   }

   if (choix == 4) // ajouter contact en tête de liste
   {
       do
        {
            printf("Rentrez l'identifiant \n");
            printf("Id = ");
            verif = scanf("%d", &id);
            scanf ("%*[^\n]");
            getchar ();
            printf("\n");
        }
        while (verif != 1);

        printf("Rentrez le nom \n");
        printf("Nom : ");
        scanf("%s", info);
        taille = strlen(info);
        nom = malloc(taille);
        strcpy(nom, info);

        printf("\n");

        printf("Rentrez le prenom \n");
        printf("Prenom : ");
        scanf("%s", info);
        taille = strlen(info);
        prenom = malloc(taille);
        strcpy(prenom, info);

        printf("\n");

        printf("Rentrez le numero de telephone \n");
        printf("Tel : ");
        scanf("%s", info);
        taille = strlen(info);
        tel = malloc(taille);
        strcpy(tel, info);

        printf("\n");

       contact = liste_ajout_tete ( tete,current);

       Menu();
   }

   if (choix == 5) // ajouter contact en fin de liste
   {
       Menu();
   }

   if (choix == 6)// ajouter contact en position n
   {
       Menu();
   }

   if (choix == 7)// rechercher un contact
   {
       Menu();
   }

   if (choix == 8)// supprimer un contact
   {
       Menu();
   }

   if (choix == 9)// tri
   {
       Menu();
   }

    free(nom);
    free(prenom);
    free(tel);

}
