UNPKG

@deeprocket/deep-service-desk-widget

Version:

Widget Vue.js para integração com o sistema Deep Service Desk - Controle de visibilidade por URLs - Compatível com Vue 2.7.16 e Vue 3 - Com botão flutuante automático

2 lines 29.5 kB
(function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t(require("vue")):"function"===typeof define&&define.amd?define([],t):"object"===typeof exports?exports["deep-service-desk-widget"]=t(require("vue")):e["deep-service-desk-widget"]=t(e["Vue"])})("undefined"!==typeof self?self:this,(e=>(()=>{"use strict";var t={262:(e,t)=>{t.A=(e,t)=>{const n=e.__vccOpts||e;for(const[i,o]of t)n[i]=o;return n}},274:t=>{t.exports=e}},n={};function i(e){var o=n[e];if(void 0!==o)return o.exports;var r=n[e]={exports:{}};return t[e](r,r.exports,i),r.exports}(()=>{i.d=(e,t)=>{for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})}})(),(()=>{i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{i.r=e=>{"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})(),(()=>{i.p=""})();var o={};if(i.r(o),i.d(o,{FloatingTicketWidget:()=>D,TicketWidget:()=>E,default:()=>A}),"undefined"!==typeof window){var r=window.document.currentScript,s=r&&r.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);s&&(i.p=s[1])}var d=i(274);const a={class:"ticket-widget"},c={class:"popup-header"},l={key:0,class:"uuid-config-section"},u={class:"form-group"},p={key:0,class:"error-message"},m={class:"form-actions"},f={class:"form-group"},h={class:"form-group"},g={key:0,class:"error-message"},y={class:"form-actions"},w=["disabled"];function x(e,t,n,i,o,r){return(0,d.openBlock)(),(0,d.createElementBlock)("div",a,[o.showPopup?((0,d.openBlock)(),(0,d.createElementBlock)("div",{key:0,class:"popup-overlay",onClick:t[10]||(t[10]=(...e)=>r.closePopup&&r.closePopup(...e))},[(0,d.createElementVNode)("div",{class:"popup-content",onClick:t[9]||(t[9]=(0,d.withModifiers)((()=>{}),["stop"]))},[(0,d.createElementVNode)("div",c,[t[11]||(t[11]=(0,d.createElementVNode)("h3",null,"Novo Ticket",-1)),(0,d.createElementVNode)("button",{class:"close-btn",onClick:t[0]||(t[0]=(...e)=>r.closePopup&&r.closePopup(...e))},"×")]),r.computedClientUuid?(0,d.createCommentVNode)("",!0):((0,d.openBlock)(),(0,d.createElementBlock)("div",l,[t[13]||(t[13]=(0,d.createStaticVNode)('<div class="config-header"><span class="config-icon">🔧</span><div class="config-details"><div class="config-title">Configuração Necessária</div><div class="config-subtitle">Configure o UUID do cliente para continuar</div></div></div>',1)),(0,d.createElementVNode)("div",u,[t[12]||(t[12]=(0,d.createElementVNode)("label",{for:"uuidInput"},"UUID do Cliente *",-1)),(0,d.withDirectives)((0,d.createElementVNode)("input",{id:"uuidInput","onUpdate:modelValue":t[1]||(t[1]=e=>o.uuidInput=e),type:"text",placeholder:"Digite o UUID do cliente (ex: 1c9eb621-b56c-43e4-b04b-b1a91b0a1809)",class:"form-input uuid-input",onKeypress:t[2]||(t[2]=(...e)=>r.handleUuidKeypress&&r.handleUuidKeypress(...e))},null,544),[[d.vModelText,o.uuidInput]])]),o.uuidError?((0,d.openBlock)(),(0,d.createElementBlock)("div",p,(0,d.toDisplayString)(o.uuidError),1)):(0,d.createCommentVNode)("",!0),(0,d.createElementVNode)("div",m,[(0,d.createElementVNode)("button",{type:"button",onClick:t[3]||(t[3]=(...e)=>r.closePopup&&r.closePopup(...e)),class:"btn btn-cancel"}," Cancelar "),(0,d.createElementVNode)("button",{type:"button",onClick:t[4]||(t[4]=(...e)=>r.setClientUuid&&r.setClientUuid(...e)),class:"btn btn-submit"}," ✅ Configurar UUID ")])])),r.computedClientUuid?((0,d.openBlock)(),(0,d.createElementBlock)("form",{key:1,onSubmit:t[8]||(t[8]=(0,d.withModifiers)(((...e)=>r.submitTicket&&r.submitTicket(...e)),["prevent"])),class:"ticket-form"},[(0,d.createElementVNode)("div",f,[t[14]||(t[14]=(0,d.createElementVNode)("label",{for:"title"},"Título *",-1)),(0,d.withDirectives)((0,d.createElementVNode)("input",{id:"title","onUpdate:modelValue":t[5]||(t[5]=e=>o.ticket.title=e),type:"text",required:"",placeholder:"Digite o título do ticket",class:"form-input"},null,512),[[d.vModelText,o.ticket.title]])]),(0,d.createElementVNode)("div",h,[t[15]||(t[15]=(0,d.createElementVNode)("label",{for:"description"},"Descrição *",-1)),(0,d.withDirectives)((0,d.createElementVNode)("textarea",{id:"description","onUpdate:modelValue":t[6]||(t[6]=e=>o.ticket.description=e),required:"",placeholder:"Descreva o problema ou solicitação",class:"form-textarea",rows:"4"},null,512),[[d.vModelText,o.ticket.description]])]),o.errorMessage?((0,d.openBlock)(),(0,d.createElementBlock)("div",g,(0,d.toDisplayString)(o.errorMessage),1)):(0,d.createCommentVNode)("",!0),(0,d.createElementVNode)("div",y,[(0,d.createElementVNode)("button",{type:"button",onClick:t[7]||(t[7]=(...e)=>r.closePopup&&r.closePopup(...e)),class:"btn btn-cancel"}," Cancelar "),(0,d.createElementVNode)("button",{type:"submit",class:"btn btn-submit",disabled:o.isSubmitting},(0,d.toDisplayString)(o.isSubmitting?"Enviando...":"Criar Ticket"),9,w)])],32)):(0,d.createCommentVNode)("",!0)])])):(0,d.createCommentVNode)("",!0)])}const k={name:"TicketWidget",inject:{deepServiceDeskConfig:{from:"deepServiceDeskConfig",default:()=>({})}},props:{apiUrl:{type:String,default:null},clientUuid:{type:String,default:null}},data(){return{showPopup:!1,isSubmitting:!1,userToken:null,userEmail:null,client:null,errorMessage:"",ticket:{title:"",description:"",type:"support",priority:"medium"},uuidInput:"",uuidError:null,configuredClientUuid:null}},computed:{computedApiUrl(){let e=this.apiUrl||this.deepServiceDeskConfig.apiUrl;return e||(e||"undefined"===typeof window||(e=window.DEEP_SERVICE_DESK_API_URL),e||"undefined"===typeof process||(e={NODE_ENV:"production",BASE_URL:"/"}.VUE_APP_API_URL||{NODE_ENV:"production",BASE_URL:"/"}.VITE_API_URL)),e||"http://localhost:3000/api"},computedClientUuid(){let e=this.configuredClientUuid||this.clientUuid||this.deepServiceDeskConfig.clientUuid;return e||(e||"undefined"===typeof window||(e=window.DEEP_SERVICE_DESK_CLIENT_UUID),e||"undefined"===typeof process||(e={NODE_ENV:"production",BASE_URL:"/"}.VUE_APP_CLIENT_UUID||{NODE_ENV:"production",BASE_URL:"/"}.VITE_CLIENT_UUID)),e||null}},mounted(){window.addEventListener("new-ticket",this.handleNewTicketEvent),this.loadClientUuidFromEnv()},beforeDestroy(){window.removeEventListener("new-ticket",this.handleNewTicketEvent)},methods:{getAuthTokenFromExternalSystem(){try{const e=localStorage.getItem("token-tc");if(e)return e;const t=localStorage.getItem("token-deep");if(t)return t;const n=localStorage.getItem("authToken");return n||null}catch(e){return console.error("Erro ao acessar token:",e),null}},getUserEmailFromExternalSystem(){try{const t=localStorage.getItem("user-tc");if(t)try{const e=JSON.parse(atob(t));return e.email||null}catch(e){}const n=localStorage.getItem("user-deep");if(n)try{const e=JSON.parse(atob(n));return e.email||null}catch(e){}return null}catch(t){return console.error("Erro ao acessar dados do usuário:",t),null}},async fetchClientByUuid(){if(!this.userToken||!this.computedClientUuid)return null;try{const e=await fetch(`${this.computedApiUrl}/clients/find-by-uuid?uuid=${encodeURIComponent(this.computedClientUuid)}`,{headers:{Authorization:`Bearer ${this.userToken}`,"Content-Type":"application/json"}});if(e.ok){const t=await e.json();return t}return e.status,null}catch(e){return console.error("Erro ao buscar cliente por UUID:",e),null}},async findClientByEmail(e){if(!e||!this.userToken)return null;try{const t=await fetch(`${this.computedApiUrl}/clients/find-by-email?email=${encodeURIComponent(e)}`,{headers:{Authorization:`Bearer ${this.userToken}`,"Content-Type":"application/json"}});if(t.ok){const e=await t.json();return e}return t.status,null}catch(t){return console.error("Erro ao buscar cliente por email:",t),null}},async fetchClients(){if(this.userToken)try{const e=await fetch(`${this.computedApiUrl}/clients`,{headers:{Authorization:`Bearer ${this.userToken}`,"Content-Type":"application/json"}});if(e.ok){const t=await e.json();this.clients=t.data||t}}catch(e){console.error("Erro ao buscar clientes:",e)}},async openPopup(){if(!this.computedClientUuid)return this.errorMessage="",void(this.showPopup=!0);await this.initializeWidget(),this.client?(this.errorMessage="",this.showPopup=!0):this.errorMessage="Erro ao configurar widget. Verifique o UUID e autenticação."},closePopup(){this.showPopup=!1,this.resetForm(),this.errorMessage=""},resetForm(){this.ticket.title="",this.ticket.description="",this.ticket.type="support",this.ticket.priority="medium"},async submitTicket(){if(this.userToken)if(this.client){this.isSubmitting=!0,this.errorMessage="";try{const e={title:this.ticket.title.trim(),description:this.ticket.description.trim(),type:this.ticket.type,priority:this.ticket.priority,status:"open",clientId:this.client.id};this.userEmail&&(e.description+=`\n\n--- Informações do Usuário ---\nEmail: ${this.userEmail}`);const t=await fetch(`${this.computedApiUrl}/tickets`,{method:"POST",headers:{Authorization:`Bearer ${this.userToken}`,"Content-Type":"application/json"},body:JSON.stringify(e)}),n=await t.json();if(t.ok)this.$emit("ticket-created",{...n,success:!0,message:"Ticket criado com sucesso!"}),this.closePopup();else{const e=n.error||"Erro ao criar ticket";this.errorMessage=e,this.$emit("ticket-error",{message:e,details:n})}}catch(e){console.error("Erro ao criar ticket:",e);const t="Erro de conexão. Verifique sua internet e tente novamente.";this.errorMessage=t,this.$emit("ticket-error",{message:t,details:e.message})}finally{this.isSubmitting=!1}}else this.errorMessage="Cliente não configurado";else this.errorMessage="Token de autenticação não encontrado"},handleNewTicketEvent(){this.openPopup()},isOpen(){return this.showPopup},loadClientUuidFromEnv(){let e=null;if(e||"undefined"===typeof window||(e=window.DEEP_SERVICE_DESK_CLIENT_UUID),e||"undefined"===typeof process||(e={NODE_ENV:"production",BASE_URL:"/"}.VUE_APP_CLIENT_UUID||{NODE_ENV:"production",BASE_URL:"/"}.VITE_CLIENT_UUID),!e)return;const t=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;t.test(e)?(this.configuredClientUuid=e,this.initializeWidget()):console.error("❌ UUID do cliente inválido:",e)},handleUuidKeypress(e){"Enter"===e.key&&this.setClientUuid()},setClientUuid(){const e=this.uuidInput.trim();if(!e)return void(this.uuidError="Por favor, digite um UUID");const t=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;t.test(e)?(this.configuredClientUuid=e,this.uuidInput="",this.uuidError=null,this.initializeWidget()):this.uuidError="UUID inválido. Formato esperado: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"},async initializeWidget(){return this.userToken=this.getAuthTokenFromExternalSystem(),this.userToken?(this.userEmail=this.getUserEmailFromExternalSystem(),this.client=await this.fetchClientByUuid(),this.client?void 0:(this.uuidError="Cliente não encontrado. Verifique se o UUID está correto.",void(this.configuredClientUuid=null))):(this.uuidError="Token de autenticação não encontrado. Faça login no sistema.",void(this.configuredClientUuid=null))},resetUuid(){this.configuredClientUuid=null,this.client=null,this.userToken=null,this.userEmail=null,this.uuidInput="",this.uuidError=null,this.errorMessage=""}}};var b=i(262);const v=(0,b.A)(k,[["render",x]]),E=v,U={class:"floating-ticket-widget"};function C(e,t,n,i,o,r){const s=(0,d.resolveComponent)("TicketWidget");return(0,d.openBlock)(),(0,d.createElementBlock)("div",U,[(0,d.createVNode)(s,{ref:"ticketWidget",onTicketCreated:r.onTicketCreated,onTicketError:r.onTicketError},null,8,["onTicketCreated","onTicketError"])])}const T={name:"FloatingTicketWidget",components:{TicketWidget:E},inject:{deepServiceDeskConfig:{from:"deepServiceDeskConfig",default:()=>({})}},mounted(){window.addEventListener("new-ticket",this.openWidget)},beforeDestroy(){window.removeEventListener("new-ticket",this.openWidget)},methods:{openWidget(){this.$refs.ticketWidget&&this.$refs.ticketWidget.openPopup()},onTicketCreated(e){window.dispatchEvent(new CustomEvent("ticket-created",{detail:e})),this.showNotification("Ticket criado com sucesso!","success")},onTicketError(e){window.dispatchEvent(new CustomEvent("ticket-error",{detail:e})),this.showNotification(e.message||"Erro ao criar ticket","error")},showNotification(e,t="info"){const n=document.createElement("div");if(n.className=`deep-service-desk-notification ${t}`,n.textContent=e,n.style.cssText=`\n position: fixed;\n top: 20px;\n right: 20px;\n background: ${"success"===t?"#10b981":"error"===t?"#ef4444":"#3b82f6"};\n color: white;\n padding: 12px 20px;\n border-radius: 8px;\n box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);\n z-index: 10000;\n font-size: 14px;\n font-weight: 500;\n max-width: 300px;\n word-wrap: break-word;\n animation: slideInRight 0.3s ease;\n `,!document.getElementById("deep-service-desk-notification-styles")){const e=document.createElement("style");e.id="deep-service-desk-notification-styles",e.textContent="\n @keyframes slideInRight {\n from {\n transform: translateX(100%);\n opacity: 0;\n }\n to {\n transform: translateX(0);\n opacity: 1;\n }\n }\n @keyframes slideOutRight {\n from {\n transform: translateX(0);\n opacity: 1;\n }\n to {\n transform: translateX(100%);\n opacity: 0;\n }\n }\n ",document.head.appendChild(e)}document.body.appendChild(n),setTimeout((()=>{n.style.animation="slideOutRight 0.3s ease",setTimeout((()=>{n.parentNode&&n.parentNode.removeChild(n)}),300)}),5e3)}}},S=(0,b.A)(T,[["render",C]]),D=S;let I=null;function V(){return"undefined"!==typeof window&&window.Vue?window.Vue.version||"2":"3"}function N(e){if(!e||!Array.isArray(e)||0===e.length)return!1;const t=window.location.href,n=window.location.pathname;return e.some((e=>"string"===typeof e?t.includes(e)||n.includes(e):e instanceof RegExp&&(e.test(t)||e.test(n))))}function B(e){if(document.getElementById("deep-service-desk-floating-btn"))return;if(N(e.hiddenUrls))return;const t=document.createElement("button");t.id="deep-service-desk-floating-btn",t.innerHTML='\n <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path d="M20 2H4C2.9 2 2 2.9 2 4V22L6 18H20C21.1 18 22 17.1 22 16V4C22 2.9 21.1 2 20 2ZM20 16H5.17L4 17.17V4H20V16Z" fill="currentColor"/>\n <path d="M7 9H17V11H7V9ZM7 12H17V14H7V12ZM7 6H17V8H7V6Z" fill="currentColor"/>\n </svg>\n ',t.style.cssText="\n position: fixed;\n bottom: 20px;\n right: 20px;\n width: 60px;\n height: 60px;\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n border: none;\n border-radius: 50%;\n color: white;\n cursor: pointer;\n box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);\n z-index: 9998;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.3s ease;\n font-size: 0;\n ",t.addEventListener("mouseenter",(()=>{t.style.transform="scale(1.1)",t.style.boxShadow="0 6px 25px rgba(0, 0, 0, 0.2)"})),t.addEventListener("mouseleave",(()=>{t.style.transform="scale(1)",t.style.boxShadow="0 4px 20px rgba(0, 0, 0, 0.15)"})),t.addEventListener("click",(()=>{window.dispatchEvent(new CustomEvent("new-ticket"))})),t.title="Abrir Suporte",document.body.appendChild(t);const n=document.createElement("style");if(n.textContent="\n @media (max-width: 768px) {\n #deep-service-desk-floating-btn {\n bottom: 15px !important;\n right: 15px !important;\n width: 50px !important;\n height: 50px !important;\n }\n }\n ",document.head.appendChild(n),e.hiddenUrls&&e.hiddenUrls.length>0){let n=window.location.href;const i=()=>{const i=window.location.href;i!==n&&(n=i);const o=N(e.hiddenUrls);t.style.display=o?"none":"flex"},o=history.pushState,r=history.replaceState;if(history.pushState=function(){o.apply(history,arguments),setTimeout(i,50),setTimeout(i,200)},history.replaceState=function(){r.apply(history,arguments),setTimeout(i,50),setTimeout(i,200)},window.addEventListener("popstate",(()=>{setTimeout(i,50)})),window.addEventListener("hashchange",(()=>{setTimeout(i,50)})),"undefined"!==typeof MutationObserver){const e=new MutationObserver((()=>{window.location.href!==n&&setTimeout(i,100)}));e.observe(document.body,{subtree:!0,childList:!0})}if(setInterval((()=>{window.location.href!==n&&i()}),2e3),window.addEventListener("beforeunload",i),window.addEventListener("load",(()=>{setTimeout(i,100)})),(window.Vue||document.querySelector("[data-v-]"))&&window.addEventListener("vue-router-navigation",(()=>{setTimeout(i,50)})),window.React||document.querySelector("[data-reactroot]")){const e=()=>{setTimeout(i,50)};window.addEventListener("react-router-navigation",e)}const s=window.fetch;s&&(window.fetch=function(){const e=s.apply(this,arguments);return e.then((()=>{setTimeout((()=>{window.location.href!==n&&i()}),300)})).catch((()=>{setTimeout((()=>{window.location.href!==n&&i()}),300)})),e}),setTimeout(i,100)}}function L(){const e=document.getElementById("deep-service-desk-floating-btn");e&&e.remove()}window.deepServiceDeskUpdateVisibility=function(){if(I&&I.hiddenUrls){const e=document.getElementById("deep-service-desk-floating-btn");if(e){const t=N(I.hiddenUrls);e.style.display=t?"none":"flex",console.log("[Deep Service Desk] Visibilidade atualizada manualmente"),console.log("[Deep Service Desk] URL atual:",window.location.href),console.log("[Deep Service Desk] Botão oculto:",t)}}};function _(e,t,n){if(document.getElementById("deep-service-desk-global-widget"))return;const i=document.createElement("div");i.id="deep-service-desk-global-widget",document.body.appendChild(i),P(e)}function P(e){const t=e||I;if(!t||!t.clientUuid)return console.error("❌ ERRO CRÍTICO: Configuração não possui clientUuid!"),console.error("❌ Config recebida:",e),void console.error("❌ Global config:",I);const n=document.getElementById("deep-service-desk-global-widget");if(!n)return;n.innerHTML='\n <div id="independent-ticket-widget" style="display: none;">\n \x3c!-- Overlay do modal --\x3e\n <div class="widget-overlay" style="\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgba(0, 0, 0, 0.5);\n display: flex;\n justify-content: center;\n align-items: center;\n z-index: 9999;\n ">\n <div class="widget-modal" style="\n background: white;\n border-radius: 8px;\n width: 90%;\n max-width: 500px;\n max-height: 90vh;\n overflow-y: auto;\n box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);\n ">\n \x3c!-- Header --\x3e\n <div class="widget-header" style="\n display: flex;\n justify-content: space-between;\n align-items: center;\n padding: 20px 24px;\n border-bottom: 1px solid #e5e7eb;\n background-color: #f9fafb;\n border-radius: 8px 8px 0 0;\n ">\n <h3 style="margin: 0; color: #1f2937; font-size: 18px; font-weight: 600;">Novo Ticket de Suporte</h3>\n <button class="widget-close" style="\n background: none;\n border: none;\n font-size: 24px;\n cursor: pointer;\n color: #6b7280;\n padding: 0;\n width: 30px;\n height: 30px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n ">&times;</button>\n </div>\n \n \x3c!-- Formulário de Ticket --\x3e\n <div class="widget-form" style="padding: 24px;">\n <form id="ticket-form">\n \x3c!-- Título --\x3e\n <div style="margin-bottom: 16px;">\n <label style="display: block; margin-bottom: 6px; font-weight: 500; color: #374151; font-size: 14px;">\n Título *\n </label>\n <input \n type="text" \n id="ticket-title" \n required\n style="\n width: 100%;\n padding: 10px 12px;\n border: 1px solid #d1d5db;\n border-radius: 6px;\n font-size: 14px;\n box-sizing: border-box;\n "\n placeholder="Resumo do problema ou solicitação"\n />\n </div>\n \n \x3c!-- Descrição --\x3e\n <div style="margin-bottom: 20px;">\n <label style="display: block; margin-bottom: 6px; font-weight: 500; color: #374151; font-size: 14px;">\n Descrição *\n </label>\n <textarea \n id="ticket-description" \n required\n rows="6"\n style="\n width: 100%;\n padding: 10px 12px;\n border: 1px solid #d1d5db;\n border-radius: 6px;\n font-size: 14px;\n box-sizing: border-box;\n resize: vertical;\n min-height: 120px;\n "\n placeholder="Descreva detalhadamente o problema ou solicitação..."\n ></textarea>\n </div>\n \n \x3c!-- Loading indicator --\x3e\n <div id="form-loading" style="display: none; text-align: center; margin: 16px 0;">\n <div style="\n display: inline-block;\n width: 20px;\n height: 20px;\n border: 2px solid #e5e7eb;\n border-top: 2px solid #3b82f6;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n "></div>\n <span style="margin-left: 8px; color: #6b7280; font-size: 14px;">Enviando...</span>\n </div>\n \n \x3c!-- Botões --\x3e\n <div style="\n display: flex;\n gap: 12px;\n justify-content: flex-end;\n margin-top: 20px;\n ">\n <button \n type="button" \n class="widget-close" \n style="\n padding: 10px 20px;\n border: 1px solid #d1d5db;\n background-color: white;\n color: #374151;\n border-radius: 6px;\n cursor: pointer;\n font-size: 14px;\n font-weight: 500;\n "\n >\n Cancelar\n </button>\n <button \n type="submit" \n id="submit-ticket"\n style="\n padding: 10px 20px;\n border: none;\n background-color: #3b82f6;\n color: white;\n border-radius: 6px;\n cursor: pointer;\n font-size: 14px;\n font-weight: 500;\n "\n >\n Enviar Ticket\n </button>\n </div>\n </form>\n </div>\n </div>\n </div>\n </div>\n \n \x3c!-- CSS para animação de loading --\x3e\n <style>\n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n </style>\n ';const i=n.querySelector("#independent-ticket-widget"),o=n.querySelector(".widget-overlay"),r=n.querySelectorAll(".widget-close"),s=n.querySelector("#ticket-form"),d=n.querySelector("#form-loading"),a=n.querySelector("#submit-ticket"),c=()=>{i.style.display="none",s.reset(),d.style.display="none",a.disabled=!1};r.forEach((e=>{e.addEventListener("click",c)})),o.addEventListener("click",(e=>{e.target===o&&c()})),s.addEventListener("submit",(async e=>{e.preventDefault(),d.style.display="block",a.disabled=!0;const n=t||I;if(!n||!n.clientUuid)return console.error("❌ ERRO: Não foi possível obter clientUuid!"),console.error("❌ finalConfig:",t),console.error("❌ globalConfig:",I),R("Erro: Configuração inválida. UUID do cliente não encontrado.","error"),d.style.display="none",void(a.disabled=!1);const i={title:document.getElementById("ticket-title").value,description:document.getElementById("ticket-description").value,type:"suporte",status:"pendente",priority:"media",clientUuid:n.clientUuid};try{const t=await fetch(`${n.apiUrl}/tickets/external`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}),o=t.headers.get("content-type");if(!o||!o.includes("application/json")){const e=await t.text();throw console.error("❌ Resposta não é JSON:",e),new Error(`Resposta inválida do servidor: ${e}`)}if(!t.ok){const n=await t.text();let i;console.error("❌ Erro na resposta:",n);try{i=JSON.parse(n)}catch(e){i={error:n}}throw new Error(`Erro ${t.status}: ${t.statusText} - ${i.error||n}`)}{const e=await t.json();R("Ticket criado com sucesso! Você receberá uma resposta em breve.","success"),c(),window.dispatchEvent(new CustomEvent("ticket-created",{detail:e}))}}catch(o){console.error("❌ Erro ao criar ticket:",o),console.error("❌ Stack trace:",o.stack),console.error("❌ Dados que causaram erro:",i),console.error("❌ Config usada:",n),R(`Erro ao enviar ticket: ${o.message}`,"error"),window.dispatchEvent(new CustomEvent("ticket-error",{detail:o}))}finally{d.style.display="none",a.disabled=!1}})),window.addEventListener("new-ticket",(()=>{i.style.display="block",setTimeout((()=>{document.getElementById("ticket-title").focus()}),100)}))}function R(e,t="info"){const n=document.createElement("div");if(n.className=`deep-service-desk-notification ${t}`,n.textContent=e,n.style.cssText=`\n position: fixed;\n top: 20px;\n right: 20px;\n background: ${"success"===t?"#10b981":"error"===t?"#ef4444":"#3b82f6"};\n color: white;\n padding: 12px 20px;\n border-radius: 8px;\n box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);\n z-index: 10000;\n font-size: 14px;\n font-weight: 500;\n max-width: 300px;\n word-wrap: break-word;\n animation: slideInRight 0.3s ease;\n `,!document.getElementById("deep-service-desk-notification-styles")){const e=document.createElement("style");e.id="deep-service-desk-notification-styles",e.textContent="\n @keyframes slideInRight {\n from {\n transform: translateX(100%);\n opacity: 0;\n }\n to {\n transform: translateX(0);\n opacity: 1;\n }\n }\n @keyframes slideOutRight {\n from {\n transform: translateX(0);\n opacity: 1;\n }\n to {\n transform: translateX(100%);\n opacity: 0;\n }\n }\n ",document.head.appendChild(e)}document.body.appendChild(n),setTimeout((()=>{n.style.animation="slideOutRight 0.3s ease",setTimeout((()=>{n.parentNode&&n.parentNode.removeChild(n)}),300)}),5e3)}const O={install(e,t={}){const n={apiUrl:t.apiUrl||"http://localhost:3000/api",clientUuid:t.clientUuid||null,showFloatingButton:!1!==t.showFloatingButton,hiddenUrls:t.hiddenUrls||[],...t};if(!n.clientUuid)throw console.error("❌ ERRO CRÍTICO: clientUuid é obrigatório!"),console.error("❌ Configuração recebida:",t),console.error("❌ Configuração processada:",n),new Error("Deep Service Desk Widget: clientUuid é obrigatório na configuração");I=n;const i=e.version&&e.version.startsWith("3");if(i?(e.config.globalProperties.$deepServiceDesk=n,e.provide("deepServiceDeskConfig",n),e.component("TicketWidget",E),e.component("DeepServiceDeskWidget",E),e.component("FloatingTicketWidget",D)):(e.prototype.$deepServiceDesk=n,e.mixin({data(){return{deepServiceDeskConfig:n}},provide(){return{deepServiceDeskConfig:n}}}),e.component("TicketWidget",E),e.component("DeepServiceDeskWidget",E),e.component("FloatingTicketWidget",D)),n.showFloatingButton){const t=()=>{B(n),setTimeout((()=>{_(n,i,e)}),100)};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t):t()}const o={showFloatingButton(){N(n.hiddenUrls)||B(n)},hideFloatingButton(){L()},openTicket(){window.dispatchEvent(new CustomEvent("new-ticket"))},updateUrlVisibility(){const e=document.getElementById("deep-service-desk-floating-btn");if(e&&n.hiddenUrls){const t=N(n.hiddenUrls);e.style.display=t?"none":"flex","localhost"!==window.location.hostname&&"127.0.0.1"!==window.location.hostname||(console.log("[Deep Service Desk] URL atual:",window.location.href),console.log("[Deep Service Desk] Botão deve ser oculto:",t),console.log("[Deep Service Desk] URLs ocultas configuradas:",n.hiddenUrls))}}};i?e.config.globalProperties.$deepServiceDeskButton=o:e.prototype.$deepServiceDeskButton=o}},$=O;if("undefined"!==typeof window&&window.Vue){const e=V();e.startsWith("2")&&window.Vue.use(O)}const A=$;return o})())); //# sourceMappingURL=deep-service-desk-widget.umd.min.js.map