import React, { useState, useEffect } from 'react';
import { 
    Dialog, 
    DialogContent, 
    DialogHeader, 
    DialogTitle,
    DialogDescription,
    DialogFooter 
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { 
    Select, 
    SelectContent, 
    SelectItem, 
    SelectTrigger, 
    SelectValue 
} from '@/components/ui/select';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Separator } from '@/components/ui/separator';
import { useEmployees } from '../hooks/useEmployees';
import { useRhFeedback } from './RhFeedbackNotification';

export const EmployeeEditModal = ({ isOpen, onClose, employee, onUpdate }) => {
    const { updateEmployee } = useEmployees();
    const { handleBackendError } = useRhFeedback();
    const [formData, setFormData] = useState({});
    const [loading, setLoading] = useState(false);

    // Lista de campos de pastas do Nextcloud
    const nextcloudFolders = [
        'pasta_espelhos', 'pasta_pedagios', 'pasta_abastecimento', 'pasta_administrativo',
        'pasta_administrativo_financeiro', 'pasta_ana_felix_priscila', 'pasta_ana_evillin',
        'pasta_compartilhamentos', 'pasta_contas_pagar_pety', 'pasta_contas_pagar_pralog',
        'pasta_contas_pagar_receber_pralog', 'pasta_contas_receber_pralog', 'pasta_contas_receber_pety',
        'pasta_contrato_frota', 'pasta_controladoria', 'pasta_controladoria_financeiro_pralog',
        'pasta_equipe_carlos_roberto', 'pasta_equipe_joseane_serra', 'pasta_equipe_rayane_santos',
        'pasta_equipe_renan_souza', 'pasta_faturamento_pety', 'pasta_financeiro_time_claudio',
        'pasta_financeiro_time_interno', 'pasta_frota', 'pasta_frota_multas_avarias',
        'pasta_gestao_frota', 'pasta_gerenciamento_risco', 'pasta_oficina_pralog',
        'pasta_operacoes', 'pasta_rh'
    ];

    useEffect(() => {
        if (employee) {
            // Formatar datas para input type="date"
            const formatDateForInput = (dateStr) => {
                if (!dateStr) return '';
                try {
                    const date = new Date(dateStr);
                    if (isNaN(date.getTime())) return '';
                    
                    // Usar métodos UTC para evitar distorções de fuso horário em datas de nascimento/admissão
                    const year = date.getUTCFullYear();
                    const month = String(date.getUTCMonth() + 1).padStart(2, '0');
                    const day = String(date.getUTCDate()).padStart(2, '0');
                    return `${year}-${month}-${day}`;
                } catch {
                    return '';
                }
            };

            // Função auxiliar para converter valores Sim/Não/1/0
            const convertSimNao = (value) => {
                if (value === true || value === 1 || value === '1' || value === 'Sim') return 'Sim';
                if (value === false || value === 0 || value === '0' || value === 'Não') return 'Não';
                return value || '';
            };

            setFormData({
                // Identificação Pessoal
                colaboradores: employee.colaboradores || employee.nome || employee.name || '',
                cpf: employee.cpf || employee.cpf_validado || '',
                cpf_validado: employee.cpf_validado || '',
                rg: employee.rg || '',
                pis: employee.pis || '',
                data_nascimento: formatDateForInput(employee.data_nascimento),
                endereco: employee.endereco || '',
                cep: employee.cep || '',
                
                // Contato
                telefone: employee.telefone || employee.phone || '',
                email_pessoal_em_uso: employee.email_pessoal_em_uso || '',
                email_corporativo: employee.email_corporativo || employee.email || '',
                contato_responsavel: employee.contato_responsavel || '',
                tentativa_contato_cadastro: formatDateForInput(employee.tentativa_contato_cadastro),
                momento_contato_1: employee.momento_contato_1 || '',
                momento_contato_2: employee.momento_contato_2 || '',
                momento_contato_3: employee.momento_contato_3 || '',
                horario_ultimo_contato: employee.horario_ultimo_contato || '',
                contato_colaborador_validado: employee.contato_colaborador_validado || '',
                
                // Profissional / Contrato
                contratacao: employee.contratacao || '',
                contratacao_validada: employee.contratacao_validada || '',
                status_contrato: employee.status_contrato || employee.status || 'Ativo',
                situacao: employee.situacao || employee.status_contrato || 'Ativo',
                cargo: employee.cargo || employee.role || '',
                cargo_adm: employee.cargo_adm || '',
                cargo_administrativo_validado: employee.cargo_administrativo_validado || '',
                funcao: employee.funcao || '',
                cbo: employee.cbo || '',
                classificacao_cbo: employee.classificacao_cbo || '',
                salario: employee.salario || 0,
                carga_horaria: employee.carga_horaria || '',
                jornada: employee.jornada || employee.jornada_1 || '',
                jornada_1: employee.jornada_1 || employee.jornada || '',
                data_admissao: formatDateForInput(employee.data_admissao),
                acesso: employee.acesso || '',
                risco: employee.risco || '',
                
                // Alocação / Empresa
                cliente: employee.cliente || '',
                cliente_nome: employee.cliente_nome || '',
                base: employee.base || '',
                base_validada: employee.base_validada || '',
                empresa: employee.empresa || '',
                empresas: employee.empresas || '',
                responsavel_direto: employee.responsavel_direto || employee.responsavel_direto_validado || '',
                responsavel_direto_validado: employee.responsavel_direto_validado || '',
                realmente_e_subordinado: convertSimNao(employee.realmente_e_subordinado),
                contratos_operacionais_ativos: employee.contratos_operacionais_ativos || '',
                
                // Documentos
                cnh: employee.cnh || '',
                data_expedicao_cnh: formatDateForInput(employee.data_expedicao_cnh),
                validade_cnh: formatDateForInput(employee.validade_cnh),
                
                // Férias
                data_limite_ferias: formatDateForInput(employee.data_limite_ferias),
                data_ultimas_ferias: formatDateForInput(employee.data_ultimas_ferias),
                
                // Infraestrutura / TI
                conta_ad: employee.conta_ad || '',
                data_criacao_conta_servico_auth: formatDateForInput(employee.data_criacao_conta_servico_auth),
                data_criacao_nextcloud: formatDateForInput(employee.data_criacao_nextcloud),
                escritorio_remoto: convertSimNao(employee.escritorio_remoto),
                usa_notebook_empresa: convertSimNao(employee.usa_notebook_empresa),
                usa_desktop_empresa: convertSimNao(employee.usa_desktop_empresa),
                possui_email_corporativo: convertSimNao(employee.possui_email_corporativo),
                modelo_dispositivo: employee.modelo_dispositivo || '',
                rotulo_servico_numero_serie: employee.rotulo_servico_numero_serie || '',
                maquina_registrada: convertSimNao(employee.maquina_registrada),
                maquina_registrada_cliente: convertSimNao(employee.maquina_registrada_cliente),
                obs_maquina: employee.obs_maquina || '',
                
                // IDs e Integrações
                id_prl: employee.id_prl || '',
                id_b2b: employee.id_b2b || '',
                id_oficina: employee.id_oficina || '',
                id_almoxarifado: employee.id_almoxarifado || '',
                id_apoio: employee.id_apoio || '',
                almoxarifado: convertSimNao(employee.almoxarifado),
                oficina: convertSimNao(employee.oficina),
                apoio_setor: convertSimNao(employee.apoio_setor),
                
                // Pastas Nextcloud (mapear valores 1/0 para Sim/Não)
                ...nextcloudFolders.reduce((acc, folder) => {
                    return { ...acc, [folder]: convertSimNao(employee[folder]) };
                }, {})
            });
        }
    }, [employee]);

    const handleChange = (e) => {
        const { name, value } = e.target;
        setFormData(prev => ({ ...prev, [name]: value }));
    };

    const handleSelectChange = (name, value) => {
        setFormData(prev => ({ ...prev, [name]: value }));
    };

    const handleSubmit = async (e) => {
        e.preventDefault();
        setLoading(true);
        try {
            // Lista de campos booleanos que devem ser 0 ou 1
            const booleanFields = [
                'realmente_e_subordinado', 
                'escritorio_remoto', 
                'maquina_registrada', 
                'maquina_registrada_cliente', 
                'usa_notebook_empresa', 
                'usa_desktop_empresa', 
                'possui_email_corporativo', 
                'almoxarifado', 
                'oficina', 
                'apoio_setor',
                ...nextcloudFolders
            ];

            // Lista de campos numéricos
            const numericFields = ['salario', 'id_prl', 'id_b2b', 'id_oficina', 'id_almoxarifado', 'id_apoio'];

            // Preparar payload enviando TODOS os campos, mesmo vazios
            const payload = Object.fromEntries(
                Object.entries(formData).map(([key, value]) => {
                    // Converter campos booleanos (Sim/Não) para 1/0
                    if (booleanFields.includes(key)) {
                        if (value === 'Sim' || value === true || value === 1 || value === '1') {
                            return [key, 1];
                        }
                        // Qualquer outro valor (Não, '', null, undefined, 0, false) vira 0
                        return [key, 0];
                    }
                    
                    // Converter campos numéricos
                    if (numericFields.includes(key)) {
                        if (value === '' || value === null || value === undefined) {
                            return [key, ''];
                        }
                        const numValue = Number(value);
                        return [key, isNaN(numValue) ? '' : numValue];
                    }
                    
                    // Manter valores vazios como string vazia
                    return [key, value === null || value === undefined ? '' : value];
                })
            );
            
            // Garantir que TODOS os campos esperados pelo backend estejam presentes
            const requiredFields = [
                'validade_cnh', 'data_criacao_conta_servico_auth', 'colaboradores',
                'email_pessoal_em_uso', 'contratacao', 'status_contrato', 'cliente', 'base', 'acesso',
                'cargo', 'cargo_adm', 'cargo_administrativo_validado', 'responsavel_direto',
                'responsavel_direto_validado', 'contato_responsavel', 'momento_contato_1',
                'momento_contato_2', 'momento_contato_3', 'realmente_e_subordinado',
                'usa_notebook_empresa', 'usa_desktop_empresa', 'possui_email_corporativo',
                'email_corporativo', 'conta_ad', 'escritorio_remoto', 'maquina_registrada_cliente',
                'maquina_registrada', 'modelo_dispositivo', 'rotulo_servico_numero_serie',
                'horario_ultimo_contato', 'obs_maquina', 'risco', 'carga_horaria', 'cpf_validado',
                'cpf', 'rg', 'data_expedicao_cnh', 'cnh', 'pis', 'data_nascimento', 'endereco', 'cep',
                'telefone', 'base_validada', 'data_admissao', 'data_ultimas_ferias', 'data_limite_ferias',
                'jornada', 'jornada_1', 'id_prl', 'id_b2b', 'id_oficina', 'id_almoxarifado', 'id_apoio',
                'almoxarifado', 'oficina', 'apoio_setor', 'funcao', 'cbo', 'classificacao_cbo', 'salario',
                'empresas', 'empresa', 'cliente_nome', 'contratos_operacionais_ativos',
                'contratacao_validada', 'tentativa_contato_cadastro', 'contato_colaborador_validado',
                'situacao', 'data_criacao_nextcloud',
                ...nextcloudFolders
            ];

            // Adicionar campos faltantes com valor vazio
            requiredFields.forEach(field => {
                if (!(field in payload)) {
                    if (booleanFields.includes(field)) {
                        payload[field] = 0;
                    } else if (numericFields.includes(field)) {
                        payload[field] = '';
                    } else {
                        payload[field] = '';
                    }
                }
            });
            
            console.log('Enviando dados para atualização:', payload);
            const success = await updateEmployee(employee.id || employee.idcolaborador, payload);
            
            if (success) {
                onUpdate?.();
                onClose();
            }
        } catch (error) {
            handleBackendError(error);
        } finally {
            setLoading(false);
        }
    };

    if (!employee) return null;

    return (
        <Dialog open={isOpen} onOpenChange={onClose}>
            <DialogContent className="w-[95vw] max-w-5xl bg-white dark:bg-[#1b1b1b] border-slate-200 dark:border-white/10 rounded-2xl p-0 z-[200]">
                <DialogHeader className="p-8 pb-4 bg-emerald-500/5">
                    <DialogTitle className="text-[clamp(1.25rem,2.4vw,1.875rem)] font-semibold text-slate-800 dark:text-white">
                        Editar Colaborador
                    </DialogTitle>
                    <DialogDescription className="text-[clamp(1rem,1.1vw,1.0625rem)] text-slate-500 font-medium uppercase tracking-wider">
                        ID: {employee.id || employee.idcolaborador} | {formData.colaboradores}
                    </DialogDescription>
                </DialogHeader>

                <form onSubmit={handleSubmit} className="flex flex-col h-full max-h-[90vh] overflow-hidden rounded-2xl">
                    <div className="flex-1 overflow-y-auto overflow-x-hidden custom-scrollbar min-h-0">
                        <Tabs defaultValue="pessoal" className="w-full">
                        <TabsList className="w-full justify-start px-4 sm:px-6 md:px-8 pt-4 bg-transparent border-b border-slate-100 dark:border-white/5 rounded-t-2xl sticky top-0 bg-white dark:bg-[#1b1b1b] z-10 overflow-x-auto flex-nowrap gap-2 scrollbar-hide [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]">
                                <TabsTrigger value="pessoal" className="text-[clamp(0.875rem,1.2vw,1rem)] font-semibold uppercase px-4 py-3 rounded-xl whitespace-nowrap flex-shrink-0">Pessoal</TabsTrigger>
                                <TabsTrigger value="contato" className="text-[clamp(0.875rem,1.2vw,1rem)] font-semibold uppercase px-4 py-3 rounded-xl whitespace-nowrap flex-shrink-0">Contato</TabsTrigger>
                                <TabsTrigger value="contrato" className="text-[clamp(0.875rem,1.2vw,1rem)] font-semibold uppercase px-4 py-3 rounded-xl whitespace-nowrap flex-shrink-0">Contrato & Cargo</TabsTrigger>
                                <TabsTrigger value="alocacao" className="text-[clamp(0.875rem,1.2vw,1rem)] font-semibold uppercase px-4 py-3 rounded-xl whitespace-nowrap flex-shrink-0">Alocação</TabsTrigger>
                                <TabsTrigger value="documentos" className="text-[clamp(0.875rem,1.2vw,1rem)] font-semibold uppercase px-4 py-3 rounded-xl whitespace-nowrap flex-shrink-0">Documentos</TabsTrigger>
                                <TabsTrigger value="ti" className="text-[clamp(0.875rem,1.2vw,1rem)] font-semibold uppercase px-4 py-3 rounded-xl whitespace-nowrap flex-shrink-0">TI & Infra</TabsTrigger>
                                <TabsTrigger value="nextcloud" className="text-[clamp(0.875rem,1.2vw,1rem)] font-semibold uppercase px-4 py-3 rounded-xl whitespace-nowrap flex-shrink-0">Nextcloud</TabsTrigger>
                                <TabsTrigger value="integracoes" className="text-[clamp(0.875rem,1.2vw,1rem)] font-semibold uppercase px-4 py-3 rounded-xl whitespace-nowrap flex-shrink-0">Sistemas</TabsTrigger>
                            </TabsList>
                            
                            <div className="px-4 sm:px-6 md:px-8 py-6 overflow-x-hidden">
                                {/* ABA PESSOAL */}
                                <TabsContent value="pessoal" className="mt-0 space-y-6">
                                    <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6">
                                        <div className="col-span-2 lg:col-span-3 space-y-2">
                                            <Label htmlFor="colaboradores" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Nome Completo</Label>
                                            <Input 
                                                id="colaboradores"
                                                name="colaboradores"
                                                value={formData.colaboradores}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="cpf" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">CPF</Label>
                                            <Input 
                                                id="cpf"
                                                name="cpf"
                                                value={formData.cpf}
                                                onChange={handleChange}
                                                placeholder="000.000.000-00"
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="rg" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">RG</Label>
                                            <Input 
                                                id="rg"
                                                name="rg"
                                                value={formData.rg}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="data_nascimento" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Data de Nascimento</Label>
                                            <Input 
                                                id="data_nascimento"
                                                name="data_nascimento"
                                                type="date"
                                                value={formData.data_nascimento}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="pis" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">PIS</Label>
                                            <Input 
                                                id="pis"
                                                name="pis"
                                                value={formData.pis}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                    </div>
                                </TabsContent>

                                {/* ABA CONTATO */}
                                <TabsContent value="contato" className="mt-0 space-y-6">
                                    <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6">
                                        <div className="space-y-2">
                                            <Label htmlFor="telefone" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Telefone</Label>
                                            <Input 
                                                id="telefone"
                                                name="telefone"
                                                value={formData.telefone}
                                                onChange={handleChange}
                                                placeholder="(00) 00000-0000"
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="email_pessoal_em_uso" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">E-mail Pessoal</Label>
                                            <Input 
                                                id="email_pessoal_em_uso"
                                                name="email_pessoal_em_uso"
                                                type="email"
                                                value={formData.email_pessoal_em_uso}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="cep" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">CEP</Label>
                                            <Input 
                                                id="cep"
                                                name="cep"
                                                value={formData.cep}
                                                onChange={handleChange}
                                                placeholder="00000-000"
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="col-span-2 lg:col-span-3 space-y-2">
                                            <Label htmlFor="endereco" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Endereço Completo</Label>
                                            <Input 
                                                id="endereco"
                                                name="endereco"
                                                value={formData.endereco}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="contato_responsavel" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Contato Responsável</Label>
                                            <Input 
                                                id="contato_responsavel"
                                                name="contato_responsavel"
                                                value={formData.contato_responsavel}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="tentativa_contato_cadastro" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Tentativa Contato Cadastro</Label>
                                            <Input 
                                                id="tentativa_contato_cadastro"
                                                name="tentativa_contato_cadastro"
                                                type="date"
                                                value={formData.tentativa_contato_cadastro}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="momento_contato_1" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Momento Contato 1</Label>
                                            <Input 
                                                id="momento_contato_1"
                                                name="momento_contato_1"
                                                value={formData.momento_contato_1}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="momento_contato_2" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Momento Contato 2</Label>
                                            <Input 
                                                id="momento_contato_2"
                                                name="momento_contato_2"
                                                value={formData.momento_contato_2}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="momento_contato_3" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Momento Contato 3</Label>
                                            <Input 
                                                id="momento_contato_3"
                                                name="momento_contato_3"
                                                value={formData.momento_contato_3}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="horario_ultimo_contato" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Horário Último Contato</Label>
                                            <Input 
                                                id="horario_ultimo_contato"
                                                name="horario_ultimo_contato"
                                                type="time"
                                                value={formData.horario_ultimo_contato}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="contato_colaborador_validado" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Contato Colaborador Validado</Label>
                                            <Input 
                                                id="contato_colaborador_validado"
                                                name="contato_colaborador_validado"
                                                value={formData.contato_colaborador_validado}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                    </div>
                                </TabsContent>

                                {/* ABA CONTRATO */}
                                <TabsContent value="contrato" className="mt-0 space-y-6">
                                    <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6">
                                        <div className="space-y-2">
                                            <Label htmlFor="cargo" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Cargo</Label>
                                            <Input 
                                                id="cargo"
                                                name="cargo"
                                                value={formData.cargo}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="cargo_adm" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Cargo Adm</Label>
                                            <Input 
                                                id="cargo_adm"
                                                name="cargo_adm"
                                                value={formData.cargo_adm}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="funcao" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Função</Label>
                                            <Input 
                                                id="funcao"
                                                name="funcao"
                                                value={formData.funcao}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="status_contrato" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Status Contrato</Label>
                                            <Select 
                                                value={formData.status_contrato} 
                                                onValueChange={(v) => handleSelectChange('status_contrato', v)}
                                            >
                                                <SelectTrigger className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10 text-slate-800 dark:text-slate-100">
                                                    <SelectValue placeholder="Selecione" />
                                                </SelectTrigger>
                                                <SelectContent position="popper" className="z-[300]">
                                                    <SelectItem value="Ativo">Ativo</SelectItem>
                                                    <SelectItem value="Inativo">Inativo</SelectItem>
                                                </SelectContent>
                                            </Select>
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="contratacao" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Tipo de Contratação</Label>
                                            <Input 
                                                id="contratacao"
                                                name="contratacao"
                                                value={formData.contratacao}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="data_admissao" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Data de Admissão</Label>
                                            <Input 
                                                id="data_admissao"
                                                name="data_admissao"
                                                type="date"
                                                value={formData.data_admissao}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="salario" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Salário</Label>
                                            <Input 
                                                id="salario"
                                                name="salario"
                                                type="number"
                                                step="0.01"
                                                value={formData.salario}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="cbo" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">CBO</Label>
                                            <Input 
                                                id="cbo"
                                                name="cbo"
                                                value={formData.cbo}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="classificacao_cbo" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Classificação CBO</Label>
                                            <Input 
                                                id="classificacao_cbo"
                                                name="classificacao_cbo"
                                                value={formData.classificacao_cbo}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="acesso" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Nível Acesso</Label>
                                            <Input 
                                                id="acesso"
                                                name="acesso"
                                                value={formData.acesso}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="risco" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Grau de Risco</Label>
                                            <Input 
                                                id="risco"
                                                name="risco"
                                                value={formData.risco}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="jornada_1" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Jornada Detalhada (1)</Label>
                                            <Input 
                                                id="jornada_1"
                                                name="jornada_1"
                                                value={formData.jornada_1}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="contratacao_validada" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Contratação Validada</Label>
                                            <Input 
                                                id="contratacao_validada"
                                                name="contratacao_validada"
                                                value={formData.contratacao_validada}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="cargo_administrativo_validado" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Cargo Administrativo Validado</Label>
                                            <Input 
                                                id="cargo_administrativo_validado"
                                                name="cargo_administrativo_validado"
                                                value={formData.cargo_administrativo_validado}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="data_ultimas_ferias" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Data Últimas Férias</Label>
                                            <Input 
                                                id="data_ultimas_ferias"
                                                name="data_ultimas_ferias"
                                                type="date"
                                                value={formData.data_ultimas_ferias}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="data_limite_ferias" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Data Limite Férias</Label>
                                            <Input 
                                                id="data_limite_ferias"
                                                name="data_limite_ferias"
                                                type="date"
                                                value={formData.data_limite_ferias}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="situacao" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Situação</Label>
                                            <Select 
                                                value={formData.situacao || undefined} 
                                                onValueChange={(v) => handleSelectChange('situacao', v || '')}
                                            >
                                                <SelectTrigger className="h-11 rounded-lg bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10">
                                                    <SelectValue placeholder="Selecione" />
                                                </SelectTrigger>
                                                <SelectContent position="popper" className="z-[300]">
                                                    <SelectItem value="Ativo">Ativo</SelectItem>
                                                    <SelectItem value="Inativo">Inativo</SelectItem>
                                                </SelectContent>
                                            </Select>
                                        </div>
                                    </div>
                                </TabsContent>

                                {/* ABA ALOCAÇÃO */}
                                <TabsContent value="alocacao" className="mt-0 space-y-6">
                                    <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6">
                                        <div className="space-y-2">
                                            <Label htmlFor="empresa" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">ID Empresa</Label>
                                            <Input 
                                                id="empresa"
                                                name="empresa"
                                                value={formData.empresa}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="empresas" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Nome Empresa</Label>
                                            <Input 
                                                id="empresas"
                                                name="empresas"
                                                value={formData.empresas}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="base" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Base</Label>
                                            <Input 
                                                id="base"
                                                name="base"
                                                value={formData.base}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="cliente" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Cliente (ID/Código)</Label>
                                            <Input 
                                                id="cliente"
                                                name="cliente"
                                                value={formData.cliente}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="cliente_nome" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Nome Cliente</Label>
                                            <Input 
                                                id="cliente_nome"
                                                name="cliente_nome"
                                                value={formData.cliente_nome}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="responsavel_direto" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Responsável Direto</Label>
                                            <Input 
                                                id="responsavel_direto"
                                                name="responsavel_direto"
                                                value={formData.responsavel_direto}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="contato_responsavel" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Contato Responsável</Label>
                                            <Input 
                                                id="contato_responsavel"
                                                name="contato_responsavel"
                                                value={formData.contato_responsavel}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="realmente_e_subordinado" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">É Subordinado?</Label>
                                            <Select 
                                                value={formData.realmente_e_subordinado || undefined} 
                                                onValueChange={(v) => handleSelectChange('realmente_e_subordinado', v || '')}
                                            >
                                                <SelectTrigger className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10 text-slate-800 dark:text-slate-100">
                                                    <SelectValue placeholder="Selecione" />
                                                </SelectTrigger>
                                                <SelectContent position="popper" className="z-[300]">
                                                    <SelectItem value="Sim">Sim</SelectItem>
                                                    <SelectItem value="Não">Não</SelectItem>
                                                </SelectContent>
                                            </Select>
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="base_validada" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Base Validada</Label>
                                            <Input 
                                                id="base_validada"
                                                name="base_validada"
                                                value={formData.base_validada}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="responsavel_direto_validado" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Responsável Direto Validado</Label>
                                            <Input 
                                                id="responsavel_direto_validado"
                                                name="responsavel_direto_validado"
                                                value={formData.responsavel_direto_validado}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="contratos_operacionais_ativos" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Contratos Operacionais Ativos</Label>
                                            <Input 
                                                id="contratos_operacionais_ativos"
                                                name="contratos_operacionais_ativos"
                                                value={formData.contratos_operacionais_ativos}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                    </div>
                                </TabsContent>

                                {/* ABA DOCUMENTOS */}
                                <TabsContent value="documentos" className="mt-0 space-y-6">
                                    <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6">
                                        <div className="space-y-2">
                                            <Label htmlFor="cnh" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">CNH</Label>
                                            <Input 
                                                id="cnh"
                                                name="cnh"
                                                value={formData.cnh}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="validade_cnh" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Validade CNH</Label>
                                            <Input 
                                                id="validade_cnh"
                                                name="validade_cnh"
                                                type="date"
                                                value={formData.validade_cnh}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="data_expedicao_cnh" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Data Expedição CNH</Label>
                                            <Input 
                                                id="data_expedicao_cnh"
                                                name="data_expedicao_cnh"
                                                type="date"
                                                value={formData.data_expedicao_cnh}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="cpf_validado" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">CPF Validado</Label>
                                            <Input 
                                                id="cpf_validado"
                                                name="cpf_validado"
                                                value={formData.cpf_validado}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                    </div>
                                </TabsContent>

                                <TabsContent value="nextcloud" className="mt-0 space-y-6">
                                    <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
                                        {nextcloudFolders.map((folder) => (
                                            <div key={folder} className="space-y-2">
                                                <Label htmlFor={folder} className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">
                                                    {folder.replace('pasta_', '').replace(/_/g, ' ')}
                                                </Label>
                                                <Select 
                                                    value={formData[folder] || undefined} 
                                                    onValueChange={(v) => handleSelectChange(folder, v || '')}
                                                >
                                                    <SelectTrigger className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10 text-slate-800 dark:text-slate-100">
                                                        <SelectValue placeholder="Selecione" />
                                                    </SelectTrigger>
                                                    <SelectContent position="popper" className="z-[300]">
                                                        <SelectItem value="Sim">Sim</SelectItem>
                                                        <SelectItem value="Não">Não</SelectItem>
                                                    </SelectContent>
                                                </Select>
                                            </div>
                                        ))}
                                    </div>
                                </TabsContent>

                                {/* ABA SISTEMAS (IDs) */}
                                <TabsContent value="integracoes" className="mt-0 space-y-6">
                                    <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 sm:gap-6">
                                        <div className="space-y-2">
                                            <Label htmlFor="id_prl" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">ID Ponto</Label>
                                            <Input 
                                                id="id_prl"
                                                name="id_prl"
                                                value={formData.id_prl}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="id_b2b" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">ID B2B</Label>
                                            <Input 
                                                id="id_b2b"
                                                name="id_b2b"
                                                value={formData.id_b2b}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="id_oficina" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">ID Oficina</Label>
                                            <Input 
                                                id="id_oficina"
                                                name="id_oficina"
                                                value={formData.id_oficina}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="id_almoxarifado" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">ID Almoxarifado</Label>
                                            <Input 
                                                id="id_almoxarifado"
                                                name="id_almoxarifado"
                                                value={formData.id_almoxarifado}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                    </div>
                                </TabsContent>

                                {/* ABA TI & INFRA */}
                                <TabsContent value="ti" className="mt-0 space-y-6">
                                    <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6">
                                        <div className="space-y-2">
                                            <Label htmlFor="email_corporativo" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">E-mail Corporativo</Label>
                                            <Input 
                                                id="email_corporativo"
                                                name="email_corporativo"
                                                type="email"
                                                value={formData.email_corporativo}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="conta_ad" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Conta AD</Label>
                                            <Input 
                                                id="conta_ad"
                                                name="conta_ad"
                                                value={formData.conta_ad}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="escritorio_remoto" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Escritório Remoto?</Label>
                                            <Select 
                                                value={formData.escritorio_remoto || undefined} 
                                                onValueChange={(v) => handleSelectChange('escritorio_remoto', v || '')}
                                            >
                                                <SelectTrigger className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10 text-slate-800 dark:text-slate-100">
                                                    <SelectValue placeholder="Selecione" />
                                                </SelectTrigger>
                                                <SelectContent position="popper" className="z-[300]">
                                                    <SelectItem value="Sim">Sim</SelectItem>
                                                    <SelectItem value="Não">Não</SelectItem>
                                                </SelectContent>
                                            </Select>
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="usa_notebook_empresa" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Usa Notebook?</Label>
                                            <Select 
                                                value={formData.usa_notebook_empresa || undefined} 
                                                onValueChange={(v) => handleSelectChange('usa_notebook_empresa', v || '')}
                                            >
                                                <SelectTrigger className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10 text-slate-800 dark:text-slate-100">
                                                    <SelectValue placeholder="Selecione" />
                                                </SelectTrigger>
                                                <SelectContent position="popper" className="z-[300]">
                                                    <SelectItem value="Sim">Sim</SelectItem>
                                                    <SelectItem value="Não">Não</SelectItem>
                                                </SelectContent>
                                            </Select>
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="usa_desktop_empresa" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Usa Desktop?</Label>
                                            <Select 
                                                value={formData.usa_desktop_empresa || undefined} 
                                                onValueChange={(v) => handleSelectChange('usa_desktop_empresa', v || '')}
                                            >
                                                <SelectTrigger className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10 text-slate-800 dark:text-slate-100">
                                                    <SelectValue placeholder="Selecione" />
                                                </SelectTrigger>
                                                <SelectContent position="popper" className="z-[300]">
                                                    <SelectItem value="Sim">Sim</SelectItem>
                                                    <SelectItem value="Não">Não</SelectItem>
                                                </SelectContent>
                                            </Select>
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="possui_email_corporativo" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Possui E-mail Corporativo?</Label>
                                            <Select 
                                                value={formData.possui_email_corporativo || undefined} 
                                                onValueChange={(v) => handleSelectChange('possui_email_corporativo', v || '')}
                                            >
                                                <SelectTrigger className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10 text-slate-800 dark:text-slate-100">
                                                    <SelectValue placeholder="Selecione" />
                                                </SelectTrigger>
                                                <SelectContent position="popper" className="z-[300]">
                                                    <SelectItem value="Sim">Sim</SelectItem>
                                                    <SelectItem value="Não">Não</SelectItem>
                                                </SelectContent>
                                            </Select>
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="modelo_dispositivo" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Modelo Dispositivo</Label>
                                            <Input 
                                                id="modelo_dispositivo"
                                                name="modelo_dispositivo"
                                                value={formData.modelo_dispositivo}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="obs_maquina" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Obs. Máquina</Label>
                                            <Input 
                                                id="obs_maquina"
                                                name="obs_maquina"
                                                value={formData.obs_maquina}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="rotulo_servico_numero_serie" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Service Tag / Serial</Label>
                                            <Input 
                                                id="rotulo_servico_numero_serie"
                                                name="rotulo_servico_numero_serie"
                                                value={formData.rotulo_servico_numero_serie}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="maquina_registrada" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Máquina Registrada?</Label>
                                            <Select 
                                                value={formData.maquina_registrada || undefined} 
                                                onValueChange={(v) => handleSelectChange('maquina_registrada', v || '')}
                                            >
                                                <SelectTrigger className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10 text-slate-800 dark:text-slate-100">
                                                    <SelectValue placeholder="Selecione" />
                                                </SelectTrigger>
                                                <SelectContent position="popper" className="z-[300]">
                                                    <SelectItem value="Sim">Sim</SelectItem>
                                                    <SelectItem value="Não">Não</SelectItem>
                                                </SelectContent>
                                            </Select>
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="maquina_registrada_cliente" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Registrada no Cliente?</Label>
                                            <Select 
                                                value={formData.maquina_registrada_cliente || undefined} 
                                                onValueChange={(v) => handleSelectChange('maquina_registrada_cliente', v || '')}
                                            >
                                                <SelectTrigger className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10 text-slate-800 dark:text-slate-100">
                                                    <SelectValue placeholder="Selecione" />
                                                </SelectTrigger>
                                                <SelectContent position="popper" className="z-[300]">
                                                    <SelectItem value="Sim">Sim</SelectItem>
                                                    <SelectItem value="Não">Não</SelectItem>
                                                </SelectContent>
                                            </Select>
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="data_criacao_conta_servico_auth" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Data Criação Conta Serviço Auth</Label>
                                            <Input 
                                                id="data_criacao_conta_servico_auth"
                                                name="data_criacao_conta_servico_auth"
                                                type="date"
                                                value={formData.data_criacao_conta_servico_auth}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                        <div className="space-y-2">
                                            <Label htmlFor="data_criacao_nextcloud" className="text-[clamp(1rem,1.1vw,1.0625rem)] font-medium uppercase text-slate-400">Data Criação Nextcloud</Label>
                                            <Input 
                                                id="data_criacao_nextcloud"
                                                name="data_criacao_nextcloud"
                                                type="date"
                                                value={formData.data_criacao_nextcloud}
                                                onChange={handleChange}
                                                className="h-11 rounded-xl bg-slate-50 dark:bg-white/5 border-slate-200 dark:border-white/10"
                                            />
                                        </div>
                                    </div>
                                </TabsContent>
                            </div>
                        </Tabs>
                    </div>

                    <DialogFooter className="p-8 bg-slate-50 dark:bg-white/5 border-t border-slate-100 dark:border-white/10 flex-shrink-0 rounded-b-2xl">
                        <Button 
                            type="button" 
                            variant="ghost" 
                            onClick={onClose}
                            className="rounded-xl h-12 px-8 font-medium text-slate-500"
                        >
                            Cancelar
                        </Button>
                        <Button 
                            type="submit" 
                            disabled={loading}
                            className="rounded-xl h-12 px-8 bg-emerald-600 hover:bg-emerald-700 text-white font-semibold uppercase tracking-widest shadow-lg shadow-emerald-500/20"
                        >
                            {loading ? 'Salvando...' : 'Salvar Alterações'}
                        </Button>
                    </DialogFooter>
                </form>
            </DialogContent>
        </Dialog>
    );
};
