import React, { useEffect, useState } from "react";
import avatarPlaceholder from '../assets/images/avatar_placeholder.png';
import { useParams,Link, useNavigate, useLocation } from "react-router-dom";
import { GetDoctorByID } from "../components/utils/Functions-Endpoints/Doctor";
import { useAuth } from "../components/utils/AuthProvider";
  
const DoctorDetails = ({DictInfo}) => {
  const {getAuthorizationHeader} = useAuth(); 
  const Parametros = useParams()
  const navigate = useNavigate();
  const location = useLocation();

const navigateEdit = () => {
   const prefixo = location.pathname.split("/")[1]; 
    navigate(`/${prefixo}/medicos/edit`);
  }

 

const Voltar = () => {
   const prefixo = location.pathname.split("/")[1]; 
    navigate(`/${prefixo}/medicos`);
  }

  return (
    <>
    <div className="card p-3 shadow-sm">
      <h3 className="mb-3 text-center">MediConnect</h3>
      <hr />
      <div className="d-flex justify-content-between align-items-center mb-3">
        <button className="btn btn-success me-2" onClick={() => Voltar()}>
          <i className="bi bi-chevron-left"></i> Voltar
        </button>

        <div className="d-flex mb-3">
          <div className="avatar avatar-xl">
            <img src={avatarPlaceholder} alt="" />
          </div>
          <div className="media-body ms-3 font-extrabold">
            <span>{DictInfo.full_name || "Nome Completo"}</span>
            <p>{DictInfo.cpf || "CPF"}</p>
          </div>
        </div>
          <button className="btn btn-light" onClick={() => {navigateEdit()}} >
            <i className="bi bi-pencil-square"></i> Editar
          </button>
      </div>
    </div>
      
      {/* ------------------ DADOS PESSOAIS ------------------ */}
      <div className="card p-3 shadow-sm">
      <h5 className="mb-3">Dados Pessoais</h5>
      <hr />
      <div className="row">
        <div className="col-md-6 mb-3">
          <label className="font-extrabold">Nome:</label>
          <p>{DictInfo.full_name || "-"}</p>
        </div>
        <div className="col-md-6 mb-3">
          <label className="font-extrabold">Data de nascimento:</label>
          <p>{DictInfo.birth_date || "-"}</p>
        </div>
        
        <div className="col-md-6 mb-3">
          <label className="font-extrabold">CPF:</label>
          <p>{DictInfo.cpf || "-"}</p>
        </div>
        <div className="col-md-6 mb-3">
          <label className="font-extrabold">CRM:</label>
          <p>{DictInfo.crm || "-"}</p>
        </div>
        <div className="col-md-6 mb-3">
          <label className="font-extrabold">Estado do CRM:</label>
          <p>{DictInfo.crm_uf || "-"}</p>
        </div>
        
        <div className="col-md-6 mb-3">
          <label className="font-extrabold">Especialização:</label>
          <p>{DictInfo.specialty || "-"}</p>
        </div>
      </div>
      </div>

      {/* ------------------ ENDEREÇO ------------------ */}
      <div className="card p-3 shadow-sm">
      <h5>Endereço</h5>
      <hr />
      <div className="row">
        <div className="col-md-4 mb-3">
          <label className="font-extrabold">CEP:</label>
          <p>{DictInfo.cep || "-"}</p>
        </div>
        <div className="col-md-8 mb-3">
          <label className="font-extrabold">Rua:</label>
          <p>{DictInfo.street || "-"}</p>
        </div>
        <div className="col-md-4 mb-3">
          <label className="font-extrabold">Bairro:</label>
          <p>{DictInfo.neighborhood || "-"}</p>
        </div>
        <div className="col-md-4 mb-3">
          <label className="font-extrabold">Cidade:</label>
          <p>{DictInfo.city || "-"}</p>
        </div>
        <div className="col-md-2 mb-3">
          <label className="font-extrabold">Estado:</label>
          <p>{DictInfo.state || "-"}</p>
        </div>
        <div className="col-md-4 mb-3">
          <label className="font-extrabold">Número:</label>
          <p>{DictInfo.number || "-"}</p>
        </div>
        <div className="col-md-8 mb-3">
          <label className="font-extrabold">Complemento:</label>
          <p>{DictInfo.complement || "-"}</p>
        </div>
      </div>
      </div>

      {/* ------------------ CONTATO ------------------ */}
      <div className="card p-3 shadow-sm">
      <h5>Contato</h5>
      <hr />
      <div className="row">
        <div className="col-md-6 mb-3">
          <label className="font-extrabold">Email:</label>
          <p>{DictInfo.email || "-"}</p>
        </div>
        <div className="col-md-6 mb-3">
          <label className="font-extrabold">Telefone:</label>
          <p>{DictInfo.phone_mobile || "-"}</p>
        </div>
        <div className="col-md-6 mb-3">
          <label className="font-extrabold">Telefone 2:</label>
          <p>{DictInfo.phone2 || "-"}</p>
        </div>
        
      </div>
      </div>
    </>
  );
};

export default DoctorDetails;
