@imj_media/tareas 1.6.4 → 1.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,3 @@
1
- import { DropdownOption } from '@imj_media/ui';
2
1
  import { ListadoProgresoRow } from '../api/listadoProgreso.types';
3
2
  /**
4
3
  * Deriva opciones de dropdown (medios/plazas/estados). Convierte selección de plazas a parámetro API.
@@ -29,27 +29,5 @@
29
29
  * ```
30
30
  */
31
31
  export declare const useGetInputFiltersByPath: (currentPath: string) => {
32
- inputFilters: ({
33
- icon?: import('@imj_media/ui').VisualSlotType;
34
- label: string;
35
- keyName?: string;
36
- value?: string;
37
- onValueChange?: (value: import('@imj_media/ui').FilterChangeValue) => void;
38
- options?: import('@imj_media/ui').DropdownOption[];
39
- placeholder?: string;
40
- clearText?: string;
41
- type?: "date" | "multiple" | "group" | "dropdown" | "input" | "textarea" | "dateRange";
42
- title?: string;
43
- } | {
44
- options: any;
45
- icon?: import('@imj_media/ui').VisualSlotType;
46
- label: string;
47
- keyName?: string;
48
- value?: string;
49
- onValueChange?: (value: import('@imj_media/ui').FilterChangeValue) => void;
50
- placeholder?: string;
51
- clearText?: string;
52
- type?: "date" | "multiple" | "group" | "dropdown" | "input" | "textarea" | "dateRange";
53
- title?: string;
54
- })[];
32
+ inputFilters: any[];
55
33
  };
package/dist/tareas.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
  tm-shadow-02`,"data-portal-host":!0,children:Object.values(f).map((v,N)=>a.jsx(w,{priorityTask:N,text:v.title,itemColor:v.color},N))}),document.body)},b=w=>{w.stopPropagation()};return o?a.jsxs("div",{className:"tm-relative",onClick:b,onPointerDown:b,children:[a.jsxs("label",{onBlur:()=>{l(null)},htmlFor:i,className:"tm-flex tm-cursor-pointer tm-items-center tm-gap-2 active:tm-opacity-50",children:[a.jsx(Me,{trigger:a.jsx(p.Icon,{name:ne.faFlag,size:"sm",color:x.color}),children:a.jsx("div",{className:"tm-px-8 tm-py-4",children:a.jsx(p.Text,{color:x.color,children:`Prioridad: ${y}`})})}),s&&a.jsx(p.Text,{as:"span",color:x.color,className:" tm-font-normal",children:y})]}),a.jsx("button",{id:i,type:"button",onClick:w=>{w.stopPropagation(),l(r?null:{x:w.clientX,y:w.clientY})},className:"tm-hidden"}),a.jsx(j,{})]}):a.jsxs("div",{className:"tm-relative tm-flex tm-items-center tm-gap-2",onClick:b,onPointerDown:b,children:[a.jsx(Me,{trigger:a.jsx(p.Icon,{name:ne.faFlag,size:"sm",color:x.color}),children:a.jsx("div",{className:"tm-px-8 tm-py-4",children:a.jsx(p.Text,{color:x.color,children:`Prioridad: ${y}`})})}),s&&a.jsx(p.Text,{as:"span",color:x.color,className:"tm-text-lg tm-font-normal",children:y})]})};function Bo(e,t){return((e==null?void 0:e.map(o=>{var n;return{id:o.id,nombre:o.motivo_imj??"",categoria:(n=o.categoria)==null?void 0:n.nombre}}).filter(o=>o.categoria===t))??[]).filter(o=>typeof o.id=="number"&&!Number.isNaN(o.id)&&o.nombre.length>0).map(o=>({id:o.id,nombre:o.nombre}))}function Ro(e){return e.map(t=>({id:t.id,label:t.nombre}))}const Ue={TO_SECOND:"task-move-first-to-second",TO_THIRD:"task-move-first-to-third",TO_FOURTH:"task-move-first-to-fourth"};function zo(e,t){const s=[];return e===0&&s.push({id:Ue.TO_SECOND,label:"Mover a trabajando",icon:Ee.faArrowRight}),e===1&&s.push({id:Ue.TO_SECOND,label:"Mover a completada",icon:Ee.faArrowRight},{id:Ue.TO_FOURTH,label:"Mover por hacer",icon:Ee.faArrowLeft}),t?s.push({id:Ue.TO_THIRD,label:"Eliminar atraso"}):s.push({id:Ue.TO_THIRD,label:"Agregar atraso"}),s}function qo(e){return e===0?{title:"Mover a trabajando"}:{title:"Mover a completada"}}function $o(){return{title:"Mover a por hacer"}}function va({copy:e,onMove:t}){return a.jsxs("div",{className:"tm-flex tm-h-fit tm-w-max tm-max-w-[280px] tm-translate-x-0 tm-flex-col tm-gap-3 tm-rounded-lg tm-bg-bg-card tm-p-l tm-shadow-02 tm-transition-all tm-duration-200 tm-ease-in-out",children:[a.jsx("p",{className:"tm-text-left tm-text-[14px] tm-font-semibold tm-text-ink-black_medium",children:e.title}),a.jsx(p.Button,{type:"button",fullWidth:!0,size:"xs",color:"primary",onClick:t,children:"Mover"})]})}const Uo=({status:e,nameRequiredTask:t,statusRequiredTask:s,id:o,statusLateTask:n=null,projectID:i,atrasoId:r,categoria:l,disabled:d=!1})=>{const c=u.useRef(null),m=u.useRef(null),f=u.useRef(null),{startWorking:g,completeTask:h,startTask:x}=He(),y=u.useRef(!1),[j,b]=u.useState(!1),[w,v]=u.useState(null),[N,L]=u.useState("first"),O=t!==""&&s===2,[C,F]=u.useState(null),{atrasoReasons:E,isLoading:X,createAtraso:U,deleteAtraso:z}=ns({enabled:!0}),[M,K]=u.useState(null),I=u.useCallback(()=>{var A;(A=c.current)==null||A.close()},[]);u.useEffect(()=>{n&&L("third")},[n]),u.useEffect(()=>{if(!j)return;const A=()=>{I()};return window.addEventListener("scroll",A,!0),document.addEventListener("scroll",A,!0),()=>{window.removeEventListener("scroll",A,!0),document.removeEventListener("scroll",A,!0)}},[j,I]);const $=A=>{L(A),A==="second"?v(e===0?"Trabajando":"Completadas"):A==="fourth"&&v("Por hacer")},R=()=>{if(y!=null&&y.current)return a.jsx("div",{className:"tm-hover:bg-primary-light tm-flex tm-h-fit tm-w-max tm-translate-x-0 tm-items-center tm-gap-2 tm-rounded-lg tm-bg-bg-card tm-p-l tm-shadow-02 tm-transition-all tm-duration-200 tm-ease-in-out",children:a.jsx("p",{className:"tm-font-regular tm-text-sm tm-font-normal tm-text-primary-pastel",children:"Moviendo..."})});const A=zo(e,r);return a.jsx("div",{className:"tm-flex tm-h-fit tm-w-max tm-translate-x-0 tm-flex-col tm-gap-3 tm-rounded-lg tm-bg-bg-card tm-p-l tm-shadow-02 tm-transition-all tm-duration-200 tm-ease-in-out",children:a.jsx(p.ListBase,{variant:"default",list:{items:A},events:{onItemClick:H=>{switch(H.id){case Ue.TO_SECOND:$("second");break;case Ue.TO_THIRD:$("third");break;case Ue.TO_FOURTH:$("fourth");break}}}})})},V=()=>a.jsx(va,{copy:qo(e),onMove:()=>{y.current=!0,w==="Trabajando"?g({id:o}):w==="Por hacer"?x({id:o}):h({id:o,idAtraso:r}),I()}}),G=()=>{if(X)return a.jsx("div",{children:"Cargando motivos..."});const A=Bo(E,l==null?void 0:l.nombre),H=Ro(A);return A.length>0?a.jsxs("div",{className:"tm-flex tm-h-fit tm-w-[288px] tm-translate-x-0 tm-flex-col tm-gap-3 tm-rounded-lg tm-bg-bg-card tm-p-l tm-shadow-02 tm-transition-all tm-duration-200 tm-ease-in-out",children:[!C&&!r?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"tm-mb-[11px] tm-text-left tm-text-[14px] tm-font-semibold tm-text-ink-black_regular",children:"Atraso de tarea"}),a.jsx(p.Dropdown,{field:{placeholder:"Seleccione una opción"},items:{options:H,idName:"id"},values:{value:(M==null?void 0:M.id)??""},menuSearch:{searchable:!0,searchPlaceholder:"Buscar"},popover:{absolute:!1,closeOnClickOutside:!0,dropdownId:`task-atraso-motivo-${o}`,popoverZIndex:1200},events:{onValueChange:Y=>{const B=Number(Y);if(Number.isNaN(B))return;const P=A.find(W=>W.id===B);K({id:B,nombre:(P==null?void 0:P.nombre)??""})},onOptionSelect:Y=>{const B=Y.id;B==null||Number.isNaN(Number(B))||K({id:Number(B),nombre:String(Y.label??"")})}}})]}):a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"tm-text-left tm-text-[14px] tm-font-semibold tm-text-ink-black_medium",children:"¿Estas seguro?"}),a.jsx("p",{className:"tm-text-left tm-text-[14px] tm-font-semibold tm-text-ink-black_medium",children:r?"Estás eliminando el atraso de la tarea seleccionada":`Esta tarea está atrasada debido a ${(C==null?void 0:C.nombre)??""}`})]}),a.jsxs("div",{className:"tm-my-[11px] tm-flex tm-justify-end tm-gap-3",children:[a.jsx(p.Button,{type:"button",size:"xs",color:"secondary",onClick:()=>{C?F(null):I()},children:C?"Regresar":"Cancelar"}),a.jsx(p.Button,{type:"button",size:"xs",color:"primary",onClick:()=>{F(M),r&&!C?z(r):C&&ee()},children:"Aceptar"})]})]}):a.jsx("div",{className:"tm-flex tm-h-fit tm-w-[288px] tm-translate-x-0 tm-flex-col tm-gap-3 tm-rounded-lg tm-bg-bg-card tm-p-l tm-shadow-02 tm-transition-all tm-duration-200 tm-ease-in-out",children:"No hay motivos de atraso para ésta tarea"})},D=()=>a.jsx(va,{copy:$o(),onMove:()=>{y.current=!0,x({id:o}),I()}}),te=()=>{if(N==="first")return R();if(N==="second")return V();if(N==="third")return G();if(N==="fourth")return D()},ee=async()=>{if(M)try{await U({taskId:o,projectID:i,motivo:(M==null?void 0:M.id)??null}),I()}catch(A){console.error("Error al crear atraso:",A)}};return a.jsx(a.Fragment,{children:(O&&s===2||!t)&&a.jsxs(a.Fragment,{children:[a.jsx(p.Button,{ref:m,type:"button","aria-label":"Más opciones para mover la tarea",color:"secondary",pill:"pill",size:"xxs",icon:Ee.faEllipsis,disabled:d}),a.jsx(p.Popup,{ref:c,triggerRef:m,popupId:`task-move-menu-${o}`,position:"bottom-right",offset:1,closeOnClick:!1,closeOnClickOutside:!1,popoverArrow:!1,onOpen:()=>{b(!0),L("first")},onClose:()=>b(!1),children:a.jsx("div",{ref:f,className:`
3
3
  tm-ease tm-transition-all tm-duration-300
4
4
  ${N==="second"?"":"tm-translate-x-0"}
5
- `,children:te()})})]})})},Se={texts:{subtext:"#4f4f4f",placeholder:"#929292"},primary:{regular:"#425CAC"},success:{dark:"#368156",regular:"#43B071"},danger:{dark:"#8C352C",regular:"#C34335"},warning:{dark:"#B4782F",regular:"#D38A31"}},Ho=({id:e,idAtraso:t})=>{const[s,o]=u.useState(!1),{completeTask:n}=He();return{checked:s,checkTask:()=>{o(!s),n({id:e,idAtraso:t})}}},_a={checked:"tm-mx-[2px] tm-flex tm-h-[20px] tm-w-[20px] tm-items-center tm-justify-center tm-rounded-full tm-bg-success-regular tm-transition-all",unchecked:"tm-transition-colors"},Ko="tm-mx-[2px] tm-flex tm-items-center tm-justify-center tm-rounded-full tm-bg-success-regular tm-transition-all",Ta="tm-text-sm tm-flex tm-w-fit tm-max-w-[400px] tm-flex-col tm-gap-m tm-rounded-lg tm-bg-surface-warning-default tm-p-l tm-text-primary",rs=({id:e,nameRequiredTask:t,statusRequiredTask:s,status:o,idAtraso:n,nameRequiredTaskResponsible:i,name_father_required_task:r,name_father_required_task_responsible:l,repeatsAreCompleted:d=!1})=>{const c=u.useId(),m=`checkbox-${e}-${c}`,{checked:f,checkTask:g}=Ho({id:e,idAtraso:n}),x=!!(t&&t!==""&&s===2)||!t,y=!!r,j=o===1&&d,b=()=>a.jsx("label",{htmlFor:m,className:f?_a.checked:_a.unchecked,children:f?a.jsx(p.Icon,{name:ne.faCheck,size:"xs",style:{color:"white"},color:"current"}):a.jsx(p.Icon,{name:ne.faCircle,size:"sm",style:{color:Se.texts.placeholder},color:"current"})});return o===2?a.jsx("div",{className:Ko,children:a.jsx(p.Icon,{name:le.faCircleCheck,size:"xs",style:{color:"white"},color:"current"})}):y?a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"tm-flex tm-w-fit tm-shrink-0 tm-flex-row tm-flex-nowrap tm-items-center tm-gap-1",children:[a.jsx(Me,{position:"bottom",popoverArrow:!1,triggerWrapperClassName:"tm-inline-flex tm-items-center",trigger:a.jsx("span",{className:"tm-cursor-help tm-inline-flex","aria-hidden":!0,children:a.jsx(p.Icon,{name:ne.faCircleInfo,size:"sm",style:{color:Se.warning.regular},color:"current"})}),children:a.jsxs("div",{className:Ta,children:[a.jsx("p",{className:"tm-w-[210px] tm-font-bold",children:"Tarea padre:"}),a.jsx("p",{children:r}),l&&a.jsxs("p",{className:"tm-font-bold",children:["Responsable:"," ",a.jsx("span",{className:"tm-font-normal",children:l})]}),a.jsx(p.Text,{children:"Esta tarea completa automáticamente la tarea padre."})]})}),j&&b()]}),a.jsx("input",{id:m,checked:f,onChange:g,type:"checkbox",className:"tm-hidden","aria-hidden":!0})]}):x?a.jsxs(a.Fragment,{children:[o===1&&b(),a.jsx("input",{id:m,checked:f,onChange:g,type:"checkbox",className:"tm-hidden","aria-hidden":!0})]}):a.jsxs(a.Fragment,{children:[a.jsx(Me,{position:"bottom",popoverArrow:!1,triggerWrapperClassName:"tm-inline-flex tm-items-center",trigger:a.jsx("span",{className:"tm-cursor-help tm-inline-flex","aria-hidden":!0,children:a.jsx(p.Icon,{name:ne.faCircleInfo,size:"sm",style:{color:Se.warning.regular},color:"current"})}),children:a.jsxs("div",{className:Ta,children:[a.jsx("p",{className:"tm-w-[210px] tm-font-bold",children:"Requiere completar su tarea:"}),a.jsx("p",{children:t}),i&&a.jsxs("p",{className:"tm-font-bold",children:["Responsable: ",a.jsx("span",{className:"tm-font-normal",children:i})]})]})}),a.jsx("input",{id:m,checked:f,onChange:g,type:"checkbox",className:"tm-hidden","aria-hidden":!0})]})};function Vo({items:e}){var o;const[t,s]=u.useState(1);return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"tm-mb-2 tm-mt-4 tm-flex tm-flex-row tm-border-b tm-border-black-light tm-bg-surface-default",children:e.map(n=>a.jsx("div",{className:"tm-border-r tm-border-black-light",children:a.jsx(p.Button,{color:"tertiary",pill:"none",size:"xs",active:t===n.id,onClick:()=>s(n.id),children:n.label},n.id)},n.id))}),a.jsx("div",{className:"tm-flex-1 tm-overflow-y-auto tm-bg-surface-default tm-pt-4",children:(o=e.find(n=>n.id===t))==null?void 0:o.component})]})}function Go({comment:e}){var n,i,r,l,d;const{getImageOBP:t}=fe(),s=(l=(r=(i=(n=e==null?void 0:e.autor)==null?void 0:n.imagen)==null?void 0:i.formats)==null?void 0:r.thumbnail)==null?void 0:l.url;function o(c){const m=c==null?new Date:typeof c=="string"?ot.parseISO(c):c;return ot.formatDistanceToNow(m,{locale:Ot.es,addSuffix:!0})}return a.jsx("div",{children:a.jsxs("div",{className:"tm-flex tm-flex-row tm-items-start tm-gap-3",children:[a.jsx(Fe,{size:"xxl",imageUrl:s?t(s):"",alt:"@shadcn"}),a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-4",children:[a.jsxs("div",{className:"tm-flex tm-flex-row tm-items-center tm-gap-4",children:[a.jsx(p.Text,{type:"title",size:"sm",weight:"medium",color:"secondary",children:(d=e==null?void 0:e.autor)==null?void 0:d.nombre}),a.jsx(p.Text,{children:o(e==null?void 0:e.createdAt)})]}),a.jsx(p.Text,{children:e==null?void 0:e.comentario})]})]})})}function Wo({currentUser:e,data:t,taskId:s,onNewComment:o}){var h,x,y;const{tasks_api:n,getImageOBP:i}=fe(),{control:r,handleSubmit:l,reset:d}=Ce.useForm({defaultValues:{comment:""}}),[c,m]=u.useState([]),f=(y=(x=(h=e==null?void 0:e.imagen)==null?void 0:h.formats)==null?void 0:x.thumbnail)==null?void 0:y.url;u.useEffect(()=>{if(t!=null&&t.comentarios){const j=[...t.comentarios].sort((b,w)=>new Date(w.createdAt).getTime()-new Date(b.createdAt).getTime());m(j)}},[t]);const g=async j=>{try{const b={id:Date.now(),autor:{id:e==null?void 0:e.id,email:e==null?void 0:e.email,nombre:e==null?void 0:e.nombre,imagen:e==null?void 0:e.imagen},comentario:j.comment,createdAt:new Date().toISOString(),updatedAt:null};await n.post("/api/comentarios",{data:{autor:e==null?void 0:e.id,comentario:j.comment,tarea:s}}),o(!0),m(w=>[b,...w]),d()}catch(b){console.error("Error al agregar comentario:",b)}};return a.jsxs("div",{className:"tm-flex tm-h-full tm-flex-col tm-gap-4",children:[a.jsxs("form",{onSubmit:l(g),className:"tm-flex tm-flex-row tm-items-center tm-gap-3",children:[a.jsx(Fe,{size:"xxl",imageUrl:f?i(f):"",alt:"@shadcn"}),a.jsx("div",{className:"tm-min-w-0 tm-flex-1",children:a.jsx(Ce.Controller,{name:"comment",control:r,rules:{required:"Escribe un comentario"},render:({field:j,fieldState:{error:b}})=>a.jsx(p.Input,{fullWidth:!0,placeholder:"Escribe un comentario",autoComplete:"off",size:"xs",error:b==null?void 0:b.message,...j,value:j.value??""})})})]}),c&&c.map((j,b)=>a.jsx(Go,{comment:j},b))]})}function Qo(e,t){const s=(e==null?void 0:e.trim())??"";return s?/^https?:\/\//i.test(s)?s:t(s):""}function Xo({data:e}){const{getImageOBP:t}=fe(),s={0:{color:"tm-bg-gray-400",label:"Sin estado"},1:{color:"tm-bg-primary-regular",label:"En curso"},2:{color:"tm-bg-success-regular",label:"Finalizada"},3:{color:"tm-bg-success-regular",label:"Finalizada"}},o=n=>n?ot.format(new Date(n),"d MMM",{locale:Ot.es}):"";return a.jsxs("div",{children:[a.jsxs("div",{className:"tm-flex tm-flex-row tm-items-center tm-gap-4",children:[a.jsx(p.Text,{children:"Tareas dependientes"}),a.jsx(p.Text,{className:"tm-flex tm-h-24 tm-w-24 tm-items-center tm-justify-center tm-rounded-full tm-bg-[#E1EBF9] tm-text-xs tm-font-normal tm-text-primary",children:(e==null?void 0:e.length)??0})]}),a.jsx("div",{className:"tm-mt-3 tm-flex tm-flex-col tm-gap-2 tm-rounded-lg tm-border tm-border-default",children:e==null?void 0:e.map((n,i)=>{var m,f,g,h,x,y,j,b,w,v,N,L;const r=n==null?void 0:n.responsable,l=((g=(f=(m=r==null?void 0:r.image)==null?void 0:m.formats)==null?void 0:f.thumbnail)==null?void 0:g.url)??((y=(x=(h=r==null?void 0:r.imagen)==null?void 0:h.formats)==null?void 0:x.thumbnail)==null?void 0:y.url)??((v=(w=(b=(j=r==null?void 0:r.userOBP)==null?void 0:j.imagen)==null?void 0:b.formats)==null?void 0:w.thumbnail)==null?void 0:v.url),d=(n==null?void 0:n.createdAt)??(n==null?void 0:n.created_at),c=Qo(l,t);return a.jsxs("div",{className:"tm-flex tm-w-full tm-flex-row tm-items-center tm-justify-between tm-gap-s tm-px-2 tm-py-1",children:[a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-8",children:[a.jsx(Fe,{imageUrl:c}),a.jsx(p.Text,{children:((N=n==null?void 0:n.texto_corto)==null?void 0:N.trim())||"—"})]}),a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-1",children:[a.jsx(p.Text,{children:o(d)}),a.jsx("div",{className:`tm-block tm-h-4 tm-w-4 tm-rounded-full tm-bg-gray-400 ${((L=s[n==null?void 0:n.estatus])==null?void 0:L.color)??"tm-bg-gray-400"}`})]})]},n.id!=null?String(n.id):`dep-${i}`)})})]})}function Yo({id:e,texto_largo:t,user_id:s}){const[o,n]=u.useState(t),{updatingTask:i}=He(),r=async()=>{await i({id:e,data:{texto_largo:o},user:s})};return u.useEffect(()=>{n(t)},[t]),a.jsx("div",{className:"tm-mt-16 tm-flex tm-w-full tm-flex-col tm-gap-3",children:a.jsx(p.Textarea,{fullWidth:!0,label:"Descripción",value:o,onChange:n,onBlur:r,placeholder:"Agregar descripción",className:"tm-resize-none"})})}function Na(e,t,s){var n;if(e!=null){const i=e instanceof Date?e:new Date(e);if(!Number.isNaN(i.getTime()))return s(i)}const o=(n=t==null?void 0:t.nombre)==null?void 0:n.trim();return o||s(null)}function is({isOpen:e,setIsOpen:t,taskId:s,initialFromList:o}){var O,C,F,E,X,U,z,M,K;const[n,i]=u.useState(null),[r,l]=u.useState(!1),[d,c]=u.useState(!1),[m,f]=u.useState(null),g=(E=(F=(C=(O=n==null?void 0:n.responsable)==null?void 0:O.imagen)==null?void 0:C.formats)==null?void 0:F.thumbnail)==null?void 0:E.url,{tasks_api:h,getImageOBP:x}=fe(),{user:y}=ve(),j=u.useRef({taskId:null,source:"none"}),b=Number(n==null?void 0:n.estatus),w=Number.isFinite(b)?b:-1,v=ft(y==null?void 0:y.role,w);u.useEffect(()=>{const I=async()=>{const G=await h.get(`/api/users/${y.id}`);f(G==null?void 0:G.data)};if(r){(async()=>{const D=await h.get(`/api/detalleTarea/${s}`);i(D==null?void 0:D.data),j.current={taskId:s,source:"api"}})(),I();return}if(!e){i(null),j.current={taskId:null,source:"none"};return}if(!s)return;const{taskId:$,source:R}=j.current;if($===s&&(R==="api"||R==="list")){R==="list"&&o&&i(G=>{if(!G)return o;const D=o.ids_t_dependientes;if(!Array.isArray(D))return G;const te=Array.isArray(G.ids_t_dependientes)?G.ids_t_dependientes.length:0,ee=D.length;return ee>te||te===0&&ee>0?{...G,ids_t_dependientes:D}:G}),I();return}if(j.current.taskId!=null&&j.current.taskId!==s&&(j.current={taskId:null,source:"none"}),o){i(o),j.current={taskId:s,source:"list"},I();return}(async()=>{const G=await h.get(`/api/detalleTarea/${s}`);i(G==null?void 0:G.data),j.current={taskId:s,source:"api"}})(),I()},[e,s,r,y.id,h,o]);const N=I=>I?ot.format(I,"d MMM yyyy, h:mmaaa",{locale:Ot.es}):"Fecha no disponible",L=u.useMemo(()=>[{id:1,label:"Todo",component:a.jsx(Wo,{taskId:s,currentUser:m,data:n,onNewComment:l})},{id:2,label:"Dependencias",component:a.jsx(Xo,{data:n==null?void 0:n.ids_t_dependientes})}],[n,s,m]);return e&&Lt.createPortal(a.jsxs(a.Fragment,{children:[a.jsx("div",{className:`tm-fixed tm-inset-0 tm-z-20 tm-flex tm-items-center tm-justify-center tm-bg-transparent tm-bg-opacity-50 ${e?"tm-pointer-events-auto tm-block":"tm-pointer-events-none tm-hidden"}`,onClick:()=>t(!1)}),a.jsx("section",{className:`tm-fixed tm-bottom-0 tm-top-0 tm-z-50 tm-flex tm-h-screen tm-w-[550px] tm-items-center tm-justify-center tm-overflow-hidden tm-bg-surface-default tm-bg-opacity-50 tm-shadow-2xl tm-transition-all tm-duration-500 tm-ease-in-out ${e?"tm-pointer-events-auto tm-right-0 tm-block":"tm-pointer-events-none tm-right-[-100%] tm-hidden"}`,children:a.jsxs("div",{className:"tm-flex tm-h-full tm-w-full tm-flex-col tm-overflow-y-scroll tm-border-none tm-bg-surface-default tm-p-16 tm-shadow-04",children:[a.jsxs("div",{className:"tm-flex tm-w-full tm-flex-row tm-items-center tm-justify-between tm-gap-10 tm-border-none tm-pb-4",children:[a.jsxs("div",{className:"tm-relative tm-flex tm-flex-row tm-items-start tm-gap-8",children:[(((X=n==null?void 0:n.id_t_requerida)==null?void 0:X.id)??0)>0?a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"tm-cursor-help",onMouseOver:()=>c(!0),onMouseLeave:()=>c(!1),children:a.jsx(p.Icon,{name:ne.faCircleInfo,size:"sm",style:{color:Se.warning.regular},color:"current"})}),d&&(()=>{var $;const I=it(n==null?void 0:n.id_t_requerida);return a.jsxs("div",{style:{top:"25px"},className:"tm-absolute tm-z-50 tm-flex tm-w-fit tm-max-w-[400px] tm-flex-col tm-gap-m tm-rounded-lg tm-bg-surface-warning-default tm-p-l tm-text-xs tm-text-primary",children:[a.jsx(p.Text,{type:"body",size:"sm",weight:"bold",children:"Requiere completar su tarea:"}),a.jsx(p.Text,{type:"body",size:"xs",weight:"medium",children:($=n==null?void 0:n.id_t_requerida)==null?void 0:$.texto_corto}),I&&a.jsxs(p.Text,{type:"body",size:"xs",weight:"medium",children:["Responsable: ",a.jsx("span",{className:"tm-font-normal",children:I})]})]})})()]}):null,a.jsx("div",{className:"tm-flex tm-flex-row tm-items-center tm-gap-8",children:a.jsxs("h3",{className:"tm-text-base tm-font-semibold tm-text-neutral-900",children:[n==null?void 0:n.texto_corto,(n==null?void 0:n.atraso)&&a.jsx(p.Tooltip,{label:(U=n==null?void 0:n.atraso)==null?void 0:U.motivo,position:"bottom",children:a.jsx("button",{className:"tm-ml-2 tm-inline-block tm-h-fit tm-align-middle",children:a.jsx(p.Icon,{name:ne.faTriangleExclamation,size:"md",style:{color:Se.warning.dark},color:"current"})})})]})})]}),a.jsx(p.Button,{color:"secondary",pill:"pill",size:"xs",onClick:()=>t(!1),icon:ne.faXmark})]}),a.jsx("div",{className:"tm-mt-6 tm-flex tm-w-full tm-flex-row tm-justify-between",children:a.jsxs("span",{className:"tm-text-xs tm-text-light-gray-700",children:[n==null?void 0:n.campania," / ",n==null?void 0:n.nombre_medio]})}),a.jsx(Yo,{id:s,texto_largo:n==null?void 0:n.texto_largo,user_id:y.id}),a.jsx(p.Accordion,{id:`details-task-detalles-${s}`,title:"Detalles",defaultOpen:!0,className:"tm-mt-6 tm-w-full",headerClassName:"tm-border-b tm-border-black-light tm-pb-4",children:a.jsxs("div",{className:"tm-gap-8 tm-grid tm-w-full tm-grid-cols-3 tm-p-4",children:[a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Responsable"}),(z=n==null?void 0:n.responsable)!=null&&z.nombre?a.jsxs("div",{className:"tm-flex tm-flex-row tm-items-center tm-gap-8",children:[a.jsx(Fe,{size:"xxl",imageUrl:g?x(g):"",alt:"@shadcn"}),a.jsx(p.Text,{children:(M=n==null?void 0:n.responsable)==null?void 0:M.nombre})]}):a.jsx(p.Text,{children:"Sin responsable"})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Equipo asignado"}),a.jsx("div",{className:"tm-flex tm-flex-row tm-gap-8",children:a.jsx(p.Text,{children:((K=n==null?void 0:n.equipo)==null?void 0:K.nombre)??"Sin equipo"})})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Prioridad"}),a.jsx(Qt,{priority:parseInt(String(n==null?void 0:n.prioridad),10)||0,id:s,withLabel:!0,canEdit:v})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Dificultad"}),a.jsx(Wt,{difficulty:(n==null?void 0:n.nivel_dificultad)!=null&&(n==null?void 0:n.nivel_dificultad)!==""?Number(n.nivel_dificultad):void 0,id:s,withLabel:!0,canEdit:v})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Lista"}),a.jsx("div",{className:"tm-flex tm-flex-row tm-gap-8",children:a.jsx(p.Text,{children:(n==null?void 0:n.lista)??"Sin lista"})})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Fecha estimada de inicio"}),a.jsx(p.Text,{children:N(n==null?void 0:n.f_inicio_estimada)})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Fecha estimada de fin"}),a.jsx(p.Text,{children:N(n==null?void 0:n.f_fin_estimada)})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Fecha de fin"}),a.jsx(p.Text,{children:N(n==null?void 0:n.ffin)})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Creado"}),a.jsx(p.Text,{children:Na(n==null?void 0:n.createdAt,n==null?void 0:n.createdBy,N)})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Última modificación"}),a.jsx(p.Text,{children:Na(n==null?void 0:n.updatedAt,n==null?void 0:n.updatedBy,N)})]})]})}),a.jsx(Vo,{items:L})]})})]}),document.body)}class Jo{static toPauseReasons(t){return{id:t.id,motivo_imj:t.motivo_imj}}}const Zo=async({tasks_api:e})=>{try{const t=await e.get("/api/motivos");return je(t.data).map(Jo.toPauseReasons)}catch(t){throw console.log("Error al obtener los usuarios comerciales",t),`Error al obtener los usuarios comerciales: ${t}`}},er=()=>{const{tasks_api:e}=fe();return{pauseReasons:de.useQuery({queryKey:["pause_task_reasons"],queryFn:()=>Zo({tasks_api:e}),staleTime:1e3*60*60*24})}},gt=30;function Xt(e,t){var o;if(!(!e||t.reduce((n,i)=>{var r;return n+(((r=i.tasks)==null?void 0:r.length)??0)},0)>=e.total)&&!((((o=e.tasks)==null?void 0:o.length)??0)<gt))return t.length+1}const Yt=e=>{var t;if(e!=null&&e.hasNextPage){const s=(t=e==null?void 0:e.data)==null?void 0:t.pages[e.data.pages.length-1],o=s!=null&&typeof s=="object"&&!Array.isArray(s)&&"tasks"in s&&Array.isArray(s.tasks)?s.tasks:Array.isArray(s)?s:null;((o==null?void 0:o.length)??0)===gt&&(e==null||e.fetchNextPage())}},ht=e=>({pagination:{page:e,pageSize:gt,withCount:!0}});function Jt(e,t,s){var o;return{...e,owner:{user:t.id,config:et((o=e==null?void 0:e.owner)==null?void 0:o.config,t.role),role:t.role},status:s}}function Zt(e){var s;const t=(s=e==null?void 0:e.owner)==null?void 0:s.config;return t!=null&&`${t}`.trim()!==""}const ls=()=>{const{tasks_api:e}=fe(),{user:t}=ve(),{filters:s}=ke(),o=u.useMemo(()=>Jt(s,t,"por_hacer"),[s,t.id,t.role]),n=Zt(s),i=de.useInfiniteQuery({initialPageParam:1,queryKey:["to_do_tasks",o],enabled:n&&!!(t!=null&&t.id),queryFn:({pageParam:l})=>pt({filters:{...o,status:"por_hacer",...ht(l)},tasks_api:e}),staleTime:1e3*60*60*24,getNextPageParam:Xt}),r=u.useMemo(()=>{var l,d,c;return((c=(d=(l=i.data)==null?void 0:l.pages)==null?void 0:d[0])==null?void 0:c.total)??0},[i.data]);return{toDoTasks:i,total:r,filtersToSend:o}};function tr(e){return(e??[]).map(t=>({id:t.id,label:t.motivo_imj}))}const ar=({idTask:e,setOpen:t,paused:s})=>{const o=de.useQueryClient(),{toDoTasks:n,filtersToSend:i}=ls(),[r,l]=u.useState(!1),[d,c]=u.useState(null),{tasksProject:m}=st(),{postPauseTask:f,postReanudeTask:g}=He(),{pauseReasons:h}=er(),x=tr(h==null?void 0:h.data),y=async()=>{try{if(d==null)return;if(t(!1),await f({id:e,motiveId:d}),await o.invalidateQueries({queryKey:["to_do_tasks",i]}),await o.invalidateQueries({queryKey:["tasksProject"]}),n&&typeof n.refetch=="function"||m&&typeof m.refetch=="function"){const b=await n.refetch(),w=await m.refetch();return[b,w]}}catch(b){console.error("Error al pausar la tarea:",b)}},j=async()=>{try{if(t(!1),await g({id:e}),await o.invalidateQueries({queryKey:["to_do_tasks",i]}),await o.invalidateQueries({queryKey:["tasksProject"]}),n&&typeof n.refetch=="function"||m&&typeof m.refetch=="function"){const b=await n.refetch(),w=await m.refetch();return[b,w]}}catch(b){console.error("Error al reanudar la tarea:",b)}};return a.jsx("div",{className:"tm-flex tm-w-[300px] tm-max-w-[300px] tm-items-center !tm-p-4",children:a.jsxs("div",{className:"tm-flex tm-w-full tm-flex-col tm-gap-s ",children:[a.jsx("h6",{className:"tm-font-regular tm-text-texts-subtext tm-truncate tm-text-xl",children:"Pausar tarea:"}),r?a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-s",children:[a.jsx("p",{className:"tm-text-xl tm-font-medium tm-text-neutral-600",children:"Esta acción detendrá la campaña en curso."}),a.jsx("p",{className:"tm-text-xl tm-font-medium tm-text-neutral-600",children:"¿Estás seguro de continuar?"})]}):s?a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-s",children:[a.jsx("p",{className:"tm-text-xl tm-font-medium tm-text-neutral-600",children:"Esta acción reanudará la campaña en curso."}),a.jsx("p",{className:"tm-text-xl tm-font-medium tm-text-neutral-600",children:"¿Estás seguro de continuar?"})]}):a.jsx(p.Dropdown,{field:{placeholder:"Selecciona una razón"},items:{options:x,idName:"id"},values:{value:d??""},menuSearch:{searchable:!0,searchPlaceholder:"Buscar"},popover:{absolute:!1,closeOnClickOutside:!0,dropdownId:`task-pause-motivo-${e}`,popoverZIndex:1200},events:{onValueChange:b=>{const w=Number(b);Number.isNaN(w)||c(w)},onOptionSelect:b=>{const w=Number(b.id);Number.isNaN(w)||c(w)}}}),a.jsxs("div",{className:"tm-mt-5 tm-flex tm-w-full tm-justify-end tm-gap-m",children:[a.jsx(p.Button,{type:"button",onClick:()=>t(!1),size:"xs",color:"secondary",children:"Cancelar"}),s?a.jsx(p.Button,{type:"button",onClick:()=>j(),size:"xs",color:"primary",children:"Si, reanudar"}):a.jsx(p.Button,{type:"button",disabled:!d,onClick:()=>r?y():l(!0),size:"xs",color:"primary",children:"Aceptar"})]})]})})},cs=({idTask:e,paused:t,popupId:s,children:o})=>{const n=u.useRef(null),i=u.useRef(null),[r,l]=u.useState(!1),[d,c]=u.useState(0),m=`task-pause-motivo-${e}`,f=u.useCallback(()=>{var g;(g=n.current)==null||g.close()},[]);return u.useEffect(()=>{if(!r)return;const g=h=>{const x=h.target;x instanceof Element&&(x.closest(`[data-popup-id="${s}"]`)||x.closest(`[data-dropdown-id="${m}"]`))||f()};return window.addEventListener("scroll",g,!0),document.addEventListener("scroll",g,!0),()=>{window.removeEventListener("scroll",g,!0),document.removeEventListener("scroll",g,!0)}},[r,f,s,m]),a.jsxs(a.Fragment,{children:[o(i),a.jsx(p.Popup,{ref:n,triggerRef:i,popupId:s,position:"bottom-left",offset:5,closeOnClick:!1,closeOnClickOutside:!1,popoverArrow:!1,onOpen:()=>{l(!0),c(g=>g+1)},onClose:()=>l(!1),children:a.jsx(ar,{idTask:e,paused:t,setOpen:g=>{g||f()}},d)})]})},sr=({id:e,task:t,endDate:s,users:o,willBePaused:n,nameProject:i,comments:r,priority:l,difficulty:d,responsible:c,nameRequiredTask:m,nameRequiredTaskResponsible:f,statusRequiredTask:g,status:h,repeatsToDo:x,repeats:y,medioName:j,paused:b,idProject:w,atraso:v,categoria:N,cambio_arte:L,name_father_required_task:O,name_father_required_task_responsible:C,panelDataFromList:F,boardColumnTitle:E,isBulkColumnLocked:X=!1})=>{const[U,z]=u.useState(!1),M=u.useId(),{reasignResponsible:K,updateUnitys:I}=He(),{getOBPUrlApi:$}=fe(),[R,V]=u.useState(y??0);u.useEffect(()=>{V(y??0)},[y]);const G=Number(y??0),D=Number(x??0),te=D>0&&G===D,ee=D>1&&!te,A=D<=1,H=h===0,Y=!ee&&(te||A||H)&&h!==2,B=(m??"")!==""&&g===2,{user:P}=ve(),W=ft(P==null?void 0:P.role,h),_=Vt(),S=!!(_!=null&&_.selectedTaskIds.includes(e)),q=Y&&(B||!m),k=!!_&&!!E&&E!=="Completadas"&&!X,T=k&&q,Q=k&&!q&&!!(_!=null&&_.isBulkSessionActive),Z=!!(_!=null&&_.isMultiSelectActive&&T&&B),ae=!T||!!(_!=null&&_.isBulkLoading),re=pe=>{!_||!E||ae||_.toggleTaskSelection(e,E)},J=()=>a.jsxs("div",{className:"tm-relative tm-flex tm-h-fit tm-w-full tm-items-center tm-justify-between",children:[a.jsxs("div",{className:"tm-flex tm-min-w-0 tm-flex-1 tm-flex-row tm-items-start tm-gap-[8px]",children:[h<2&&!ee&&(O||te||A||H)&&a.jsx("span",{"data-prevent-bulk-select":!0,children:a.jsx(rs,{id:e,nameRequiredTask:m??"",statusRequiredTask:g??0,status:h,idAtraso:v==null?void 0:v.atrasoId,nameRequiredTaskResponsible:f,name_father_required_task:O,name_father_required_task_responsible:C,repeatsAreCompleted:te})}),a.jsx("p",{className:"tm-w-full tm-overflow-hidden tm-text-ellipsis tm-text-nowrap tm-text-base tm-text-neutral-900","data-prevent-bulk-select":!0,onClick:pe=>{pe.stopPropagation(),z(!0)},children:t})]}),q&&a.jsxs("div",{className:"tm-flex tm-shrink-0 tm-items-center tm-gap-2","data-prevent-bulk-select":!0,children:[_?a.jsx("div",{className:"tm-flex tm-items-center tm-pt-0.5 tm-pr-2",children:a.jsx(p.Checkbox,{id:`kanban-bulk-select-${e}-${M}`,size:"sm",checked:S,disabled:ae,onChange:re})}):null,a.jsx(Uo,{id:e,nameRequiredTask:m,status:h,statusRequiredTask:g,projectID:w,atrasoId:v==null?void 0:v.atrasoId,categoria:N,disabled:Z})]})]}),se=pe=>{const be=D>0?D:Number(x??0);V(Ae=>{const we=Number.isFinite(Number(Ae))?Number(Ae):G;return pe==="minus"?Math.max(0,we-1):!Number.isFinite(be)||be<=0?we:Math.min(be,we+1)})},ce=pe=>{var be;return((be=pe==null?void 0:pe.charAt(0))==null?void 0:be.toUpperCase())??""},me=pe=>pe==="Venta"?"accent":"danger",ie=X||!!(_!=null&&_.isBulkLoading),ye=Q?"tm-cursor-not-allowed tm-opacity-60 hover:tm-border-cards hover:tm-bg-surface-default":"tm-cursor-pointer hover:tm-border-default hover:tm-border-primary-regular hover:tm-bg-primary-light";return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:`tm-relative tm-h-fit tm-max-w-[350px] tm-rounded-lg tm-border tm-p-[12px_12px] tm-transition-all tm-duration-300 ${ye} ${S?"tm-border-blue-500 tm-bg-primary-light":"tm-border-transparent tm-bg-surface-default"} ${ie?"tm-pointer-events-none":""}`,children:[a.jsx(J,{}),a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-[4px] tm-py-2",children:[a.jsx("p",{className:"tm-font-regular tm-max-w-[250px] tm-truncate tm-text-xs tm-text-texts-subtext",children:i}),j&&a.jsx(p.Text,{type:"body",size:"sm",weight:"medium",children:j})]}),L&&a.jsx(p.Badge,{label:L.nombre,color:"gray",icon:ne.faImage,size:"md",theme:"solid"}),a.jsxs("div",{"data-prevent-bulk-select":!0,className:"tm-relative tm-flex tm-h-fit tm-w-full tm-items-center tm-justify-between tm-pb-1 tm-pt-5",children:[a.jsxs("div",{className:"tm-relative tm-flex tm-items-center",children:[a.jsx(os,{responsible:c,responsibleCandidateIds:o.map(pe=>pe.id),role:P==null?void 0:P.role,status:h,users:o.filter(pe=>c?pe.id===c:!0).map(pe=>Ut(pe,$())),onClick:async(pe,be)=>{await K({idNewResponsible:pe,id:e,typeOfSelect:be})}}),n&&a.jsx(cs,{idTask:e,paused:b,popupId:`task-pause-menu-${e}`,children:pe=>a.jsx("button",{ref:pe,type:"button",className:"tm-font-regular tm-flex !tm-h-[32px] !tm-w-[32px] tm-items-center tm-justify-center tm-gap-2 tm-text-sm tm-text-gray-400",children:a.jsx(p.Icon,{name:b?ne.faPlay:ne.faPause,size:"xs",color:"current"})})})]}),a.jsxs("div",{className:"tm-flex tm-flex-wrap tm-items-center tm-gap-8",children:[a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-8",children:[a.jsx(p.Badge,{label:ce((N==null?void 0:N.tipo)??"P"),color:me((N==null?void 0:N.tipo)??"Preventa"),size:"sm",theme:"solid"}),v&&a.jsx(Me,{trigger:a.jsx(p.Icon,{name:ne.faTriangleExclamation,size:"sm",color:"warning"}),children:a.jsx(p.Text,{color:"warning",children:`Tarea atrasada debido a: ${v==null?void 0:v.motivo}`})}),a.jsx(Wt,{difficulty:d,id:e,canEdit:W}),a.jsx(Qt,{priority:l,id:e,canEdit:W}),!x||x&&h===0&&a.jsxs(a.Fragment,{children:[a.jsx(p.Icon,{name:ne.faCalendar,size:"xs",color:"primary"}),a.jsx(p.Text,{color:"primary",children:`${s.getDate()} ${$t(s.getMonth()).slice(0,3)}`})]})]}),h===1&&D>0&&a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-m",children:[a.jsx(p.Text,{color:"primary",children:"unidades"}),a.jsx("button",{type:"button",onClick:()=>se("minus"),className:"tm-mr-[4px] tm-flex tm-h-8 tm-w-8 tm-shrink-0 tm-items-center tm-justify-center tm-rounded-full tm-bg-surface-default hover:tm-bg-surface-hover",children:a.jsx(p.Icon,{name:ne.faCircleMinus,size:"xs",color:"primary"})}),a.jsx(p.Text,{color:"primary",children:`${R??0} / ${D}`}),a.jsx("button",{type:"button",onClick:()=>se("plus"),className:"tm-ml-[4px] tm-flex tm-h-8 tm-w-8 tm-shrink-0 tm-items-center tm-justify-center tm-rounded-full tm-bg-surface-default hover:tm-bg-surface-hover",children:a.jsx(p.Icon,{name:ne.faCirclePlus,size:"xs",color:"primary"})}),a.jsx(p.Button,{type:"button",color:"primary",size:"xs",pill:"none",className:"tm-ml-[4px]",disabled:R===G,onClick:()=>{I({repeats:R,id:e})},children:"Agregar Unidad"})]})]})]}),r>0&&a.jsx("div",{className:"tm-mt-4 tm-border-t tm-border-default tm-pt-2",children:a.jsxs("button",{type:"button","data-prevent-bulk-select":!0,onClick:pe=>{pe.stopPropagation(),z(!0)},className:"tm-flex tm-items-center tm-gap-8",children:[a.jsx(p.Icon,{name:ne.faComment,size:"xs",color:"current"}),a.jsx("span",{className:"tm-font-regular tm-text-xl tm-text-gray-400",children:r})]})})]}),a.jsx(is,{taskId:e,isOpen:U,setIsOpen:z,initialFromList:F??void 0})]})},xt=({title:e,tasks:t,loadNextPage:s,isFetching:o,total:n,bulkSelectAllIds:i})=>{const r=u.useRef(null),l=u.useRef(null),d=u.useRef(!1);u.useEffect(()=>{const j=r.current,b=l.current;j&&b&&(b.style.minHeight=`${j.clientHeight-300}px`)},[]);const c=j=>{if(d.current)return;const{scrollTop:b,clientHeight:w,scrollHeight:v}=j.currentTarget,N=v-w,L=N===0?0:b/N*100;L<=95||L>=95&&(d.current=!0,s&&s(),setTimeout(()=>{d.current=!1},200))},m={"Por hacer":"tm-border-texts-placeholder",Trabajando:"tm-border-primary-regular",Completadas:"tm-border-success-regular"},f=Vt(),g=e,h=!!(f!=null&&f.baseColumn&&f.baseColumn!==e),x=!!f&&e!=="Completadas"&&(f==null?void 0:f.isBulkSessionActive)&&f.baseColumn===e&&typeof i=="function",y=()=>{if(!(!f||!i)){if(f.isFullColumnSelected){f.deselectAllSelectedTasks();return}f.selectEntireColumn(g,i)}};return a.jsxs("div",{ref:r,className:`tm-relative tm-flex tm-h-full tm-min-h-[100%] tm-w-fit tm-min-w-[400px] tm-max-w-[400px] tm-flex-col tm-overflow-hidden tm-rounded-lg tm-border-t-4 tm-bg-canvas tm-p-[16px] ${m[e]} ${h?"tm-opacity-40":""}`,children:[a.jsxs("div",{className:"tm-flex tm-items-center tm-justify-between",children:[a.jsxs("div",{className:"tm-flex tm-items-center tm-justify-between tm-w-full",children:[a.jsx("p",{className:"tm-text-sm",children:e}),x&&a.jsx("button",{type:"button",className:"tm-text-base tm-text-brand disabled:tm-cursor-not-allowed disabled:tm-opacity-50 tm-mx-3",disabled:f==null?void 0:f.isBulkLoading,onClick:y,children:f!=null&&f.isBulkLoading?"Cargando…":f!=null&&f.isFullColumnSelected?"Quitar Selección":"Seleccionar todas"})]}),a.jsx("div",{className:"tm-flex tm-items-center tm-gap-[8px]",children:a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-[4px]",children:[a.jsx(p.Icon,{name:ne.faFiles,size:"sm",color:"secondary"}),a.jsx("p",{className:"tm-text-base tm-text-texts-placeholder",children:n??0})]})})]}),a.jsxs("div",{ref:l,className:"tm-flex tm-h-full tm-max-w-[350px] tm-flex-col tm-gap-[12px] tm-overflow-y-auto tm-pb-[200px] tm-pt-4 tm-scrollbar-none hover:tm-border-default hover:tm-bg-surface-hover focus:tm-border-default focus:tm-bg-light-gray-50 focus:tm-outline-none",onScroll:c,children:[t==null?void 0:t.map(j=>a.jsx(sr,{...j,boardColumnTitle:f?g:void 0,isBulkColumnLocked:!!(f&&h)},j.id)),o?a.jsx(No,{}):a.jsx("p",{className:"tm-text-center tm-text-sm tm-text-light-gray-900",children:"No hay más tareas por mostrar..."})]})]})},Ca=[{label:"Tipo de dependencia 2",type:"select",id:"dependency",options:[{id:"con",name:"Con dependencia"},{id:"sin",name:"Sin dependencia"},{id:"ambas",name:"Ambas"}]},{label:"Por responsable",type:"select",id:"owner.config",options:[{id:"yo",name:"Mis tareas"},{id:"yo_y_mis_equipos",name:"Tareas mías y de mis equipos"},{id:"mis_equipos",name:"Tareas de mis equipos"}]},{label:"Por dificultad",type:"select",id:"difficulty",options:[{id:1,name:"Muy facil"},{id:2,name:"Facil"},{id:3,name:"Media"},{id:4,name:"Dificil"},{id:5,name:"Muy dificil"}]}],nr=()=>{const{user:e}=ve(),[t,s]=u.useState([...Ca]),o=[{roles:[...Kt],id:"owner.config",filters:[{id:"todas",name:"Todas las tareas"}]}];return u.useEffect(()=>{const n=[...Ca];o.forEach(l=>{if(l.roles.includes(e.role)){const d=n.find(c=>c.id===l.id);d&&(d.options.some(m=>m.id==="todas")||(d.options=[{id:"todas",name:"Todas las tareas"},...d.options]))}});const i=JSON.stringify(t),r=JSON.stringify(n);i!==r&&s(n)},[e.role]),{filters:t}},or="/api/tareas/bulk-update-status";async function rr(e,t){const{data:s}=await e.post(or,t);return s}function ir(e){var t,s,o,n;if(at.isAxiosError(e)){const i=(t=e.response)==null?void 0:t.status,r=(s=e.response)==null?void 0:s.data;if(i===400){if(typeof r=="string"&&r.trim().length>0)return r.trim();if(r&&typeof r=="object"){const l=r.message;if(typeof l=="string"&&l.trim())return l.trim();const d=(o=r.details)==null?void 0:o.errors,c=(n=d==null?void 0:d[0])==null?void 0:n.message;if(typeof c=="string"&&c.trim())return c.trim()}return"Los datos enviados no son válidos. Revisa la selección e inténtalo de nuevo."}return typeof r=="string"&&r.trim().length>0?r.trim():e.message||"No se pudo actualizar las tareas."}return e instanceof Error?e.message:"No se pudo actualizar las tareas."}function lr(){const{tasks_api:e}=fe(),{user:t}=ve();return de.useMutation({mutationKey:["tareas","bulk-update-status"],mutationFn:async s=>{const o=s.user_id??(t==null?void 0:t.id);if(o==null||o<1)throw new Error("No hay usuario válido para la actualización masiva.");try{return await rr(e,{...s,user_id:o})}catch(n){throw new Error(ir(n))}}})}const Nt={MOVE_TO_TRABAJANDO:"kanban-bulk-move-trabajando",MOVE_TO_POR_HACER:"kanban-bulk-move-por-hacer",MOVE_TO_COMPLETADAS:"kanban-bulk-move-completadas"};function cr(e){const{isBulkLoading:t}=e;return[{type:"button",label:"Cancelar",icon:ne.faXmark,color:"secondary",pill:"pill",disabled:t,onClick:()=>{t||(e.setPendingTargetStatus(null),e.setActiveButtonId(null))}},{type:"button",label:"Confirmar",icon:ne.faCheck,color:"secondary",pill:"pill",disabled:t,onClick:()=>{t||e.onConfirmBulkMove()}}]}const Ct="secondary";function dr(e){const t=cr({setActiveButtonId:e.setActiveButtonId,setPendingTargetStatus:e.setPendingTargetStatus,onConfirmBulkMove:e.onConfirmBulkMove,isBulkLoading:e.isBulkLoading});return e.baseColumn==="Por hacer"?[{id:Nt.MOVE_TO_TRABAJANDO,label:"Mover a trabajando",icon:ne.faArrowRight,color:Ct,disabled:e.isBulkLoading,onClick:()=>{e.isBulkLoading||e.setPendingTargetStatus(1)},addons:t}]:e.baseColumn==="Trabajando"?[{id:Nt.MOVE_TO_POR_HACER,label:"Mover a por hacer",icon:ne.faArrowLeft,color:Ct,disabled:e.isBulkLoading,onClick:()=>{e.isBulkLoading||e.setPendingTargetStatus(0)},addons:t},{id:Nt.MOVE_TO_COMPLETADAS,label:"Mover a completadas",icon:ne.faArrowRight,color:Ct,disabled:e.isBulkLoading,onClick:()=>{e.isBulkLoading||e.setPendingTargetStatus(2)},addons:t}]:[]}const mr="Seleccionados";function ds(){const e=Vt(),[t,s]=u.useState(null),o=t!==null,n=de.useQueryClient(),{mutate:i}=lr(),r=(e==null?void 0:e.selectedTaskIds.length)??0;u.useEffect(()=>{r===0&&s(null)},[r]);const l=u.useCallback(()=>{e!=null&&e.isBulkLoading||e==null||e.setPendingTargetStatus(null)},[e]),d=u.useCallback(()=>{s(null),e==null||e.exitBulkSelectionMode()},[e]),c=u.useCallback(()=>{if(!e)return;const f=e.pendingTargetStatus,g=e.selectedTaskIds;if(f==null||g.length===0)return;const h={tasks_ids:[...g],estatus:f,...f===2?{ended_at:new Date().toISOString()}:{}};e.setIsBulkLoading(!0),i(h,{onSettled:()=>{e.setIsBulkLoading(!1)},onSuccess:async()=>{await e.invalidateAfterBulkSuccess(n),s(null),e.exitBulkSelectionMode()},onError:()=>{s(null),e.setPendingTargetStatus(null)}})},[e,i,n]),m=u.useMemo(()=>e?dr({baseColumn:e.baseColumn,setPendingTargetStatus:e.setPendingTargetStatus,setActiveButtonId:s,onConfirmBulkMove:c,isBulkLoading:e.isBulkLoading}):[],[e,c]);return!e||r===0||e.baseColumn!=="Por hacer"&&e.baseColumn!=="Trabajando"?null:a.jsx(p.Toolbar,{visible:!0,count:r,text:mr,activeButtonId:t,onActiveButtonIdChange:s,onBackClick:l,buttons:m,onClose:d,showCounterInButtonsView:!o,showBackButton:!o,showCloseButton:!o})}const ms=["to_do_tasks","working_tasks","done_tasks"],us="tasksProject";function ur(e){return Promise.all(ms.map(t=>e.invalidateQueries({queryKey:[t]}))).then(()=>{})}function pr(e){return Promise.all(ms.map(t=>e.resetQueries({queryKey:[t]}))).then(()=>{})}function fr(e){return e.refetchQueries({queryKey:[us],type:"active"}).then(()=>{})}function gr(e){return e.invalidateQueries({queryKey:[us]}).then(()=>{})}function hr(e){const t=!!(e.repeatsToDo&&e.repeats===e.repeatsToDo),s=!e.repeatsToDo||e.repeatsToDo===1,o=e.status===0;return t||s||o}function xr(e,t){return(e??"")!==""&&(t??0)===2||!(e??"")}function ps(e){return e.status===2||!hr(e)?!1:xr(e.nameRequiredTask,e.statusRequiredTask)}const br=["Por hacer","Trabajando","Completadas"],yr=()=>{const{defineFields:e}=ke(),{tasksProject:t}=st(),{filters:s}=nr();u.useEffect(()=>{e([...s])},[e,s]);const o=u.useMemo(()=>{var i;return(((i=t==null?void 0:t.data)==null?void 0:i.filter(r=>{var l;return(((l=r==null?void 0:r.tasks)==null?void 0:l.length)??0)===0}))??[]).reduce((r,l)=>(r[l.status]=r[l.status]||[],r[l.status].push(l),r),{})},[t==null?void 0:t.data]);return a.jsxs(as,{invalidateAfterBulkSuccess:gr,children:[a.jsx(ds,{}),a.jsx("div",{className:"tm-relative tm-flex tm-h-full tm-min-h-[100%] tm-w-full tm-gap-8",children:br.map((n,i)=>{const r=(o==null?void 0:o[i])??[];return a.jsx(xt,{total:r.length,title:n,tasks:r,isFetching:t==null?void 0:t.isFetching,isLoadingData:t==null?void 0:t.isLoading,bulkSelectAllIds:()=>Promise.resolve(r.filter(l=>ps({status:l.status,nameRequiredTask:l.nameRequiredTask,statusRequiredTask:l.statusRequiredTask,repeatsToDo:l.repeatsToDo,repeats:l.repeats})).map(l=>l.id))},n)})})]})};function jr(e,t){return!e||e.length!==t.length?!1:JSON.stringify(e)===JSON.stringify(t)}async function fs(e){const t=[];let s=1;for(;;){const{tasks:o}=await pt({filters:{...e.filters,status:e.status,...ht(s)},tasks_api:e.tasks_api});for(const n of o)ps({status:n.status,nameRequiredTask:n.nameRequiredTask,statusRequiredTask:n.statusRequiredTask,repeatsToDo:n.repeatsToDo,repeats:n.repeats})&&t.push(n.id);if(o.length<gt)break;s+=1}return t}const wr=()=>{var i,r;const{tasks_api:e}=fe(),{toDoTasks:t,total:s,filtersToSend:o}=ls(),n=[...((r=(i=t==null?void 0:t.data)==null?void 0:i.pages)==null?void 0:r.flatMap(l=>l.tasks))??[]];return a.jsx(xt,{total:s,title:"Por hacer",tasks:n,loadNextPage:()=>Yt(t),isFetching:t==null?void 0:t.isFetching,isLoadingData:t==null?void 0:t.isLoading,bulkSelectAllIds:()=>fs({tasks_api:e,filters:o,status:"por_hacer"})})},vr=()=>{const{tasks_api:e}=fe(),{user:t}=ve(),{filters:s}=ke(),o=u.useMemo(()=>Jt(s,t,"trabajando"),[s,t.id,t.role]),n=Zt(s),i=de.useInfiniteQuery({initialPageParam:1,queryKey:["working_tasks",o],enabled:n&&!!(t!=null&&t.id),queryFn:({pageParam:l})=>pt({filters:{...o,status:"trabajando",...ht(l)},tasks_api:e}),staleTime:1e3*60*60*24,getNextPageParam:Xt}),r=u.useMemo(()=>{var l,d,c;return((c=(d=(l=i.data)==null?void 0:l.pages)==null?void 0:d[0])==null?void 0:c.total)??0},[i.data]);return{workingTasks:i,total:r,filtersToSend:o}},_r=()=>{var i,r;const{tasks_api:e}=fe(),{workingTasks:t,total:s,filtersToSend:o}=vr(),n=[...((r=(i=t==null?void 0:t.data)==null?void 0:i.pages)==null?void 0:r.flatMap(l=>l.tasks))??[]];return a.jsx(xt,{total:s,title:"Trabajando",tasks:n,loadNextPage:()=>Yt(t),isFetching:t==null?void 0:t.isFetching,bulkSelectAllIds:()=>fs({tasks_api:e,filters:o,status:"trabajando"})})},Tr=()=>{const{user:e}=ve(),{tasks_api:t}=fe(),{filters:s}=ke(),o=u.useMemo(()=>Jt(s,e,"completadas"),[s,e.id,e.role]),n=Zt(s),i=de.useInfiniteQuery({initialPageParam:1,queryKey:["done_tasks",o],enabled:n&&!!(e!=null&&e.id),queryFn:({pageParam:l})=>pt({filters:{...o,status:"completadas",...ht(l)},tasks_api:t}),staleTime:1e3*60*60*24,getNextPageParam:Xt}),r=u.useMemo(()=>{var l,d,c;return((c=(d=(l=i.data)==null?void 0:l.pages)==null?void 0:d[0])==null?void 0:c.total)??0},[i.data]);return{doneTasks:i,total:r,filtersToSend:o}},Nr=()=>{var o,n;const{doneTasks:e,total:t}=Tr(),s=[...((n=(o=e==null?void 0:e.data)==null?void 0:o.pages)==null?void 0:n.flatMap(i=>i.tasks))??[]];return a.jsx(xt,{title:"Completadas",tasks:s,loadNextPage:()=>Yt(e),isFetching:e==null?void 0:e.isFetching,total:t})};class ut{static toSalesmanUsers(t){return{id:t.id,name:t.nombre}}}const Cr=()=>{const{tasks_api:e}=fe(),{filters:t}=ke(),{user:s}=ve(),o=async()=>(await e.get("/api/obtener-comerciales")).data.map(ut.toSalesmanUsers),n=async()=>{var l;return(await e.get("/api/listado_tareas",{params:{...ra(t),owner:{user:s.id,config:et((l=t==null?void 0:t.owner)==null?void 0:l.config,s.role),role:s.role},justProjects:!0,cancelada:!1}})).data.map(ut.toSalesmanUsers)};return{getSalesmanAndProjects:u.useCallback(async(r={})=>{var h;const l={...t,...r},d=et((r==null?void 0:r["owner.config"])??((h=t==null?void 0:t.owner)==null?void 0:h.config),s==null?void 0:s.role),c={...l};delete c["owner.config"];const m=ra(c),[f,g]=await Promise.all([e.get("/api/obtener-comerciales"),e.get("/api/listado_tareas",{params:{...m,owner:{user:s==null?void 0:s.id,config:d,role:s.role},justProjects:!0,cancelada:!1}})]);return{salesmanUsers:f.data.map(ut.toSalesmanUsers),projects:g.data.map(ut.toSalesmanUsers)}},[e,t,s==null?void 0:s.id,s==null?void 0:s.role]),getProjects:n,getSalesmans:o}},Sr=()=>{const{user:e}=ve(),[t,s]=u.useState([...la]),o=[{roles:[...Kt],id:"owner.config",filters:[{id:"todas",name:"Todas las tareas"}]}];return u.useEffect(()=>{const n=[...la];o.forEach(l=>{if(l.roles.includes(e.role)){const d=n.find(c=>c.id===l.id);d&&(d.options.some(m=>m.id==="todas")||(d.options=[{id:"todas",name:"Todas las tareas"},...d.options]))}});const i=JSON.stringify(t),r=JSON.stringify(n);i!==r&&s(n)},[e.role]),{filters:t}},Er=()=>{const{defineFields:e,initialFilters:t,fields:s}=ke(),{getSalesmanAndProjects:o}=Cr(),{filters:n}=Sr(),i=u.useRef(s);i.current=s;const r=(t==null?void 0:t["owner.config"])??"yo_y_mis_equipos";return u.useEffect(()=>{let l=!1;return(async()=>{const{salesmanUsers:c,projects:m}=await o({"owner.config":r});if(l)return;const f=n.map(g=>g.id==="project.id"?{...g,options:m}:g.id==="salesman.id"?{...g,options:c}:g);jr(i.current,f)||e(f)})(),()=>{l=!0}},[e,n,o,r]),a.jsxs(as,{invalidateAfterBulkSuccess:ur,children:[a.jsx(ds,{}),a.jsxs("div",{className:"tm-relative tm-flex tm-h-full tm-min-h-[100%] tm-w-full tm-gap-8",children:[a.jsx(wr,{}),a.jsx(_r,{}),a.jsx(Nr,{})]})]})},gs=u.createContext({}),Ar=({children:e})=>{const[t,s]=u.useState([]),o=n=>{s(i=>i.includes(n)?i.filter(r=>r!==n):[...i,n])};return a.jsx(gs.Provider,{value:{selectedTasks:t,selectTask:o},children:e})},Pr=()=>u.useContext(gs),Dr=()=>{const e=()=>a.jsxs("div",{className:"tm-flex tm-w-full tm-gap-m",children:[a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-full tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-w-[30%] tm-animate-pulse tm-rounded-md tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-lg tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-lg tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-lg tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-w-[10%] tm-animate-pulse tm-rounded-md tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-lg tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-w-[10%] tm-animate-pulse tm-rounded-md tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-lg tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-lg tm-bg-gray-200"})]});return a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-m",children:[a.jsx(e,{}),a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-m tm-pl-5",children:[a.jsx(e,{}),a.jsx("div",{className:"tm-pl-5",children:a.jsx(e,{})})]}),a.jsx(e,{}),a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-m tm-pl-5",children:[a.jsx(e,{}),a.jsx("div",{className:"tm-pl-5",children:a.jsx(e,{})})]})]})},hs=({startDate:e,endDate:t})=>a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"tm-flex tm-h-[30px] tm-w-fit tm-items-center tm-justify-center tm-gap-s tm-rounded-md tm-bg-surface-default tm-px-xl",children:[a.jsx(p.Icon,{name:ne.faCalendar,size:"xs",color:"current"}),a.jsxs(p.Text,{children:[" ",xa(e)]})]}),a.jsx(p.Icon,{name:ne.faArrowRight,size:"xs",color:"current"}),a.jsxs("div",{className:"tm-flex tm-h-[30px] tm-w-fit tm-items-center tm-justify-center tm-gap-s tm-rounded-md tm-bg-surface-default tm-px-xxxl",children:[a.jsx(p.Icon,{name:ne.faCalendar,size:"xs",color:"current"}),a.jsxs(p.Text,{children:[" ",xa(t)]})]})]}),xs=({id:e,priority:t,difficulty:s,endDate:o,atraso:n,role:i,status:r})=>{const[l,d]=u.useState(!1),c=ft(i,r),m={0:{title:"N/A",color:Se.success.regular,bg:"tm-bg-texts-placeholder tm-border-texts-placeholder",border:"tm-border-success-medium",borderHover:"hover:tm-border-success-dark"},1:{title:"Baja",color:Se.success.regular,bg:"tm-bg-success-medium tm-border-success-pastel",border:"tm-border-success-pastel",borderHover:"hover:tm-border-success-dark"},2:{title:"Media",color:Se.warning.regular,bg:"tm-bg-warning-light tm-border-warning-regular",border:"tm-border-warning-regular",borderHover:"hover:tm-border-warning-dark"},3:{title:"Alta",color:Se.danger.regular,bg:"tm-bg-danger-light tm-border-danger-regular",border:"tm-border-danger-regular",borderHover:"hover:tm-border-danger-dark"}},f={1:{title:"Muy fácil",color:Se.success.dark,iconColor:"brand",bg:"tm-bg-success-medium tm-border-success-regular",border:"tm-border-success-medium",borderHover:"hover:tm-border-success-dark"},2:{title:"Fácil",color:Se.success.regular,iconColor:"success",bg:"tm-bg-success-medium tm-border-success-pastel",border:"tm-border-success-medium",borderHover:"hover:tm-border-success-dark"},3:{title:"Media",color:Se.warning.regular,iconColor:"warning",bg:"tm-bg-warning-light tm-border-warning-regular",border:"tm-border-warning-medium",borderHover:"hover:tm-border-warning-dark"},4:{title:"Difícil",color:Se.danger.regular,iconColor:"danger",bg:"tm-bg-danger-light tm-border-danger-regular",border:"tm-border-danger-medium",borderHover:"hover:tm-border-danger-dark"},5:{title:"Muy difícil",color:Se.danger.dark,iconColor:"danger",bg:"tm-bg-danger-light tm-border-danger-regular",border:"tm-border-danger-medium",borderHover:"hover:tm-border-danger-dark"}},g=()=>{if(s==null||Number.isNaN(Number(s)))return 1;const b=Math.trunc(Number(s));return b===0?1:b>=1&&b<=5?b:1},h=()=>{if(t==null||Number.isNaN(Number(t)))return 0;const b=Math.trunc(Number(t));return b>=0&&b<=3?b:0},x=f[g()]??f[1],y=m[h()]??m[0],j=o instanceof Date&&!Number.isNaN(o.getTime())?`${o.getDate()} ${$t(o.getMonth()).slice(0,3)}`:"—";return a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"tm-flex tm-h-[30px] tm-w-[30px] tm-items-center tm-justify-center tm-gap-8 tm-rounded-[8px] tm-bg-surface-default hover:tm-bg-surface-hover",children:a.jsx(Me,{trigger:a.jsx(p.Icon,{name:ne.faAlignCenter,size:"xs",color:"current"}),children:a.jsx("div",{className:"tm-px-8 tm-py-4",children:a.jsx(p.Text,{children:"Espéralo muy pronto..."})})})}),a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-8",children:[a.jsx("div",{className:`tm-gap-s ${x.border} ${x.borderHover} transition-all duration-300 tm-flex tm-h-[30px] tm-w-[30px] tm-items-center tm-justify-center
5
+ `,children:te()})})]})})},Se={texts:{subtext:"#4f4f4f",placeholder:"#929292"},primary:{regular:"#425CAC"},success:{dark:"#368156",regular:"#43B071"},danger:{dark:"#8C352C",regular:"#C34335"},warning:{dark:"#B4782F",regular:"#D38A31"}},Ho=({id:e,idAtraso:t})=>{const[s,o]=u.useState(!1),{completeTask:n}=He();return{checked:s,checkTask:()=>{o(!s),n({id:e,idAtraso:t})}}},_a={checked:"tm-mx-[2px] tm-flex tm-h-[20px] tm-w-[20px] tm-items-center tm-justify-center tm-rounded-full tm-bg-success-regular tm-transition-all",unchecked:"tm-transition-colors"},Ko="tm-mx-[2px] tm-flex tm-items-center tm-justify-center tm-rounded-full tm-bg-success-regular tm-transition-all",Ta="tm-text-sm tm-flex tm-w-fit tm-max-w-[400px] tm-flex-col tm-gap-m tm-rounded-lg tm-bg-surface-warning-default tm-p-l tm-text-primary",rs=({id:e,nameRequiredTask:t,statusRequiredTask:s,status:o,idAtraso:n,nameRequiredTaskResponsible:i,name_father_required_task:r,name_father_required_task_responsible:l,repeatsAreCompleted:d=!1})=>{const c=u.useId(),m=`checkbox-${e}-${c}`,{checked:f,checkTask:g}=Ho({id:e,idAtraso:n}),x=!!(t&&t!==""&&s===2)||!t,y=!!r,j=o===1&&d,b=()=>a.jsx("label",{htmlFor:m,className:f?_a.checked:_a.unchecked,children:f?a.jsx(p.Icon,{name:ne.faCheck,size:"xs",style:{color:"white"},color:"current"}):a.jsx(p.Icon,{name:ne.faCircle,size:"sm",style:{color:Se.texts.placeholder},color:"current"})});return o===2?a.jsx("div",{className:Ko,children:a.jsx(p.Icon,{name:le.faCircleCheck,size:"xs",style:{color:"white"},color:"current"})}):y?a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"tm-flex tm-w-fit tm-shrink-0 tm-flex-row tm-flex-nowrap tm-items-center tm-gap-1",children:[a.jsx(Me,{position:"bottom",popoverArrow:!1,triggerWrapperClassName:"tm-inline-flex tm-items-center",trigger:a.jsx("span",{className:"tm-cursor-help tm-inline-flex","aria-hidden":!0,children:a.jsx(p.Icon,{name:ne.faCircleInfo,size:"sm",style:{color:Se.warning.regular},color:"current"})}),children:a.jsxs("div",{className:Ta,children:[a.jsx("p",{className:"tm-w-[210px] tm-font-bold",children:"Tarea padre:"}),a.jsx("p",{children:r}),l&&a.jsxs("p",{className:"tm-font-bold",children:["Responsable:"," ",a.jsx("span",{className:"tm-font-normal",children:l})]}),a.jsx(p.Text,{children:"Esta tarea completa automáticamente la tarea padre."})]})}),j&&b()]}),a.jsx("input",{id:m,checked:f,onChange:g,type:"checkbox",className:"tm-hidden","aria-hidden":!0})]}):x?a.jsxs(a.Fragment,{children:[o===1&&b(),a.jsx("input",{id:m,checked:f,onChange:g,type:"checkbox",className:"tm-hidden","aria-hidden":!0})]}):a.jsxs(a.Fragment,{children:[a.jsx(Me,{position:"bottom",popoverArrow:!1,triggerWrapperClassName:"tm-inline-flex tm-items-center",trigger:a.jsx("span",{className:"tm-cursor-help tm-inline-flex","aria-hidden":!0,children:a.jsx(p.Icon,{name:ne.faCircleInfo,size:"sm",style:{color:Se.warning.regular},color:"current"})}),children:a.jsxs("div",{className:Ta,children:[a.jsx("p",{className:"tm-w-[210px] tm-font-bold",children:"Requiere completar su tarea:"}),a.jsx("p",{children:t}),i&&a.jsxs("p",{className:"tm-font-bold",children:["Responsable: ",a.jsx("span",{className:"tm-font-normal",children:i})]})]})}),a.jsx("input",{id:m,checked:f,onChange:g,type:"checkbox",className:"tm-hidden","aria-hidden":!0})]})};function Vo({items:e}){var o;const[t,s]=u.useState(1);return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"tm-mb-2 tm-mt-4 tm-flex tm-flex-row tm-border-b tm-border-black-light tm-bg-surface-default",children:e.map(n=>a.jsx("div",{className:"tm-border-r tm-border-black-light",children:a.jsx(p.Button,{color:"tertiary",pill:"none",size:"xs",active:t===n.id,onClick:()=>s(n.id),children:n.label},n.id)},n.id))}),a.jsx("div",{className:"tm-flex-1 tm-overflow-y-auto tm-bg-surface-default tm-pt-4",children:(o=e.find(n=>n.id===t))==null?void 0:o.component})]})}function Go({comment:e}){var n,i,r,l,d;const{getImageOBP:t}=fe(),s=(l=(r=(i=(n=e==null?void 0:e.autor)==null?void 0:n.imagen)==null?void 0:i.formats)==null?void 0:r.thumbnail)==null?void 0:l.url;function o(c){const m=c==null?new Date:typeof c=="string"?ot.parseISO(c):c;return ot.formatDistanceToNow(m,{locale:Ot.es,addSuffix:!0})}return a.jsx("div",{children:a.jsxs("div",{className:"tm-flex tm-flex-row tm-items-start tm-gap-3",children:[a.jsx(Fe,{size:"xxl",imageUrl:s?t(s):"",alt:"@shadcn"}),a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-4",children:[a.jsxs("div",{className:"tm-flex tm-flex-row tm-items-center tm-gap-4",children:[a.jsx(p.Text,{type:"title",size:"sm",weight:"medium",color:"secondary",children:(d=e==null?void 0:e.autor)==null?void 0:d.nombre}),a.jsx(p.Text,{children:o(e==null?void 0:e.createdAt)})]}),a.jsx(p.Text,{children:e==null?void 0:e.comentario})]})]})})}function Wo({currentUser:e,data:t,taskId:s,onNewComment:o}){var h,x,y;const{tasks_api:n,getImageOBP:i}=fe(),{control:r,handleSubmit:l,reset:d}=Ce.useForm({defaultValues:{comment:""}}),[c,m]=u.useState([]),f=(y=(x=(h=e==null?void 0:e.imagen)==null?void 0:h.formats)==null?void 0:x.thumbnail)==null?void 0:y.url;u.useEffect(()=>{if(t!=null&&t.comentarios){const j=[...t.comentarios].sort((b,w)=>new Date(w.createdAt).getTime()-new Date(b.createdAt).getTime());m(j)}},[t]);const g=async j=>{try{const b={id:Date.now(),autor:{id:e==null?void 0:e.id,email:e==null?void 0:e.email,nombre:e==null?void 0:e.nombre,imagen:e==null?void 0:e.imagen},comentario:j.comment,createdAt:new Date().toISOString(),updatedAt:null};await n.post("/api/comentarios",{data:{autor:e==null?void 0:e.id,comentario:j.comment,tarea:s}}),o(!0),m(w=>[b,...w]),d()}catch(b){console.error("Error al agregar comentario:",b)}};return a.jsxs("div",{className:"tm-flex tm-h-full tm-flex-col tm-gap-4",children:[a.jsxs("form",{onSubmit:l(g),className:"tm-flex tm-flex-row tm-items-center tm-gap-3",children:[a.jsx(Fe,{size:"xxl",imageUrl:f?i(f):"",alt:"@shadcn"}),a.jsx("div",{className:"tm-min-w-0 tm-flex-1",children:a.jsx(Ce.Controller,{name:"comment",control:r,rules:{required:"Escribe un comentario"},render:({field:j,fieldState:{error:b}})=>a.jsx(p.Input,{fullWidth:!0,placeholder:"Escribe un comentario",autoComplete:"off",size:"xs",error:b==null?void 0:b.message,...j,value:j.value??""})})})]}),c&&c.map((j,b)=>a.jsx(Go,{comment:j},b))]})}function Qo(e,t){const s=(e==null?void 0:e.trim())??"";return s?/^https?:\/\//i.test(s)?s:t(s):""}function Xo({data:e}){const{getImageOBP:t}=fe(),s={0:{color:"tm-bg-gray-400",label:"Sin estado"},1:{color:"tm-bg-primary-regular",label:"En curso"},2:{color:"tm-bg-success-regular",label:"Finalizada"},3:{color:"tm-bg-success-regular",label:"Finalizada"}},o=n=>n?ot.format(new Date(n),"d MMM",{locale:Ot.es}):"";return a.jsxs("div",{children:[a.jsxs("div",{className:"tm-flex tm-flex-row tm-items-center tm-gap-4",children:[a.jsx(p.Text,{children:"Tareas dependientes"}),a.jsx(p.Text,{className:"tm-flex tm-h-24 tm-w-24 tm-items-center tm-justify-center tm-rounded-full tm-bg-[#E1EBF9] tm-text-xs tm-font-normal tm-text-primary",children:(e==null?void 0:e.length)??0})]}),a.jsx("div",{className:"tm-mt-3 tm-flex tm-flex-col tm-gap-2 tm-rounded-lg tm-border tm-border-default",children:e==null?void 0:e.map((n,i)=>{var m,f,g,h,x,y,j,b,w,v,N,L;const r=n==null?void 0:n.responsable,l=((g=(f=(m=r==null?void 0:r.image)==null?void 0:m.formats)==null?void 0:f.thumbnail)==null?void 0:g.url)??((y=(x=(h=r==null?void 0:r.imagen)==null?void 0:h.formats)==null?void 0:x.thumbnail)==null?void 0:y.url)??((v=(w=(b=(j=r==null?void 0:r.userOBP)==null?void 0:j.imagen)==null?void 0:b.formats)==null?void 0:w.thumbnail)==null?void 0:v.url),d=(n==null?void 0:n.createdAt)??(n==null?void 0:n.created_at),c=Qo(l,t);return a.jsxs("div",{className:"tm-flex tm-w-full tm-flex-row tm-items-center tm-justify-between tm-gap-s tm-px-2 tm-py-1",children:[a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-8",children:[a.jsx(Fe,{imageUrl:c}),a.jsx(p.Text,{children:((N=n==null?void 0:n.texto_corto)==null?void 0:N.trim())||"—"})]}),a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-1",children:[a.jsx(p.Text,{children:o(d)}),a.jsx("div",{className:`tm-block tm-h-4 tm-w-4 tm-rounded-full tm-bg-gray-400 ${((L=s[n==null?void 0:n.estatus])==null?void 0:L.color)??"tm-bg-gray-400"}`})]})]},n.id!=null?String(n.id):`dep-${i}`)})})]})}function Yo({id:e,texto_largo:t,user_id:s}){const[o,n]=u.useState(t),{updatingTask:i}=He(),r=async()=>{await i({id:e,data:{texto_largo:o},user:s})};return u.useEffect(()=>{n(t)},[t]),a.jsx("div",{className:"tm-mt-16 tm-flex tm-w-full tm-flex-col tm-gap-3",children:a.jsx(p.Textarea,{fullWidth:!0,label:"Descripción",value:o,onChange:n,onBlur:r,placeholder:"Agregar descripción",className:"tm-resize-none"})})}function Na(e,t,s){var n;if(e!=null){const i=e instanceof Date?e:new Date(e);if(!Number.isNaN(i.getTime()))return s(i)}const o=(n=t==null?void 0:t.nombre)==null?void 0:n.trim();return o||s(null)}function is({isOpen:e,setIsOpen:t,taskId:s,initialFromList:o}){var O,C,F,E,X,U,z,M,K;const[n,i]=u.useState(null),[r,l]=u.useState(!1),[d,c]=u.useState(!1),[m,f]=u.useState(null),g=(E=(F=(C=(O=n==null?void 0:n.responsable)==null?void 0:O.imagen)==null?void 0:C.formats)==null?void 0:F.thumbnail)==null?void 0:E.url,{tasks_api:h,getImageOBP:x}=fe(),{user:y}=ve(),j=u.useRef({taskId:null,source:"none"}),b=Number(n==null?void 0:n.estatus),w=Number.isFinite(b)?b:-1,v=ft(y==null?void 0:y.role,w);u.useEffect(()=>{const I=async()=>{const G=await h.get(`/api/users/${y.id}`);f(G==null?void 0:G.data)};if(r){(async()=>{const D=await h.get(`/api/detalleTarea/${s}`);i(D==null?void 0:D.data),j.current={taskId:s,source:"api"}})(),I();return}if(!e){i(null),j.current={taskId:null,source:"none"};return}if(!s)return;const{taskId:$,source:R}=j.current;if($===s&&(R==="api"||R==="list")){R==="list"&&o&&i(G=>{if(!G)return o;const D=o.ids_t_dependientes;if(!Array.isArray(D))return G;const te=Array.isArray(G.ids_t_dependientes)?G.ids_t_dependientes.length:0,ee=D.length;return ee>te||te===0&&ee>0?{...G,ids_t_dependientes:D}:G}),I();return}if(j.current.taskId!=null&&j.current.taskId!==s&&(j.current={taskId:null,source:"none"}),o){i(o),j.current={taskId:s,source:"list"},I();return}(async()=>{const G=await h.get(`/api/detalleTarea/${s}`);i(G==null?void 0:G.data),j.current={taskId:s,source:"api"}})(),I()},[e,s,r,y.id,h,o]);const N=I=>I?ot.format(I,"d MMM yyyy, h:mmaaa",{locale:Ot.es}):"Fecha no disponible",L=u.useMemo(()=>[{id:1,label:"Todo",component:a.jsx(Wo,{taskId:s,currentUser:m,data:n,onNewComment:l})},{id:2,label:"Dependencias",component:a.jsx(Xo,{data:n==null?void 0:n.ids_t_dependientes})}],[n,s,m]);return e&&Lt.createPortal(a.jsxs(a.Fragment,{children:[a.jsx("div",{className:`tm-fixed tm-inset-0 tm-z-20 tm-flex tm-items-center tm-justify-center tm-bg-transparent tm-bg-opacity-50 ${e?"tm-pointer-events-auto tm-block":"tm-pointer-events-none tm-hidden"}`,onClick:()=>t(!1)}),a.jsx("section",{className:`tm-fixed tm-bottom-0 tm-top-0 tm-z-50 tm-flex tm-h-screen tm-w-[550px] tm-items-center tm-justify-center tm-overflow-hidden tm-bg-surface-default tm-bg-opacity-50 tm-shadow-2xl tm-transition-all tm-duration-500 tm-ease-in-out ${e?"tm-pointer-events-auto tm-right-0 tm-block":"tm-pointer-events-none tm-right-[-100%] tm-hidden"}`,children:a.jsxs("div",{className:"tm-flex tm-h-full tm-w-full tm-flex-col tm-overflow-y-scroll tm-border-none tm-bg-surface-default tm-p-16 tm-shadow-04",children:[a.jsxs("div",{className:"tm-flex tm-w-full tm-flex-row tm-items-center tm-justify-between tm-gap-10 tm-border-none tm-pb-4",children:[a.jsxs("div",{className:"tm-relative tm-flex tm-flex-row tm-items-start tm-gap-8",children:[(((X=n==null?void 0:n.id_t_requerida)==null?void 0:X.id)??0)>0?a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"tm-cursor-help",onMouseOver:()=>c(!0),onMouseLeave:()=>c(!1),children:a.jsx(p.Icon,{name:ne.faCircleInfo,size:"sm",style:{color:Se.warning.regular},color:"current"})}),d&&(()=>{var $;const I=it(n==null?void 0:n.id_t_requerida);return a.jsxs("div",{style:{top:"25px"},className:"tm-absolute tm-z-50 tm-flex tm-w-fit tm-max-w-[400px] tm-flex-col tm-gap-m tm-rounded-lg tm-bg-surface-warning-default tm-p-l tm-text-xs tm-text-primary",children:[a.jsx(p.Text,{type:"body",size:"sm",weight:"bold",children:"Requiere completar su tarea:"}),a.jsx(p.Text,{type:"body",size:"xs",weight:"medium",children:($=n==null?void 0:n.id_t_requerida)==null?void 0:$.texto_corto}),I&&a.jsxs(p.Text,{type:"body",size:"xs",weight:"medium",children:["Responsable: ",a.jsx("span",{className:"tm-font-normal",children:I})]})]})})()]}):null,a.jsx("div",{className:"tm-flex tm-flex-row tm-items-center tm-gap-8",children:a.jsxs("h3",{className:"tm-text-base tm-font-semibold tm-text-neutral-900",children:[n==null?void 0:n.texto_corto,(n==null?void 0:n.atraso)&&a.jsx(p.Tooltip,{label:(U=n==null?void 0:n.atraso)==null?void 0:U.motivo,position:"bottom",children:a.jsx("button",{className:"tm-ml-2 tm-inline-block tm-h-fit tm-align-middle",children:a.jsx(p.Icon,{name:ne.faTriangleExclamation,size:"md",style:{color:Se.warning.dark},color:"current"})})})]})})]}),a.jsx(p.Button,{color:"secondary",pill:"pill",size:"xs",onClick:()=>t(!1),icon:ne.faXmark})]}),a.jsx("div",{className:"tm-mt-6 tm-flex tm-w-full tm-flex-row tm-justify-between",children:a.jsxs("span",{className:"tm-text-xs tm-text-light-gray-700",children:[n==null?void 0:n.campania," / ",n==null?void 0:n.nombre_medio]})}),a.jsx(Yo,{id:s,texto_largo:n==null?void 0:n.texto_largo,user_id:y.id}),a.jsx(p.Accordion,{id:`details-task-detalles-${s}`,title:"Detalles",defaultOpen:!0,className:"tm-mt-6 tm-w-full",headerClassName:"tm-border-b tm-border-black-light tm-pb-4",children:a.jsxs("div",{className:"tm-gap-8 tm-grid tm-w-full tm-grid-cols-3 tm-p-4",children:[a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Responsable"}),(z=n==null?void 0:n.responsable)!=null&&z.nombre?a.jsxs("div",{className:"tm-flex tm-flex-row tm-items-center tm-gap-8",children:[a.jsx(Fe,{size:"xxl",imageUrl:g?x(g):"",alt:"@shadcn"}),a.jsx(p.Text,{children:(M=n==null?void 0:n.responsable)==null?void 0:M.nombre})]}):a.jsx(p.Text,{children:"Sin responsable"})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Equipo asignado"}),a.jsx("div",{className:"tm-flex tm-flex-row tm-gap-8",children:a.jsx(p.Text,{children:((K=n==null?void 0:n.equipo)==null?void 0:K.nombre)??"Sin equipo"})})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Prioridad"}),a.jsx(Qt,{priority:parseInt(String(n==null?void 0:n.prioridad),10)||0,id:s,withLabel:!0,canEdit:v})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Dificultad"}),a.jsx(Wt,{difficulty:(n==null?void 0:n.nivel_dificultad)!=null&&(n==null?void 0:n.nivel_dificultad)!==""?Number(n.nivel_dificultad):void 0,id:s,withLabel:!0,canEdit:v})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Lista"}),a.jsx("div",{className:"tm-flex tm-flex-row tm-gap-8",children:a.jsx(p.Text,{children:(n==null?void 0:n.lista)??"Sin lista"})})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Fecha estimada de inicio"}),a.jsx(p.Text,{children:N(n==null?void 0:n.f_inicio_estimada)})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Fecha estimada de fin"}),a.jsx(p.Text,{children:N(n==null?void 0:n.f_fin_estimada)})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Fecha de fin"}),a.jsx(p.Text,{children:N(n==null?void 0:n.ffin)})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Creado"}),a.jsx(p.Text,{children:Na(n==null?void 0:n.createdAt,n==null?void 0:n.createdBy,N)})]}),a.jsxs("div",{className:"tm-flex tm-w-auto tm-flex-col tm-gap-8",children:[a.jsx("span",{className:" tm-text-sm tm-font-semibold tm-leading-[100%] tm-tracking-normal",children:"Última modificación"}),a.jsx(p.Text,{children:Na(n==null?void 0:n.updatedAt,n==null?void 0:n.updatedBy,N)})]})]})}),a.jsx(Vo,{items:L})]})})]}),document.body)}class Jo{static toPauseReasons(t){return{id:t.id,motivo_imj:t.motivo_imj}}}const Zo=async({tasks_api:e})=>{try{const t=await e.get("/api/motivos");return je(t.data).map(Jo.toPauseReasons)}catch(t){throw console.log("Error al obtener los usuarios comerciales",t),`Error al obtener los usuarios comerciales: ${t}`}},er=()=>{const{tasks_api:e}=fe();return{pauseReasons:de.useQuery({queryKey:["pause_task_reasons"],queryFn:()=>Zo({tasks_api:e}),staleTime:1e3*60*60*24})}},gt=30;function Xt(e,t){var o;if(!(!e||t.reduce((n,i)=>{var r;return n+(((r=i.tasks)==null?void 0:r.length)??0)},0)>=e.total)&&!((((o=e.tasks)==null?void 0:o.length)??0)<gt))return t.length+1}const Yt=e=>{var t;if(e!=null&&e.hasNextPage){const s=(t=e==null?void 0:e.data)==null?void 0:t.pages[e.data.pages.length-1],o=s!=null&&typeof s=="object"&&!Array.isArray(s)&&"tasks"in s&&Array.isArray(s.tasks)?s.tasks:Array.isArray(s)?s:null;((o==null?void 0:o.length)??0)===gt&&(e==null||e.fetchNextPage())}},ht=e=>({pagination:{page:e,pageSize:gt,withCount:!0}});function Jt(e,t,s){var o;return{...e,owner:{user:t.id,config:et((o=e==null?void 0:e.owner)==null?void 0:o.config,t.role),role:t.role},status:s}}function Zt(e){var s;const t=(s=e==null?void 0:e.owner)==null?void 0:s.config;return t!=null&&`${t}`.trim()!==""}const ls=()=>{const{tasks_api:e}=fe(),{user:t}=ve(),{filters:s}=ke(),o=u.useMemo(()=>Jt(s,t,"por_hacer"),[s,t.id,t.role]),n=Zt(s),i=de.useInfiniteQuery({initialPageParam:1,queryKey:["to_do_tasks",o],enabled:n&&!!(t!=null&&t.id),queryFn:({pageParam:l})=>pt({filters:{...o,status:"por_hacer",...ht(l)},tasks_api:e}),staleTime:1e3*60*60*24,getNextPageParam:Xt}),r=u.useMemo(()=>{var l,d,c;return((c=(d=(l=i.data)==null?void 0:l.pages)==null?void 0:d[0])==null?void 0:c.total)??0},[i.data]);return{toDoTasks:i,total:r,filtersToSend:o}};function tr(e){return(e??[]).map(t=>({id:t.id,label:t.motivo_imj}))}const ar=({idTask:e,setOpen:t,paused:s})=>{const o=de.useQueryClient(),{toDoTasks:n,filtersToSend:i}=ls(),[r,l]=u.useState(!1),[d,c]=u.useState(null),{tasksProject:m}=st(),{postPauseTask:f,postReanudeTask:g}=He(),{pauseReasons:h}=er(),x=tr(h==null?void 0:h.data),y=async()=>{try{if(d==null)return;if(t(!1),await f({id:e,motiveId:d}),await o.invalidateQueries({queryKey:["to_do_tasks",i]}),await o.invalidateQueries({queryKey:["tasksProject"]}),n&&typeof n.refetch=="function"||m&&typeof m.refetch=="function"){const b=await n.refetch(),w=await m.refetch();return[b,w]}}catch(b){console.error("Error al pausar la tarea:",b)}},j=async()=>{try{if(t(!1),await g({id:e}),await o.invalidateQueries({queryKey:["to_do_tasks",i]}),await o.invalidateQueries({queryKey:["tasksProject"]}),n&&typeof n.refetch=="function"||m&&typeof m.refetch=="function"){const b=await n.refetch(),w=await m.refetch();return[b,w]}}catch(b){console.error("Error al reanudar la tarea:",b)}};return a.jsx("div",{className:"tm-flex tm-w-[300px] tm-max-w-[300px] tm-items-center !tm-p-4",children:a.jsxs("div",{className:"tm-flex tm-w-full tm-flex-col tm-gap-s ",children:[a.jsx("h6",{className:"tm-font-regular tm-text-texts-subtext tm-truncate tm-text-xl",children:"Pausar tarea:"}),r?a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-s",children:[a.jsx("p",{className:"tm-text-xl tm-font-medium tm-text-neutral-600",children:"Esta acción detendrá la campaña en curso."}),a.jsx("p",{className:"tm-text-xl tm-font-medium tm-text-neutral-600",children:"¿Estás seguro de continuar?"})]}):s?a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-s",children:[a.jsx("p",{className:"tm-text-xl tm-font-medium tm-text-neutral-600",children:"Esta acción reanudará la campaña en curso."}),a.jsx("p",{className:"tm-text-xl tm-font-medium tm-text-neutral-600",children:"¿Estás seguro de continuar?"})]}):a.jsx(p.Dropdown,{field:{placeholder:"Selecciona una razón"},items:{options:x,idName:"id"},values:{value:d??""},menuSearch:{searchable:!0,searchPlaceholder:"Buscar"},popover:{absolute:!1,closeOnClickOutside:!0,dropdownId:`task-pause-motivo-${e}`,popoverZIndex:1200},events:{onValueChange:b=>{const w=Number(b);Number.isNaN(w)||c(w)},onOptionSelect:b=>{const w=Number(b.id);Number.isNaN(w)||c(w)}}}),a.jsxs("div",{className:"tm-mt-5 tm-flex tm-w-full tm-justify-end tm-gap-m",children:[a.jsx(p.Button,{type:"button",onClick:()=>t(!1),size:"xs",color:"secondary",children:"Cancelar"}),s?a.jsx(p.Button,{type:"button",onClick:()=>j(),size:"xs",color:"primary",children:"Si, reanudar"}):a.jsx(p.Button,{type:"button",disabled:!d,onClick:()=>r?y():l(!0),size:"xs",color:"primary",children:"Aceptar"})]})]})})},cs=({idTask:e,paused:t,popupId:s,children:o})=>{const n=u.useRef(null),i=u.useRef(null),[r,l]=u.useState(!1),[d,c]=u.useState(0),m=`task-pause-motivo-${e}`,f=u.useCallback(()=>{var g;(g=n.current)==null||g.close()},[]);return u.useEffect(()=>{if(!r)return;const g=h=>{const x=h.target;x instanceof Element&&(x.closest(`[data-popup-id="${s}"]`)||x.closest(`[data-dropdown-id="${m}"]`))||f()};return window.addEventListener("scroll",g,!0),document.addEventListener("scroll",g,!0),()=>{window.removeEventListener("scroll",g,!0),document.removeEventListener("scroll",g,!0)}},[r,f,s,m]),a.jsxs(a.Fragment,{children:[o(i),a.jsx(p.Popup,{ref:n,triggerRef:i,popupId:s,position:"bottom-left",offset:5,closeOnClick:!1,closeOnClickOutside:!1,popoverArrow:!1,onOpen:()=>{l(!0),c(g=>g+1)},onClose:()=>l(!1),children:a.jsx(ar,{idTask:e,paused:t,setOpen:g=>{g||f()}},d)})]})},sr=({id:e,task:t,endDate:s,users:o,willBePaused:n,nameProject:i,comments:r,priority:l,difficulty:d,responsible:c,nameRequiredTask:m,nameRequiredTaskResponsible:f,statusRequiredTask:g,status:h,repeatsToDo:x,repeats:y,medioName:j,paused:b,idProject:w,atraso:v,categoria:N,cambio_arte:L,name_father_required_task:O,name_father_required_task_responsible:C,panelDataFromList:F,boardColumnTitle:E,isBulkColumnLocked:X=!1})=>{const[U,z]=u.useState(!1),M=u.useId(),{reasignResponsible:K,updateUnitys:I}=He(),{getOBPUrlApi:$}=fe(),[R,V]=u.useState(y??0);u.useEffect(()=>{V(y??0)},[y]);const G=Number(y??0),D=Number(x??0),te=D>0&&G===D,ee=D>=1&&!te&&h===1,A=D<=1,H=h===0,Y=!ee&&(te||A||H)&&h!==2,B=(m??"")!==""&&g===2,{user:P}=ve(),W=ft(P==null?void 0:P.role,h),_=Vt(),S=!!(_!=null&&_.selectedTaskIds.includes(e)),q=Y&&(B||!m),k=!!_&&!!E&&E!=="Completadas"&&!X,T=k&&q,Q=k&&!q&&!!(_!=null&&_.isBulkSessionActive),Z=!!(_!=null&&_.isMultiSelectActive&&T&&B),ae=!T||!!(_!=null&&_.isBulkLoading),re=pe=>{!_||!E||ae||_.toggleTaskSelection(e,E)},J=()=>a.jsxs("div",{className:"tm-relative tm-flex tm-h-fit tm-w-full tm-items-center tm-justify-between",children:[a.jsxs("div",{className:"tm-flex tm-min-w-0 tm-flex-1 tm-flex-row tm-items-start tm-gap-[8px]",children:[h<2&&!ee&&(O||te||A||H)&&a.jsx("span",{"data-prevent-bulk-select":!0,children:a.jsx(rs,{id:e,nameRequiredTask:m??"",statusRequiredTask:g??0,status:h,idAtraso:v==null?void 0:v.atrasoId,nameRequiredTaskResponsible:f,name_father_required_task:O,name_father_required_task_responsible:C,repeatsAreCompleted:te})}),a.jsx("p",{className:"tm-w-full tm-overflow-hidden tm-text-ellipsis tm-text-nowrap tm-text-base tm-text-neutral-900","data-prevent-bulk-select":!0,onClick:pe=>{pe.stopPropagation(),z(!0)},children:t})]}),q&&a.jsxs("div",{className:"tm-flex tm-shrink-0 tm-items-center tm-gap-2","data-prevent-bulk-select":!0,children:[_?a.jsx("div",{className:"tm-flex tm-items-center tm-pt-0.5 tm-pr-2",children:a.jsx(p.Checkbox,{id:`kanban-bulk-select-${e}-${M}`,size:"sm",checked:S,disabled:ae,onChange:re})}):null,a.jsx(Uo,{id:e,nameRequiredTask:m,status:h,statusRequiredTask:g,projectID:w,atrasoId:v==null?void 0:v.atrasoId,categoria:N,disabled:Z})]})]}),se=pe=>{const be=D>0?D:Number(x??0);V(Ae=>{const we=Number.isFinite(Number(Ae))?Number(Ae):G;return pe==="minus"?Math.max(0,we-1):!Number.isFinite(be)||be<=0?we:Math.min(be,we+1)})},ce=pe=>{var be;return((be=pe==null?void 0:pe.charAt(0))==null?void 0:be.toUpperCase())??""},me=pe=>pe==="Venta"?"accent":"danger",ie=X||!!(_!=null&&_.isBulkLoading),ye=Q?"tm-cursor-not-allowed tm-opacity-60 hover:tm-border-cards hover:tm-bg-surface-default":"tm-cursor-pointer hover:tm-border-default hover:tm-border-primary-regular hover:tm-bg-primary-light";return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:`tm-relative tm-h-fit tm-max-w-[350px] tm-rounded-lg tm-border tm-p-[12px_12px] tm-transition-all tm-duration-300 ${ye} ${S?"tm-border-blue-500 tm-bg-primary-light":"tm-border-transparent tm-bg-surface-default"} ${ie?"tm-pointer-events-none":""}`,children:[a.jsx(J,{}),a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-[4px] tm-py-2",children:[a.jsx("p",{className:"tm-font-regular tm-max-w-[250px] tm-truncate tm-text-xs tm-text-texts-subtext",children:i}),j&&a.jsx(p.Text,{type:"body",size:"sm",weight:"medium",children:j})]}),L&&a.jsx(p.Badge,{label:L.nombre,color:"gray",icon:ne.faImage,size:"md",theme:"solid"}),a.jsxs("div",{"data-prevent-bulk-select":!0,className:"tm-relative tm-flex tm-h-fit tm-w-full tm-items-center tm-justify-between tm-pb-1 tm-pt-5",children:[a.jsxs("div",{className:"tm-relative tm-flex tm-items-center",children:[a.jsx(os,{responsible:c,responsibleCandidateIds:o.map(pe=>pe.id),role:P==null?void 0:P.role,status:h,users:o.filter(pe=>c?pe.id===c:!0).map(pe=>Ut(pe,$())),onClick:async(pe,be)=>{await K({idNewResponsible:pe,id:e,typeOfSelect:be})}}),n&&a.jsx(cs,{idTask:e,paused:b,popupId:`task-pause-menu-${e}`,children:pe=>a.jsx("button",{ref:pe,type:"button",className:"tm-font-regular tm-flex !tm-h-[32px] !tm-w-[32px] tm-items-center tm-justify-center tm-gap-2 tm-text-sm tm-text-gray-400",children:a.jsx(p.Icon,{name:b?ne.faPlay:ne.faPause,size:"xs",color:"current"})})})]}),a.jsxs("div",{className:"tm-flex tm-flex-wrap tm-items-center tm-gap-8",children:[a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-8",children:[a.jsx(p.Badge,{label:ce((N==null?void 0:N.tipo)??"P"),color:me((N==null?void 0:N.tipo)??"Preventa"),size:"sm",theme:"solid"}),v&&a.jsx(Me,{trigger:a.jsx(p.Icon,{name:ne.faTriangleExclamation,size:"sm",color:"warning"}),children:a.jsx(p.Text,{color:"warning",children:`Tarea atrasada debido a: ${v==null?void 0:v.motivo}`})}),a.jsx(Wt,{difficulty:d,id:e,canEdit:W}),a.jsx(Qt,{priority:l,id:e,canEdit:W}),!x||x&&h===0&&a.jsxs(a.Fragment,{children:[a.jsx(p.Icon,{name:ne.faCalendar,size:"xs",color:"primary"}),a.jsx(p.Text,{color:"primary",children:`${s.getDate()} ${$t(s.getMonth()).slice(0,3)}`})]})]}),h===1&&D>0&&a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-m",children:[a.jsx(p.Text,{color:"primary",children:"unidades"}),a.jsx("button",{type:"button",onClick:()=>se("minus"),className:"tm-mr-[4px] tm-flex tm-h-8 tm-w-8 tm-shrink-0 tm-items-center tm-justify-center tm-rounded-full tm-bg-surface-default hover:tm-bg-surface-hover",children:a.jsx(p.Icon,{name:ne.faCircleMinus,size:"xs",color:"primary"})}),a.jsx(p.Text,{color:"primary",children:`${R??0} / ${D}`}),a.jsx("button",{type:"button",onClick:()=>se("plus"),className:"tm-ml-[4px] tm-flex tm-h-8 tm-w-8 tm-shrink-0 tm-items-center tm-justify-center tm-rounded-full tm-bg-surface-default hover:tm-bg-surface-hover",children:a.jsx(p.Icon,{name:ne.faCirclePlus,size:"xs",color:"primary"})}),a.jsx(p.Button,{type:"button",color:"primary",size:"xs",pill:"none",className:"tm-ml-[4px]",disabled:R===G,onClick:()=>{I({repeats:R,id:e})},children:"Agregar Unidad"})]})]})]}),r>0&&a.jsx("div",{className:"tm-mt-4 tm-border-t tm-border-default tm-pt-2",children:a.jsxs("button",{type:"button","data-prevent-bulk-select":!0,onClick:pe=>{pe.stopPropagation(),z(!0)},className:"tm-flex tm-items-center tm-gap-8",children:[a.jsx(p.Icon,{name:ne.faComment,size:"xs",color:"current"}),a.jsx("span",{className:"tm-font-regular tm-text-xl tm-text-gray-400",children:r})]})})]}),a.jsx(is,{taskId:e,isOpen:U,setIsOpen:z,initialFromList:F??void 0})]})},xt=({title:e,tasks:t,loadNextPage:s,isFetching:o,total:n,bulkSelectAllIds:i})=>{const r=u.useRef(null),l=u.useRef(null),d=u.useRef(!1);u.useEffect(()=>{const j=r.current,b=l.current;j&&b&&(b.style.minHeight=`${j.clientHeight-300}px`)},[]);const c=j=>{if(d.current)return;const{scrollTop:b,clientHeight:w,scrollHeight:v}=j.currentTarget,N=v-w,L=N===0?0:b/N*100;L<=95||L>=95&&(d.current=!0,s&&s(),setTimeout(()=>{d.current=!1},200))},m={"Por hacer":"tm-border-texts-placeholder",Trabajando:"tm-border-primary-regular",Completadas:"tm-border-success-regular"},f=Vt(),g=e,h=!!(f!=null&&f.baseColumn&&f.baseColumn!==e),x=!!f&&e!=="Completadas"&&(f==null?void 0:f.isBulkSessionActive)&&f.baseColumn===e&&typeof i=="function",y=()=>{if(!(!f||!i)){if(f.isFullColumnSelected){f.deselectAllSelectedTasks();return}f.selectEntireColumn(g,i)}};return a.jsxs("div",{ref:r,className:`tm-relative tm-flex tm-h-full tm-min-h-[100%] tm-w-fit tm-min-w-[400px] tm-max-w-[400px] tm-flex-col tm-overflow-hidden tm-rounded-lg tm-border-t-4 tm-bg-canvas tm-p-[16px] ${m[e]} ${h?"tm-opacity-40":""}`,children:[a.jsxs("div",{className:"tm-flex tm-items-center tm-justify-between",children:[a.jsxs("div",{className:"tm-flex tm-items-center tm-justify-between tm-w-full",children:[a.jsx("p",{className:"tm-text-sm",children:e}),x&&a.jsx("button",{type:"button",className:"tm-text-base tm-text-brand disabled:tm-cursor-not-allowed disabled:tm-opacity-50 tm-mx-3",disabled:f==null?void 0:f.isBulkLoading,onClick:y,children:f!=null&&f.isBulkLoading?"Cargando…":f!=null&&f.isFullColumnSelected?"Quitar Selección":"Seleccionar todas"})]}),a.jsx("div",{className:"tm-flex tm-items-center tm-gap-[8px]",children:a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-[4px]",children:[a.jsx(p.Icon,{name:ne.faFiles,size:"sm",color:"secondary"}),a.jsx("p",{className:"tm-text-base tm-text-texts-placeholder",children:n??0})]})})]}),a.jsxs("div",{ref:l,className:"tm-flex tm-h-full tm-max-w-[350px] tm-flex-col tm-gap-[12px] tm-overflow-y-auto tm-pb-[200px] tm-pt-4 tm-scrollbar-none hover:tm-border-default hover:tm-bg-surface-hover focus:tm-border-default focus:tm-bg-light-gray-50 focus:tm-outline-none",onScroll:c,children:[t==null?void 0:t.map(j=>a.jsx(sr,{...j,boardColumnTitle:f?g:void 0,isBulkColumnLocked:!!(f&&h)},j.id)),o?a.jsx(No,{}):a.jsx("p",{className:"tm-text-center tm-text-sm tm-text-light-gray-900",children:"No hay más tareas por mostrar..."})]})]})},Ca=[{label:"Tipo de dependencia 2",type:"select",id:"dependency",options:[{id:"con",name:"Con dependencia"},{id:"sin",name:"Sin dependencia"},{id:"ambas",name:"Ambas"}]},{label:"Por responsable",type:"select",id:"owner.config",options:[{id:"yo",name:"Mis tareas"},{id:"yo_y_mis_equipos",name:"Tareas mías y de mis equipos"},{id:"mis_equipos",name:"Tareas de mis equipos"}]},{label:"Por dificultad",type:"select",id:"difficulty",options:[{id:1,name:"Muy facil"},{id:2,name:"Facil"},{id:3,name:"Media"},{id:4,name:"Dificil"},{id:5,name:"Muy dificil"}]}],nr=()=>{const{user:e}=ve(),[t,s]=u.useState([...Ca]),o=[{roles:[...Kt],id:"owner.config",filters:[{id:"todas",name:"Todas las tareas"}]}];return u.useEffect(()=>{const n=[...Ca];o.forEach(l=>{if(l.roles.includes(e.role)){const d=n.find(c=>c.id===l.id);d&&(d.options.some(m=>m.id==="todas")||(d.options=[{id:"todas",name:"Todas las tareas"},...d.options]))}});const i=JSON.stringify(t),r=JSON.stringify(n);i!==r&&s(n)},[e.role]),{filters:t}},or="/api/tareas/bulk-update-status";async function rr(e,t){const{data:s}=await e.post(or,t);return s}function ir(e){var t,s,o,n;if(at.isAxiosError(e)){const i=(t=e.response)==null?void 0:t.status,r=(s=e.response)==null?void 0:s.data;if(i===400){if(typeof r=="string"&&r.trim().length>0)return r.trim();if(r&&typeof r=="object"){const l=r.message;if(typeof l=="string"&&l.trim())return l.trim();const d=(o=r.details)==null?void 0:o.errors,c=(n=d==null?void 0:d[0])==null?void 0:n.message;if(typeof c=="string"&&c.trim())return c.trim()}return"Los datos enviados no son válidos. Revisa la selección e inténtalo de nuevo."}return typeof r=="string"&&r.trim().length>0?r.trim():e.message||"No se pudo actualizar las tareas."}return e instanceof Error?e.message:"No se pudo actualizar las tareas."}function lr(){const{tasks_api:e}=fe(),{user:t}=ve();return de.useMutation({mutationKey:["tareas","bulk-update-status"],mutationFn:async s=>{const o=s.user_id??(t==null?void 0:t.id);if(o==null||o<1)throw new Error("No hay usuario válido para la actualización masiva.");try{return await rr(e,{...s,user_id:o})}catch(n){throw new Error(ir(n))}}})}const Nt={MOVE_TO_TRABAJANDO:"kanban-bulk-move-trabajando",MOVE_TO_POR_HACER:"kanban-bulk-move-por-hacer",MOVE_TO_COMPLETADAS:"kanban-bulk-move-completadas"};function cr(e){const{isBulkLoading:t}=e;return[{type:"button",label:"Cancelar",icon:ne.faXmark,color:"secondary",pill:"pill",disabled:t,onClick:()=>{t||(e.setPendingTargetStatus(null),e.setActiveButtonId(null))}},{type:"button",label:"Confirmar",icon:ne.faCheck,color:"secondary",pill:"pill",disabled:t,onClick:()=>{t||e.onConfirmBulkMove()}}]}const Ct="secondary";function dr(e){const t=cr({setActiveButtonId:e.setActiveButtonId,setPendingTargetStatus:e.setPendingTargetStatus,onConfirmBulkMove:e.onConfirmBulkMove,isBulkLoading:e.isBulkLoading});return e.baseColumn==="Por hacer"?[{id:Nt.MOVE_TO_TRABAJANDO,label:"Mover a trabajando",icon:ne.faArrowRight,color:Ct,disabled:e.isBulkLoading,onClick:()=>{e.isBulkLoading||e.setPendingTargetStatus(1)},addons:t}]:e.baseColumn==="Trabajando"?[{id:Nt.MOVE_TO_POR_HACER,label:"Mover a por hacer",icon:ne.faArrowLeft,color:Ct,disabled:e.isBulkLoading,onClick:()=>{e.isBulkLoading||e.setPendingTargetStatus(0)},addons:t},{id:Nt.MOVE_TO_COMPLETADAS,label:"Mover a completadas",icon:ne.faArrowRight,color:Ct,disabled:e.isBulkLoading,onClick:()=>{e.isBulkLoading||e.setPendingTargetStatus(2)},addons:t}]:[]}const mr="Seleccionados";function ds(){const e=Vt(),[t,s]=u.useState(null),o=t!==null,n=de.useQueryClient(),{mutate:i}=lr(),r=(e==null?void 0:e.selectedTaskIds.length)??0;u.useEffect(()=>{r===0&&s(null)},[r]);const l=u.useCallback(()=>{e!=null&&e.isBulkLoading||e==null||e.setPendingTargetStatus(null)},[e]),d=u.useCallback(()=>{s(null),e==null||e.exitBulkSelectionMode()},[e]),c=u.useCallback(()=>{if(!e)return;const f=e.pendingTargetStatus,g=e.selectedTaskIds;if(f==null||g.length===0)return;const h={tasks_ids:[...g],estatus:f,...f===2?{ended_at:new Date().toISOString()}:{}};e.setIsBulkLoading(!0),i(h,{onSettled:()=>{e.setIsBulkLoading(!1)},onSuccess:async()=>{await e.invalidateAfterBulkSuccess(n),s(null),e.exitBulkSelectionMode()},onError:()=>{s(null),e.setPendingTargetStatus(null)}})},[e,i,n]),m=u.useMemo(()=>e?dr({baseColumn:e.baseColumn,setPendingTargetStatus:e.setPendingTargetStatus,setActiveButtonId:s,onConfirmBulkMove:c,isBulkLoading:e.isBulkLoading}):[],[e,c]);return!e||r===0||e.baseColumn!=="Por hacer"&&e.baseColumn!=="Trabajando"?null:a.jsx(p.Toolbar,{visible:!0,count:r,text:mr,activeButtonId:t,onActiveButtonIdChange:s,onBackClick:l,buttons:m,onClose:d,showCounterInButtonsView:!o,showBackButton:!o,showCloseButton:!o})}const ms=["to_do_tasks","working_tasks","done_tasks"],us="tasksProject";function ur(e){return Promise.all(ms.map(t=>e.invalidateQueries({queryKey:[t]}))).then(()=>{})}function pr(e){return Promise.all(ms.map(t=>e.resetQueries({queryKey:[t]}))).then(()=>{})}function fr(e){return e.refetchQueries({queryKey:[us],type:"active"}).then(()=>{})}function gr(e){return e.invalidateQueries({queryKey:[us]}).then(()=>{})}function hr(e){const t=!!(e.repeatsToDo&&e.repeats===e.repeatsToDo),s=!e.repeatsToDo||e.repeatsToDo===1,o=e.status===0;return t||s||o}function xr(e,t){return(e??"")!==""&&(t??0)===2||!(e??"")}function ps(e){return e.status===2||!hr(e)?!1:xr(e.nameRequiredTask,e.statusRequiredTask)}const br=["Por hacer","Trabajando","Completadas"],yr=()=>{const{defineFields:e}=ke(),{tasksProject:t}=st(),{filters:s}=nr();u.useEffect(()=>{e([...s])},[e,s]);const o=u.useMemo(()=>{var i;return(((i=t==null?void 0:t.data)==null?void 0:i.filter(r=>{var l;return(((l=r==null?void 0:r.tasks)==null?void 0:l.length)??0)===0}))??[]).reduce((r,l)=>(r[l.status]=r[l.status]||[],r[l.status].push(l),r),{})},[t==null?void 0:t.data]);return a.jsxs(as,{invalidateAfterBulkSuccess:gr,children:[a.jsx(ds,{}),a.jsx("div",{className:"tm-relative tm-flex tm-h-full tm-min-h-[100%] tm-w-full tm-gap-8",children:br.map((n,i)=>{const r=(o==null?void 0:o[i])??[];return a.jsx(xt,{total:r.length,title:n,tasks:r,isFetching:t==null?void 0:t.isFetching,isLoadingData:t==null?void 0:t.isLoading,bulkSelectAllIds:()=>Promise.resolve(r.filter(l=>ps({status:l.status,nameRequiredTask:l.nameRequiredTask,statusRequiredTask:l.statusRequiredTask,repeatsToDo:l.repeatsToDo,repeats:l.repeats})).map(l=>l.id))},n)})})]})};function jr(e,t){return!e||e.length!==t.length?!1:JSON.stringify(e)===JSON.stringify(t)}async function fs(e){const t=[];let s=1;for(;;){const{tasks:o}=await pt({filters:{...e.filters,status:e.status,...ht(s)},tasks_api:e.tasks_api});for(const n of o)ps({status:n.status,nameRequiredTask:n.nameRequiredTask,statusRequiredTask:n.statusRequiredTask,repeatsToDo:n.repeatsToDo,repeats:n.repeats})&&t.push(n.id);if(o.length<gt)break;s+=1}return t}const wr=()=>{var i,r;const{tasks_api:e}=fe(),{toDoTasks:t,total:s,filtersToSend:o}=ls(),n=[...((r=(i=t==null?void 0:t.data)==null?void 0:i.pages)==null?void 0:r.flatMap(l=>l.tasks))??[]];return a.jsx(xt,{total:s,title:"Por hacer",tasks:n,loadNextPage:()=>Yt(t),isFetching:t==null?void 0:t.isFetching,isLoadingData:t==null?void 0:t.isLoading,bulkSelectAllIds:()=>fs({tasks_api:e,filters:o,status:"por_hacer"})})},vr=()=>{const{tasks_api:e}=fe(),{user:t}=ve(),{filters:s}=ke(),o=u.useMemo(()=>Jt(s,t,"trabajando"),[s,t.id,t.role]),n=Zt(s),i=de.useInfiniteQuery({initialPageParam:1,queryKey:["working_tasks",o],enabled:n&&!!(t!=null&&t.id),queryFn:({pageParam:l})=>pt({filters:{...o,status:"trabajando",...ht(l)},tasks_api:e}),staleTime:1e3*60*60*24,getNextPageParam:Xt}),r=u.useMemo(()=>{var l,d,c;return((c=(d=(l=i.data)==null?void 0:l.pages)==null?void 0:d[0])==null?void 0:c.total)??0},[i.data]);return{workingTasks:i,total:r,filtersToSend:o}},_r=()=>{var i,r;const{tasks_api:e}=fe(),{workingTasks:t,total:s,filtersToSend:o}=vr(),n=[...((r=(i=t==null?void 0:t.data)==null?void 0:i.pages)==null?void 0:r.flatMap(l=>l.tasks))??[]];return a.jsx(xt,{total:s,title:"Trabajando",tasks:n,loadNextPage:()=>Yt(t),isFetching:t==null?void 0:t.isFetching,bulkSelectAllIds:()=>fs({tasks_api:e,filters:o,status:"trabajando"})})},Tr=()=>{const{user:e}=ve(),{tasks_api:t}=fe(),{filters:s}=ke(),o=u.useMemo(()=>Jt(s,e,"completadas"),[s,e.id,e.role]),n=Zt(s),i=de.useInfiniteQuery({initialPageParam:1,queryKey:["done_tasks",o],enabled:n&&!!(e!=null&&e.id),queryFn:({pageParam:l})=>pt({filters:{...o,status:"completadas",...ht(l)},tasks_api:t}),staleTime:1e3*60*60*24,getNextPageParam:Xt}),r=u.useMemo(()=>{var l,d,c;return((c=(d=(l=i.data)==null?void 0:l.pages)==null?void 0:d[0])==null?void 0:c.total)??0},[i.data]);return{doneTasks:i,total:r,filtersToSend:o}},Nr=()=>{var o,n;const{doneTasks:e,total:t}=Tr(),s=[...((n=(o=e==null?void 0:e.data)==null?void 0:o.pages)==null?void 0:n.flatMap(i=>i.tasks))??[]];return a.jsx(xt,{title:"Completadas",tasks:s,loadNextPage:()=>Yt(e),isFetching:e==null?void 0:e.isFetching,total:t})};class ut{static toSalesmanUsers(t){return{id:t.id,name:t.nombre}}}const Cr=()=>{const{tasks_api:e}=fe(),{filters:t}=ke(),{user:s}=ve(),o=async()=>(await e.get("/api/obtener-comerciales")).data.map(ut.toSalesmanUsers),n=async()=>{var l;return(await e.get("/api/listado_tareas",{params:{...ra(t),owner:{user:s.id,config:et((l=t==null?void 0:t.owner)==null?void 0:l.config,s.role),role:s.role},justProjects:!0,cancelada:!1}})).data.map(ut.toSalesmanUsers)};return{getSalesmanAndProjects:u.useCallback(async(r={})=>{var h;const l={...t,...r},d=et((r==null?void 0:r["owner.config"])??((h=t==null?void 0:t.owner)==null?void 0:h.config),s==null?void 0:s.role),c={...l};delete c["owner.config"];const m=ra(c),[f,g]=await Promise.all([e.get("/api/obtener-comerciales"),e.get("/api/listado_tareas",{params:{...m,owner:{user:s==null?void 0:s.id,config:d,role:s.role},justProjects:!0,cancelada:!1}})]);return{salesmanUsers:f.data.map(ut.toSalesmanUsers),projects:g.data.map(ut.toSalesmanUsers)}},[e,t,s==null?void 0:s.id,s==null?void 0:s.role]),getProjects:n,getSalesmans:o}},Sr=()=>{const{user:e}=ve(),[t,s]=u.useState([...la]),o=[{roles:[...Kt],id:"owner.config",filters:[{id:"todas",name:"Todas las tareas"}]}];return u.useEffect(()=>{const n=[...la];o.forEach(l=>{if(l.roles.includes(e.role)){const d=n.find(c=>c.id===l.id);d&&(d.options.some(m=>m.id==="todas")||(d.options=[{id:"todas",name:"Todas las tareas"},...d.options]))}});const i=JSON.stringify(t),r=JSON.stringify(n);i!==r&&s(n)},[e.role]),{filters:t}},Er=()=>{const{defineFields:e,initialFilters:t,fields:s}=ke(),{getSalesmanAndProjects:o}=Cr(),{filters:n}=Sr(),i=u.useRef(s);i.current=s;const r=(t==null?void 0:t["owner.config"])??"yo_y_mis_equipos";return u.useEffect(()=>{let l=!1;return(async()=>{const{salesmanUsers:c,projects:m}=await o({"owner.config":r});if(l)return;const f=n.map(g=>g.id==="project.id"?{...g,options:m}:g.id==="salesman.id"?{...g,options:c}:g);jr(i.current,f)||e(f)})(),()=>{l=!0}},[e,n,o,r]),a.jsxs(as,{invalidateAfterBulkSuccess:ur,children:[a.jsx(ds,{}),a.jsxs("div",{className:"tm-relative tm-flex tm-h-full tm-min-h-[100%] tm-w-full tm-gap-8",children:[a.jsx(wr,{}),a.jsx(_r,{}),a.jsx(Nr,{})]})]})},gs=u.createContext({}),Ar=({children:e})=>{const[t,s]=u.useState([]),o=n=>{s(i=>i.includes(n)?i.filter(r=>r!==n):[...i,n])};return a.jsx(gs.Provider,{value:{selectedTasks:t,selectTask:o},children:e})},Pr=()=>u.useContext(gs),Dr=()=>{const e=()=>a.jsxs("div",{className:"tm-flex tm-w-full tm-gap-m",children:[a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-full tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-w-[30%] tm-animate-pulse tm-rounded-md tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-lg tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-lg tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-lg tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-w-[10%] tm-animate-pulse tm-rounded-md tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-lg tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-w-[10%] tm-animate-pulse tm-rounded-md tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-lg tm-bg-gray-200"}),a.jsx("div",{className:"tm-h-[30px] tm-min-h-[30px] tm-w-[30px] tm-min-w-[30px] tm-animate-pulse tm-rounded-lg tm-bg-gray-200"})]});return a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-m",children:[a.jsx(e,{}),a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-m tm-pl-5",children:[a.jsx(e,{}),a.jsx("div",{className:"tm-pl-5",children:a.jsx(e,{})})]}),a.jsx(e,{}),a.jsxs("div",{className:"tm-flex tm-flex-col tm-gap-m tm-pl-5",children:[a.jsx(e,{}),a.jsx("div",{className:"tm-pl-5",children:a.jsx(e,{})})]})]})},hs=({startDate:e,endDate:t})=>a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"tm-flex tm-h-[30px] tm-w-fit tm-items-center tm-justify-center tm-gap-s tm-rounded-md tm-bg-surface-default tm-px-xl",children:[a.jsx(p.Icon,{name:ne.faCalendar,size:"xs",color:"current"}),a.jsxs(p.Text,{children:[" ",xa(e)]})]}),a.jsx(p.Icon,{name:ne.faArrowRight,size:"xs",color:"current"}),a.jsxs("div",{className:"tm-flex tm-h-[30px] tm-w-fit tm-items-center tm-justify-center tm-gap-s tm-rounded-md tm-bg-surface-default tm-px-xxxl",children:[a.jsx(p.Icon,{name:ne.faCalendar,size:"xs",color:"current"}),a.jsxs(p.Text,{children:[" ",xa(t)]})]})]}),xs=({id:e,priority:t,difficulty:s,endDate:o,atraso:n,role:i,status:r})=>{const[l,d]=u.useState(!1),c=ft(i,r),m={0:{title:"N/A",color:Se.success.regular,bg:"tm-bg-texts-placeholder tm-border-texts-placeholder",border:"tm-border-success-medium",borderHover:"hover:tm-border-success-dark"},1:{title:"Baja",color:Se.success.regular,bg:"tm-bg-success-medium tm-border-success-pastel",border:"tm-border-success-pastel",borderHover:"hover:tm-border-success-dark"},2:{title:"Media",color:Se.warning.regular,bg:"tm-bg-warning-light tm-border-warning-regular",border:"tm-border-warning-regular",borderHover:"hover:tm-border-warning-dark"},3:{title:"Alta",color:Se.danger.regular,bg:"tm-bg-danger-light tm-border-danger-regular",border:"tm-border-danger-regular",borderHover:"hover:tm-border-danger-dark"}},f={1:{title:"Muy fácil",color:Se.success.dark,iconColor:"brand",bg:"tm-bg-success-medium tm-border-success-regular",border:"tm-border-success-medium",borderHover:"hover:tm-border-success-dark"},2:{title:"Fácil",color:Se.success.regular,iconColor:"success",bg:"tm-bg-success-medium tm-border-success-pastel",border:"tm-border-success-medium",borderHover:"hover:tm-border-success-dark"},3:{title:"Media",color:Se.warning.regular,iconColor:"warning",bg:"tm-bg-warning-light tm-border-warning-regular",border:"tm-border-warning-medium",borderHover:"hover:tm-border-warning-dark"},4:{title:"Difícil",color:Se.danger.regular,iconColor:"danger",bg:"tm-bg-danger-light tm-border-danger-regular",border:"tm-border-danger-medium",borderHover:"hover:tm-border-danger-dark"},5:{title:"Muy difícil",color:Se.danger.dark,iconColor:"danger",bg:"tm-bg-danger-light tm-border-danger-regular",border:"tm-border-danger-medium",borderHover:"hover:tm-border-danger-dark"}},g=()=>{if(s==null||Number.isNaN(Number(s)))return 1;const b=Math.trunc(Number(s));return b===0?1:b>=1&&b<=5?b:1},h=()=>{if(t==null||Number.isNaN(Number(t)))return 0;const b=Math.trunc(Number(t));return b>=0&&b<=3?b:0},x=f[g()]??f[1],y=m[h()]??m[0],j=o instanceof Date&&!Number.isNaN(o.getTime())?`${o.getDate()} ${$t(o.getMonth()).slice(0,3)}`:"—";return a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"tm-flex tm-h-[30px] tm-w-[30px] tm-items-center tm-justify-center tm-gap-8 tm-rounded-[8px] tm-bg-surface-default hover:tm-bg-surface-hover",children:a.jsx(Me,{trigger:a.jsx(p.Icon,{name:ne.faAlignCenter,size:"xs",color:"current"}),children:a.jsx("div",{className:"tm-px-8 tm-py-4",children:a.jsx(p.Text,{children:"Espéralo muy pronto..."})})})}),a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-8",children:[a.jsx("div",{className:`tm-gap-s ${x.border} ${x.borderHover} transition-all duration-300 tm-flex tm-h-[30px] tm-w-[30px] tm-items-center tm-justify-center
6
6
  tm-rounded-[8px] tm-border tm-shadow-[0px_0px_2px_0px_rgba(37,37,37,0.10)]`,children:a.jsx(Wt,{difficulty:s,id:e,canEdit:c})}),a.jsx("div",{className:`tm-gap-s ${y.bg.replace(/\bbg-|border-/g,"tm-$&")??"tm-bg-light-gray-50"} transition-all duration-300 tm-flex tm-h-[30px] tm-w-[30px] tm-items-center tm-justify-center tm-rounded-[8px]
7
7
  tm-border tm-border-success-medium tm-shadow-[0px_0px_2px_0px_rgba(37,37,37,0.10)] hover:tm-border-success-dark`,children:a.jsx(Qt,{priority:h(),id:e,canEdit:c})}),(n==null?void 0:n.activa)&&a.jsx("div",{onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),className:`transition-all duration-300 tm-flex tm-h-[30px] tm-w-[30px] tm-items-center tm-justify-center tm-gap-s tm-rounded-[8px]
8
8
  tm-border tm-border-danger-medium tm-shadow-[0px_0px_2px_0px_rgba(37,37,37,0.10)] hover:tm-border-danger-dark`,children:a.jsx(Me,{trigger:a.jsx(p.Icon,{name:ne.faTriangleExclamation,size:"xs",color:l?"warning":"primary"}),children:a.jsx("div",{className:"tm-px-8 tm-py-4",children:a.jsx(p.Text,{children:n==null?void 0:n.motivo})})})}),a.jsx(p.Icon,{name:ne.faCalendar,size:"xs",color:"current"}),a.jsx(p.Text,{children:j})]})]})},Ir=({id:e})=>{const{selectedTasks:t,selectTask:s}=Pr();return a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"tm-flex tm-h-[20px] tm-w-[20px] tm-cursor-pointer tm-items-center tm-justify-center tm-rounded-md tm-border-2 tm-border-default",htmlFor:e.toString(),children:a.jsx("span",{className:`${t.includes(e)?"tm-opacity-100":"tm-opacity-0"} tm-transition-opacity tm-duration-500`,children:a.jsx(p.Icon,{name:ne.faCheck,size:"xs",style:{color:Se.primary.regular},color:"current"})})}),a.jsx("input",{className:"tm-hidden",id:e.toString(),type:"checkbox",onChange:()=>s(e)})]})},bs=({task:e})=>a.jsx(Me,{trigger:a.jsx(p.Text,{children:e}),children:a.jsx("div",{className:"tm-py-2 tm-px-4",children:a.jsx(p.Text,{children:e})})}),Fr=({id:e})=>{var d,c,m,f;const[t,s]=u.useState(!1),{tasksProject:o}=st(),{reasignResponsible:n}=He(),{getOBPUrlApi:i}=fe(),r=(d=o==null?void 0:o.data)==null?void 0:d.find(g=>g.id===e),{user:l}=ve();return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"tm-border-b tm-border-default tm-pb-3",children:a.jsxs("div",{className:"tm-mb-3 tm-ml-[30px] tm-mt-1 tm-flex tm-flex-wrap tm-items-center tm-gap-xl tm-rounded-md tm-p-2 hover:tm-bg-surface-hover",onClick:()=>s(!0),children:[!(r!=null&&r.nameRequiredTask)||(r==null?void 0:r.nameRequiredTask)!==""&&(r==null?void 0:r.statusRequiredTask)===2&&a.jsx(Ir,{id:e}),a.jsx(rs,{id:e,idAtraso:(c=r==null?void 0:r.atraso)==null?void 0:c.atrasoId,nameRequiredTask:(r==null?void 0:r.nameRequiredTask)??"",status:r==null?void 0:r.status,statusRequiredTask:(r==null?void 0:r.statusRequiredTask)??0,nameRequiredTaskResponsible:r==null?void 0:r.nameRequiredTaskResponsible},e),(r==null?void 0:r.willBePaused)&&a.jsx(cs,{idTask:r.id,paused:r.paused,popupId:`child-task-pause-menu-${r.id}`,children:g=>a.jsx(p.Button,{ref:g,color:"tertiary",icon:r!=null&&r.paused?ne.faPause:ne.faPlay,className:"tm-font-regular tm-flex tm-items-center tm-gap-8 tm-text-sm tm-text-gray-400",size:"xs"})}),a.jsx(os,{responsibleCandidateIds:((m=r==null?void 0:r.users)==null?void 0:m.map(g=>g.id))??[],role:l==null?void 0:l.role,status:r==null?void 0:r.status,onClick:async(g,h)=>{await n({idNewResponsible:g,id:e,typeOfSelect:h})},responsible:r==null?void 0:r.responsible,users:((f=r==null?void 0:r.users)==null?void 0:f.map(g=>Ut(g,i())))??[]}),a.jsx(bs,{task:(r==null?void 0:r.task)??""}),a.jsx(xs,{id:e,priority:r==null?void 0:r.priority,difficulty:r.difficulty,endDate:r==null?void 0:r.endDate,atraso:r==null?void 0:r.atraso,role:l==null?void 0:l.role,status:(r==null?void 0:r.status)??-1}),a.jsx(hs,{startDate:r==null?void 0:r.startDate,endDate:r==null?void 0:r.endDate})]})}),a.jsx(is,{taskId:e,isOpen:t,setIsOpen:s,initialFromList:(r==null?void 0:r.panelDataFromList)??void 0})]})},ys=({id:e})=>{var d,c,m,f,g,h;const{user:t}=ve(),{tasksProject:s,openTasks:o,openTask:n}=st(),i=(d=s==null?void 0:s.data)==null?void 0:d.find(x=>x.id===e),l=(()=>{var j;const x=s==null?void 0:s.data,y=[];return(j=i==null?void 0:i.tasks)==null||j.forEach(b=>{const w=x.find(v=>v.id===(b==null?void 0:b.id));w&&y.push(w)}),y})();return i?a.jsxs("div",{className:"tm-mb-2 tm-flex tm-flex-col tm-gap-m tm-overflow-y-auto",children:[a.jsxs("div",{className:"tm-flex tm-cursor-pointer tm-flex-wrap tm-items-center tm-gap-16 tm-rounded-md tm-p-2 hover:tm-bg-surface-hover",onClick:()=>n(e),children:[a.jsx("button",{type:"button",className:`${o.includes(e)?"":"tm--rotate-90"} tm-transition-all tm-duration-300`,children:a.jsx(p.Icon,{name:ne.faChevronDown,size:"sm",style:{color:Se.texts.subtext},color:"current"})}),a.jsx("div",{className:"tm-mx-1 tm-flex tm-h-[28px] tm-min-h-[28px] tm-w-fit tm-min-w-[28px] tm-items-center tm-justify-center tm-rounded-full tm-bg-surface-default",children:a.jsx("p",{className:"tm-text-primary tm-text-md",children:((c=i==null?void 0:i.tasks)==null?void 0:c.length)===0?1:l.length})}),a.jsx(bs,{task:(i==null?void 0:i.task)??""}),a.jsx(xs,{id:e,priority:i==null?void 0:i.priority,difficulty:i==null?void 0:i.difficulty,endDate:i==null?void 0:i.endDate,atraso:i==null?void 0:i.atraso,role:t==null?void 0:t.role,status:(i==null?void 0:i.status)??-1}),a.jsx(hs,{startDate:i==null?void 0:i.startDate,endDate:i==null?void 0:i.endDate}),a.jsxs("button",{type:"button",className:"tm-flex tm-h-[30px] tm-w-fit tm-items-center tm-justify-center tm-gap-s tm-rounded-md tm-bg-surface-default tm-px-m hover:tm-bg-surface-hover",children:[a.jsx(p.Icon,{name:ne.faDiagramSubtask,size:"sm",color:"current"}),a.jsx(p.Text,{children:((m=i==null?void 0:i.tasks)==null?void 0:m.length)===0?1:(f=i==null?void 0:i.tasks)==null?void 0:f.length})]})]}),o.includes(e)&&a.jsx("div",{className:"tm-ml-[30px]",children:((g=i==null?void 0:i.tasks)==null?void 0:g.length)>0?(h=i==null?void 0:i.tasks)==null?void 0:h.map(x=>a.jsx(ys,{id:x==null?void 0:x.id})):a.jsx(Fr,{id:i==null?void 0:i.id})})]}):null},Mr=()=>{const{tasksProject:e,projectID:t}=st();if(e!=null&&e.isFetching||e!=null&&e.isLoading)return a.jsx(Dr,{});const o=((e==null?void 0:e.data)??[]).filter(n=>n.isPrincipalTask);return a.jsx("div",{className:"tm-flex tm-flex-col tm-gap-m",children:a.jsx(Ar,{project:t,children:o.sort((n,i)=>(n.orden??0)-(i.orden??0)).map(n=>a.jsx("div",{className:"tm-flex tm-flex-col tm-gap-m tm-border-b tm-border-default tm-pb-m ",children:a.jsx(ys,{id:n.id})}))})})};function kr({title:e,color:t,icon:s}){return a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-x-8",children:[a.jsx(p.Icon,{name:s,size:"md",colorDuotonePrimary:"blue",colorDuotoneSecondary:"blue",opacityDuotoneSecondary:.5}),a.jsx("p",{className:"tm-text-base tm-py-0.5 tm-font-body-sm-bold tm-text-body-sm-bold tm-leading-none tm-text-primary",children:e})]})}function Lr({value:e,onChange:t}){return a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-x-4",children:[a.jsx("label",{className:"tm-text-body-sm-bold tm-text-primary",children:"Nombre del equipo"}),a.jsx(p.Input,{size:"xs",placeholder:"Creative",value:e,onChange:s=>t(s.target.value)})]})}const js=({title:e})=>a.jsxs("div",{className:"flex-1 tm-flex tm-items-center tm-gap-x-8",children:[a.jsx(p.Icon,{background:!0,name:ne.faFilePen,color:"blue",size:"lg"}),a.jsx(p.Text,{size:"xl",weight:"bold",children:e})]}),Xe={search:"",debouncedSearch:"",filters:[]},Or={"kanban-general":{...Xe},"lista-campanias":{...Xe},"kanban-campania":{...Xe},"teams-container":{...Xe},"templates-container":{...Xe}},bt=We.create((e,t)=>({viewFilters:Or,currentPath:null,debounceTimeouts:{},setCurrentPath:s=>{const o=t().currentPath;e({currentPath:s}),o&&o!==s&&t().resetPathData(o)},setSearch:(s,o)=>{const n=o||t().currentPath;if(!n)return;const i=`search_${n}`,r=t().debounceTimeouts[i];r&&clearTimeout(r),e(d=>({viewFilters:{...d.viewFilters,[n]:{...d.viewFilters[n],search:s}}}));const l=setTimeout(()=>{e(d=>({viewFilters:{...d.viewFilters,[n]:{...d.viewFilters[n],debouncedSearch:s}},debounceTimeouts:{...d.debounceTimeouts,[i]:void 0}}))},500);e(d=>({debounceTimeouts:{...d.debounceTimeouts,[i]:l}}))},setFilters:(s,o)=>{const n=o||t().currentPath;n&&e(i=>({viewFilters:{...i.viewFilters,[n]:{...i.viewFilters[n],filters:s}}}))},getSearch:s=>{var n;const o=s||t().currentPath;return o&&((n=t().viewFilters[o])==null?void 0:n.search)||""},getDebouncedSearch:s=>{var n;const o=s||t().currentPath;return o&&((n=t().viewFilters[o])==null?void 0:n.debouncedSearch)||""},getFilters:s=>{var n;const o=s||t().currentPath;return o?((n=t().viewFilters[o])==null?void 0:n.filters)||[]:[]},resetPathData:s=>{const o=`search_${s}`,n=t().debounceTimeouts[o];n&&clearTimeout(n),e(i=>({viewFilters:{...i.viewFilters,[s]:{...Xe}},debounceTimeouts:{...i.debounceTimeouts,[o]:void 0}}))}}));function ws({path:e}){const{getSearch:t,setSearch:s}=bt(),o=t(e);return a.jsx(p.Input,{leftSlot:ne.faSearch,placeholder:"Buscar...",size:"xs",value:o,onChange:n=>s(n.target.value,e)})}const Sa={fase_plantilla:"",tipo_plantilla:"",modo_configuracion:"",categoria:"",formato_salida:"",tipo_medio:"",medio_especifico:"",responsable_impresion:"",pertenencia_medio:"",ubicacion_medio:""},Br={fase_plantilla:null,tipo_plantilla:null,modo_configuracion:null,categoria:null,formato_salida:null,tipo_medio:null,medio_especifico:null,responsable_impresion:null,pertenencia_medio:null,ubicacion_medio:null},Rr={fase_plantilla:"",tipo_plantilla:"",categoria:"",tipo_medio:"",medio_especifico:"",modo_configuracion:"",responsable_impresion:"",pertenencia_medio:"",ubicacion_medio:""},Ea={tipo_plantilla:!0,modo_configuracion:!0,categoria:!0,formato_salida:!0,tipo_medio:!0,medio_especifico:!0,responsable_impresion:!0,pertenencia_medio:!0,ubicacion_medio:!0},Le=We.create(e=>({path:"",viewMode:"grid",isOpenModalLimit:!1,template:null,clave:"XX-XXX-XX-XXX-XX-X-X",templateFormData:Sa,disabledFields:Ea,claveParams:Rr,paramsTipo:Br,isEditTemplate:!1,openModalCreateTemplate:!1,currentTemplateForEdit:null,refetch:null,openModalUnsavedChanges:!1,isDuplicateTemplate:!1,hasFormChanges:!1,openModalPublishTemplate:!1,currentTemplateId:null,openModalDeleteTemplate:!1,setPath:t=>e({path:t}),setViewMode:t=>e({viewMode:t}),setIsOpenModalLimit:t=>e({isOpenModalLimit:t}),setTemplate:t=>e({template:t}),setClave:t=>e({clave:t}),setTemplateFormData:t=>{e(s=>({templateFormData:{...s.templateFormData,...t}}))},resetTemplateFormData:()=>e({templateFormData:Sa}),setDisableField:({fields:t,value:s})=>{for(const o of t)e(n=>({disabledFields:{...n.disabledFields,[o]:s}}))},resetDisabledFields:()=>e({disabledFields:Ea}),setClaveParams:({field:t,value:s})=>{e(o=>({claveParams:{...o.claveParams,[t]:s}}))},resetClave:()=>e(()=>({clave:"XX-XXX-XX-XXX-XX-X-X"})),setParamTipo:t=>e(s=>({paramsTipo:{...s.paramsTipo,...t}})),setIsEditTemplate:t=>e({isEditTemplate:t}),setOpenModalCreateTemplate:t=>e({openModalCreateTemplate:t}),setCurrentTemplateForEdit:t=>e({currentTemplateForEdit:t}),setRefetch:t=>e({refetch:t}),setOpenModalUnsavedChanges:t=>e({openModalUnsavedChanges:t}),setIsDuplicateTemplate:t=>e({isDuplicateTemplate:t}),setHasFormChanges:t=>e({hasFormChanges:t}),setOpenModalPublishTemplate:t=>e({openModalPublishTemplate:t}),setCurrentTemplateId:t=>e({currentTemplateId:t}),setOpenModalDeleteTemplate:t=>e({openModalDeleteTemplate:t})})),vs=e=>{const{getSearch:t,getDebouncedSearch:s,setSearch:o,getFilters:n,setFilters:i,resetPathData:r}=bt();return{search:t(e),debouncedSearch:s(e),filters:n(e),setSearch:l=>o(l,e),setFilters:l=>i(l,e),resetData:()=>r(e)}},zr=()=>a.jsx(js,{title:"Flujos de trabajo"}),ze=We.create(e=>({activeTemplate:null,setActiveTemplate:t=>e({activeTemplate:t}),clearActiveTemplate:()=>e({activeTemplate:null})})),_e=We.create((e,t)=>({mode:"grid",id:null,setMode:(s,o)=>{const n=t();if(s==="grid"||n.id!==null&&n.id!==o){const{clearAllGroupData:r}=t();r()}e({mode:s,id:o??null})},setId:s=>e({id:s}),reset:()=>{const{clearAllGroupData:s}=t();s(),e({mode:"grid",id:null})},addNode:null,addBranch:null,addNodeFromHandle:null,addNodeWithType:null,savePositions:null,loadPositions:null,clearPositions:null,activePlusNode:null,templateViewModes:{},setViewMode:(s,o)=>{const{templateViewModes:n}=t();e({templateViewModes:{...n,[s]:o}})},getViewMode:s=>{const{templateViewModes:o}=t();return o[s]??"readonly"},clearViewMode:s=>{const{templateViewModes:o}=t(),n={...o};delete n[s],e({templateViewModes:n})},flowViewportByTemplateId:{},setFlowViewportForTemplate:(s,o)=>{const{flowViewportByTemplateId:n}=t();e({flowViewportByTemplateId:{...n,[s]:{x:o.x,y:o.y,zoom:o.zoom}}})},expandedGroups:new Set,groupTemplateData:{},toggleGroupExpansion:s=>{const{expandedGroups:o}=t(),n=new Set(o);n.has(s)?n.delete(s):n.add(s),e({expandedGroups:n})},setGroupTemplateData:(s,o)=>{const{groupTemplateData:n}=t();e({groupTemplateData:{...n,[s]:o}})},clearGroupTemplateData:s=>{const{groupTemplateData:o}=t(),n={...o};delete n[s],e({groupTemplateData:n})},clearAllGroupData:()=>{e({expandedGroups:new Set,groupTemplateData:{}})},copiedNodes:[],setCopiedNodes:s=>e({copiedNodes:s}),clearCopiedNodes:()=>e({copiedNodes:[]}),expandGroup:null,collapseGroup:null})),_s=()=>{const{tasks_api:e}=fe();return{getTemplateWithTasks:async s=>{var o;try{const n=De.stringify({filters:{plantilla:{id:s}}},{encodeValuesOnly:!0}),i=await e.get(`/api/plantillas/plantilla-tareas-grafico?${n}`);if(i.data&&i.data.data)return i.data.data;throw new Error(`No se encontraron datos para la plantilla con ID ${s}`)}catch(n){throw console.error("Error en getTemplateWithTasks:",{error:n.message,status:(o=n.response)==null?void 0:o.status}),n}}}},Te={DIRTY:"dirty",IDLE:"idle",NEW:"new"},Pe={DRAFT:"draft",PUBLISHED:"published",DELETED:"deleted"},Ye="templates",Je="templates_states";function qr(e,t){return We.create((s,o)=>{let n=null;const i=f=>s({isLoading:f}),r=f=>s({error:f}),l=f=>s({data:f}),d=()=>new Promise((f,g)=>{const h=indexedDB.open(e.name,e.version);h.onerror=()=>{r("Error al abrir la base de datos"),g(new Error("Error al abrir la base de datos"))},h.onsuccess=()=>{n=h.result,s({isConnected:!0,error:null}),f(n)},h.onupgradeneeded=x=>{const y=x.target.result;e.stores.forEach(j=>{var b;if(!y.objectStoreNames.contains(j.name)){const w=y.createObjectStore(j.name,{keyPath:j.keyPath,autoIncrement:j.autoIncrement??!1});(b=j.indexes)==null||b.forEach(v=>{w.createIndex(v.name,v.keyPath,v.options)})}})}}),c=(f="readonly")=>{if(!n)throw new Error("Base de datos no conectada");return n.transaction(t,f)},m=(f="readonly")=>c(f).objectStore(t);return{data:[],isLoading:!1,error:null,isConnected:!1,connect:async()=>{try{i(!0),r(null),await d(),await o().getAll()}catch(f){r(f instanceof Error?f.message:"Error desconocido")}finally{i(!1)}},disconnect:()=>{n&&(n.close(),n=null,s({isConnected:!1,data:[]}))},add:async f=>{try{i(!0),r(null);const g=m("readwrite");return new Promise((h,x)=>{const y=g.add(f);y.onsuccess=async()=>{await o().getAll(),h()},y.onerror=()=>{r("Error al agregar elemento"),x(new Error("Error al agregar elemento"))}})}finally{i(!1)}},addMany:async f=>{try{i(!0),r(null);const g=m("readwrite");return new Promise((h,x)=>{let y=0,j=!1;f.forEach(b=>{const w=g.add(b);w.onsuccess=()=>{y++,y===f.length&&!j&&o().getAll().then(()=>h())},w.onerror=()=>{j||(j=!0,r("Error al agregar elementos"),x(new Error("Error al agregar elementos")))}})})}finally{i(!1)}},get:async f=>{try{r(null);const g=m();return new Promise((h,x)=>{const y=g.get(f);y.onsuccess=()=>{h(y.result)},y.onerror=()=>{r("Error al obtener elemento"),x(new Error("Error al obtener elemento"))}})}catch(g){r(g instanceof Error?g.message:"Error desconocido");return}},getAll:async()=>{try{r(null);const f=m();return new Promise((g,h)=>{const x=f.getAll();x.onsuccess=()=>{const y=x.result;l(y),g(y)},x.onerror=()=>{r("Error al obtener elementos"),h(new Error("Error al obtener elementos"))}})}catch(f){return r(f instanceof Error?f.message:"Error desconocido"),[]}},update:async(f,g)=>{try{i(!0),r(null);const h=m("readwrite");return new Promise((x,y)=>{const j=h.get(f);j.onsuccess=()=>{const b=j.result;if(!b){r("Elemento no encontrado"),y(new Error("Elemento no encontrado"));return}const w={...b,...g},v=h.put(w);v.onsuccess=async()=>{await o().getAll(),x()},v.onerror=()=>{r("Error al actualizar elemento"),y(new Error("Error al actualizar elemento"))}},j.onerror=()=>{r("Error al obtener elemento para actualizar"),y(new Error("Error al obtener elemento para actualizar"))}})}finally{i(!1)}},delete:async f=>{try{i(!0),r(null);const g=m("readwrite");return new Promise((h,x)=>{const y=g.delete(f);y.onsuccess=async()=>{await o().getAll(),h()},y.onerror=()=>{r("Error al eliminar elemento"),x(new Error("Error al eliminar elemento"))}})}finally{i(!1)}},clear:async()=>{try{i(!0),r(null);const f=m("readwrite");return new Promise((g,h)=>{const x=f.clear();x.onsuccess=()=>{l([]),g()},x.onerror=()=>{r("Error al limpiar store"),h(new Error("Error al limpiar store"))}})}finally{i(!1)}},query:async(f,g)=>{try{r(null);const x=m().index(f);return new Promise((y,j)=>{const b=x.getAll(g);b.onsuccess=()=>{y(b.result)},b.onerror=()=>{r("Error en consulta"),j(new Error("Error en consulta"))}})}catch(h){return r(h instanceof Error?h.message:"Error desconocido"),[]}},queryRange:async(f,g,h)=>{try{r(null);const y=m().index(f);return new Promise((j,b)=>{const w=IDBKeyRange.bound(g,h),v=y.getAll(w);v.onsuccess=()=>{j(v.result)},v.onerror=()=>{r("Error en consulta por rango"),b(new Error("Error en consulta por rango"))}})}catch(x){return r(x instanceof Error?x.message:"Error desconocido"),[]}}}})}const St=new Map;function Aa(e,t,s=!0){const o=u.useMemo(()=>{const v=`${e.name}-${t}`;if(!St.has(v)){const N=qr(e,t);St.set(v,N)}return St.get(v)},[e.name,t]);u.useEffect(()=>{s&&!o.getState().isConnected&&o.getState().connect()},[s,o]);const n=o(v=>v.data),i=o(v=>v.isLoading),r=o(v=>v.error),l=o(v=>v.isConnected),d=u.useCallback(()=>o.getState().connect(),[o]),c=u.useCallback(()=>o.getState().disconnect(),[o]),m=u.useCallback(v=>o.getState().add(v),[o]),f=u.useCallback(v=>o.getState().addMany(v),[o]),g=u.useCallback(v=>o.getState().get(v),[o]),h=u.useCallback(()=>o.getState().getAll(),[o]),x=u.useCallback((v,N)=>o.getState().update(v,N),[o]),y=u.useCallback(v=>o.getState().delete(v),[o]),j=u.useCallback(()=>o.getState().clear(),[o]),b=u.useCallback((v,N)=>o.getState().query(v,N),[o]),w=u.useCallback((v,N,L)=>o.getState().queryRange(v,N,L),[o]);return{data:n,isLoading:i,error:r,isConnected:l,connect:d,disconnect:c,add:m,addMany:f,get:g,getAll:h,update:x,delete:y,clear:j,query:b,queryRange:w}}const Ts=u.createContext(void 0);function $r({children:e}){const[t,s]=u.useState(!1),[o,n]=u.useState(!0),[i,r]=u.useState(null),l={name:"template_tabs_v1",version:2,stores:[{name:Ye,keyPath:"id",autoIncrement:!1,indexes:[{name:"id",keyPath:"id",options:{unique:!0}}]},{name:Je,keyPath:"id",autoIncrement:!1,indexes:[{name:"id",keyPath:"id",options:{unique:!0}}]}]},d=Aa(l,Ye,!0),c=Aa(l,Je,!0),m=u.useRef(new Map);m.current.has(Ye)||m.current.set(Ye,d),m.current.has(Je)||m.current.set(Je,c);const f=d.isConnected,g=d.error;u.useEffect(()=>{m.current.set(Ye,d),m.current.set(Je,c)},[d,c]);const h=u.useCallback(y=>{const j=m.current.get(y);if(!j)throw new Error(`Store ${y} no encontrado. Asegúrate de que esté configurada en indexedDBConfig.`);return{data:j.data,isLoading:j.isLoading,add:j.add,addMany:j.addMany,get:j.get,getAll:j.getAll,update:j.update,delete:j.delete,clear:j.clear,query:j.query,queryRange:j.queryRange,error:j.error}},[]);u.useEffect(()=>{(async()=>{try{if(n(!0),r(null),await d.connect(),f)s(!0);else throw new Error("No se pudo establecer la conexión con IndexedDB")}catch(j){r(j instanceof Error?j.message:"Error desconocido")}finally{n(!1)}})()},[d.connect,f]),u.useEffect(()=>{g&&r(g)},[g]);const x={isInitialized:t,isInitializing:o,error:i,isConnected:f,getStore:h};return a.jsx(Ts.Provider,{value:x,children:e})}function Ns(){const e=u.useContext(Ts);if(e===void 0)throw new Error("useIndexedDBContext debe usarse dentro de IndexedDBProvider");return e}function ea(){const{getStore:e}=Ns();return e(Ye)}function Cs(){const{add:e}=ea(),t=async r=>{try{await e(r)}catch(l){console.error("Error al guardar plantilla a indexDB:",l)}},s=async r=>{const l={},d=c=>{c.id&&(l[c.id]=c),c.tareas&&Array.isArray(c.tareas)&&c.tareas.forEach(m=>{d(m)}),c.ids_t_dependientes&&Array.isArray(c.ids_t_dependientes)&&c.ids_t_dependientes.forEach(m=>{typeof m=="object"&&m.id&&d(m)}),c.plantilla_dependents&&Array.isArray(c.plantilla_dependents)&&c.plantilla_dependents.forEach(m=>{m.tarea_plantillas&&Array.isArray(m.tarea_plantillas)&&m.tarea_plantillas.forEach(f=>{d(f)})})};return r.tarea_plantillas.forEach(c=>{d(c)}),l},o=(r,l)=>{const d=l[r];if(!d)return[];const c=[d];return d.tareas&&Array.isArray(d.tareas)&&d.tareas.forEach(m=>{m.id&&c.push(...o(m.id,l))}),d.ids_t_dependientes&&Array.isArray(d.ids_t_dependientes)&&d.ids_t_dependientes.forEach(m=>{typeof m=="object"&&m.id?c.push(...o(m.id,l)):typeof m=="number"&&l[m]&&c.push(...o(m,l))}),c},n=(r,l)=>{const d=l[r];if(!d)return[];const c=[d];return d.tarea_padre&&l[d.tarea_padre]&&c.unshift(...n(d.tarea_padre,l)),c};return{hydrateTasks:async r=>{var c,m;const l=await s(r);return(m=(c=r==null?void 0:r.graph_layout)==null?void 0:c.snapshot)==null?void 0:m.nodes.map(f=>{if(f.type==="group")return{...f,data:{...f.data,type:"template"},type:"group",selected:!1};const g=f.data.tareaId?l[f.data.tareaId]:r;return g!=null&&g.start?{...f,data:{...g.plantilla,id:g.id},selected:!1}:{...f,data:{...g,type:"task"},selected:!1}})},initializeTemplateStore:t,indexedTasks:s,getTaskHierarchy:o,getTaskPath:n}}function Ss(){const{getStore:e}=Ns();return e(Je)}const ct=()=>{const{add:e,get:t,delete:s,update:o}=Ss(),{get:n}=ea(),i={created:[],updated:[],deleted:[]},r=async({templateId:h})=>{const x=await t(h);return x||null};return{addTaskToState:async({task:h})=>{const x=await r({templateId:h.plantilla.id}),y=await n(h.plantilla.id);if(console.log("🔄 template:",y),!x)e({...i,id:h.plantilla.id,created:[...i.created,h]});else{const j=x.created.findIndex(b=>b.id===h.id);if(j!==-1){const b=x.created[j];x.created[j]={...b,...h},await o(h.plantilla.id,x)}else x.created.push(h),await o(h.plantilla.id,x)}},getTaskFromState:r,removeTemplateStates:async h=>{await s(h)},updateTaskInState:async({task:h})=>{const x=await r({templateId:h.plantilla.id}),j=(await n(h.plantilla.id)).graph_layout.snapshot.nodes;if(console.log("🔄 nodes:",j),x){const b=x.updated.findIndex(w=>w.id===h.id);if(b!==-1){const w=x.updated[b];console.log("🔄 currentTask:",w),x.updated[b]={...w,...h}}else x.updated.push(h);await o(h.plantilla.id,x)}else e({...i,id:h.plantilla.id,updated:[...i.updated,h]})},removeTaskFromState:async({templateId:h,id:x})=>{const y=await r({templateId:h});if(y){if(x>0){const b=y.deleted.findIndex(w=>w===x);if(b!==-1){y.deleted.splice(b,1),await o(h,y);return}}const j=y.created.findIndex(b=>b.id===x);if(j!==-1){y.created.splice(j,1),await o(h,y);return}}else if(x>0){e({...i,id:h,deleted:[...i.deleted,x]});return}},removeParentIdFromNodes:async({templateId:h,id:x})=>{const y=await r({templateId:h});if(y){const j=y.created.findIndex(w=>w.id===x);if(j!==-1){y.created[j].tarea_padre=null,y.created[j].id_t_requerida=null,await o(h,y);return}const b=y.updated.findIndex(w=>w.id===x);if(b!==-1){y.updated[b].tarea_padre=null,y.updated[b].id_t_requerida=null,await o(h,y);return}}},updateNodeWithNewEdge:async({templateId:h,edge:x,task:y})=>{console.log("🔵 updateNodeWithNewEdge - Inicio",{templateId:h,taskId:y.id,taskData:y});const j=await r({templateId:h});if(console.log("🔵 updateNodeWithNewEdge - Estado actual:",j),j){console.log("🔵 updateNodeWithNewEdge - Estado existe, buscando tarea...");const b=j.created.findIndex(v=>v.id===y.id);if(console.log("🔵 updateNodeWithNewEdge - Índice en created:",b),b!==-1){console.log("🔵 updateNodeWithNewEdge - Actualizando en created"),j.created[b]=y,await o(h,j),console.log("✅ updateNodeWithNewEdge - Actualizado en created");return}const w=j.updated.findIndex(v=>v.id===y.id);if(console.log("🔵 updateNodeWithNewEdge - Índice en updated:",w),w!==-1){console.log("🔵 updateNodeWithNewEdge - Actualizando en updated"),j.updated[w]=y,await o(h,j),console.log("✅ updateNodeWithNewEdge - Actualizado en updated");return}if(console.log("🔵 updateNodeWithNewEdge - Tarea no encontrada en arrays"),y.id&&y.id!==0){const v=y.id<0;v?(console.log("🔵 updateNodeWithNewEdge - Agregando a created (tarea nueva)"),j.created.push(y)):(console.log("🔵 updateNodeWithNewEdge - Agregando a updated (tarea existente)"),j.updated.push(y)),await o(h,j),console.log("✅ updateNodeWithNewEdge - Tarea agregada exitosamente a",v?"created":"updated")}else console.error("❌ updateNodeWithNewEdge - task.id no válido para agregar:",y.id)}else if(console.log("🔵 updateNodeWithNewEdge - Creando nuevo estado"),y.id&&y.id!==0){const b=y.id<0,w={...i,id:h,created:b?[y]:[],updated:b?[]:[y]};console.log("🔵 updateNodeWithNewEdge - Nuevo estado:",w,b?"(created)":"(updated)"),e(w),console.log("✅ updateNodeWithNewEdge - Estado creado exitosamente")}else console.error("❌ updateNodeWithNewEdge - task.id no válido:",y.id);console.log("🔵 updateNodeWithNewEdge - Fin")}}};function qe(){const{activeTemplate:e,setActiveTemplate:t}=ze(),{mode:s,setMode:o,setViewMode:n,clearViewMode:i}=_e(),{template:r,setIsOpenModalLimit:l,setOpenModalUnsavedChanges:d,setOpenModalPublishTemplate:c,setOpenModalDeleteTemplate:m}=Le(),{hydrateTasks:f}=Cs(),{addTaskToState:g,removeTemplateStates:h}=ct(),x=de.useQueryClient(),{data:y,add:j,update:b,get:w,getAll:v,delete:N,isLoading:L,error:O}=ea(),{get:C}=Ss(),{getTemplateWithTasks:F}=_s(),{tasks_api:E}=fe(),[X,U]=u.useState(!1),[z,M]=u.useState(!1),[K,I]=u.useState(!1),$=u.useMemo(()=>y.sort((S,q)=>S.order-q.order),[y]);u.useEffect(()=>{$.length===0&&s!=="grid"&&o("grid")},[$,s,o]);const R=async(_,S=Te.IDLE)=>{var q;try{const k=await F(_.id),T=await f(k),Q={id:crypto.randomUUID(),data:k,type:"start",dragging:!1,measured:{width:171,height:48},position:{x:91,y:-24.5},selected:!1,deletable:!1},Z=T||[Q],ae={...k,graph_layout:{...k==null?void 0:k.graph_layout,snapshot:{...(q=k==null?void 0:k.graph_layout)==null?void 0:q.snapshot,nodes:Z}},estatus:S,estatusFromStrapi:k.estatus};await j(ae)}catch(k){console.warn("No se pudieron obtener los datos completos de la plantilla, creando versión básica:",k);const T=_,Q={id:crypto.randomUUID(),data:T,type:"start",dragging:!1,measured:{width:171,height:48},position:{x:91,y:-24.5},selected:!1,deletable:!1},Z={id:T.id,snapshot:{nodes:[Q],edges:[],viewport:{x:0,y:0,zoom:1}},history:null,zoom:1,position:{x:0,y:0}},ae={...T,graph_layout:T.graph_layout||Z,estatus:S,tarea_plantillas:T.tarea_plantillas||[]};await j(ae)}},V=async({template:_,checkTemplateInIndexedDB:S=!1,statusTemplate:q=Te.IDLE})=>{const k=$;if(!k.find(Q=>Q.id===_.id)){if(k.length===5){l(!0);return}if(S&&await w(_.id))return;await R({..._,order:k.length+1},q)}await D(_.id),await G(_),o("create-edit",_==null?void 0:_.id)},G=async _=>{const S=await w(_.id);t(S)},D=async _=>{try{const S=await v();S.sort((k,T)=>(k.order||0)-(T.order||0));const q=S.findIndex(k=>k.id===_);if(q!==-1){const[k]=S.splice(q,1);S.unshift(k),S.forEach((Q,Z)=>{Q.order=Z+1});const T=S.map(Q=>b(Q.id,Q));await Promise.all(T)}else return}catch{}},te=async _=>{try{await N(_),i(_);const S=await v();S.forEach((k,T)=>{k.order=T+1});const q=S.map(k=>b(k.id,k));await Promise.all(q)}catch{}};return{screens:$,isLoading:L,error:O,add:j,data:y,addScreen:R,openTemplate:V,update:b,delete:te,get:w,activeTemplate:e,activateTemplate:G,reorderingTemplates:D,replaceTemplate:async()=>{try{const _=[...$],S={..._[_.length-1]};await N(S.id);const q={...r,order:S.order};await R(q);const T=(await v()).sort((Z,ae)=>Z.order-ae.order);if(T.some((Z,ae)=>(Z.order||0)!==ae+1)){const Z=T.map((ae,re)=>({...ae,order:re+1}));for(const ae of Z)try{await b(ae.id,ae)}catch{}}}catch{}finally{l(!1)}},addTaskUpdatingTemplate:async(_,S,q="hija")=>{var Z,ae,re,J;const k=await w(S);if(!k)return null;const T={id:_.id,uuid:crypto.randomUUID(),reference_graph:_.reference_graph,texto_corto:_.title,texto_largo:_.description||"",prioridad:_.priority||null,nivel_dificultad:_.difficulty||1,duracion:_.duration||null,start:!1,is_monitoring_trigger:_.is_monitoring_trigger??!1,type:"task",equipo:{id:Number(_.team)||null},responsable:{id:Number(_.responsible)||null},plantilla:{id:k.id,clave:k.clave,categoria:k.categoria||{id:0,nombre:"Sin categoría"}},plantilla_dependents:[],id_t_requerida:q==="dependiente"?(ae=(Z=_.parent)==null?void 0:Z.data)==null?void 0:ae.id:null,ids_t_dependientes:[],tarea_padre:q==="hija"?(J=(re=_.parent)==null?void 0:re.data)==null?void 0:J.id:null,tareas:[]},Q={...k,estatus:Te.DIRTY};return await b(S,Q),e&&e.id===S&&t(Q),await g({task:T}),T},addTemplateUpdatingTemplate:async(_,S,q,k="hija")=>{let T=null;if(e&&e.id===S?T=e:T=await w(S),!T)return null;const Q=(ae,re,J,se)=>{for(let ce=0;ce<ae.length;ce++){const me=ae[ce];if(me.id===re||me.uuid===re)return se==="dependiente"?(me.plantilla_dependents||(me.plantilla_dependents=[]),me.plantilla_dependents.push(J)):se==="hija"&&(me.plantilla_dependents||(me.plantilla_dependents=[]),me.plantilla_dependents.push(J)),!0;if(me.tareas&&me.tareas.length>0){const ie=Q(me.tareas,re,J,se);if(ie)return ie}}return!1};if(Q(T.tarea_plantillas,q,_,k)){const ae={...T,estatus:Te.DIRTY,updatedAt:new Date().toISOString()};return await b(S,ae),e&&e.id===S&&t(ae),!0}else return!1},updateGraphLayout:async(_,S)=>{var q;if(!_){console.warn("⚠️ updateGraphLayout - Template ID no válido");return}try{const k=await w(_);if(!k){console.warn("⚠️ updateGraphLayout - Template no encontrado");return}const T=(S.nodes||[]).filter(se=>{var ce;return!((ce=se.data)!=null&&ce.isInternal)&&!se.parentId}).map(se=>{const{style:ce,measured:me,data:ie,...ye}=se,{expandedDimensions:pe,isExpanded:be,needsReExpansion:Ae,...we}=ie||{},$e=ce?{...ce,width:void 0,height:void 0,minWidth:void 0,minHeight:void 0}:void 0;return{...ye,style:$e,data:we,position:se.position}}),Q=(S.edges||[]).filter(se=>{var ce;return!((ce=se.data)!=null&&ce.isInternal)}).map(se=>{var ce;if((ce=se.data)!=null&&ce.redirectedToInternal){const{redirectedToInternal:me,originalTarget:ie,...ye}=se.data;return{...se,target:ie||se.target,data:ye}}return se}),Z={...S,nodes:T,edges:Q},ae=(q=k.graph_layout)==null?void 0:q.snapshot;if(!(!ae||JSON.stringify(ae)!==JSON.stringify(Z)))return;const J={...k,graph_layout:{...k.graph_layout,snapshot:Z},estatus:Te.DIRTY,updatedAt:new Date().toISOString()};await b(_,J),e&&e.id===_&&t(J)}catch(k){console.error("❌ updateGraphLayout - Error:",k)}},saveTemplateChanges:async(_=!0)=>{try{if(e.estatus===Te.DIRTY){M(!0);const{id:S}=e,q=await w(S),k=await C(S),T=q.graph_layout.snapshot.nodes||[],Q=T.filter(J=>{var se;return!((se=J.data)!=null&&se.isInternal)&&!J.parentId}),Z=T.length-Q.length;Z>0&&console.warn(`💾 [saveTemplateChanges] Se filtraron ${Z} nodos internos al guardar plantilla ${S}`);const ae={graph_layout:{...q.graph_layout,snapshot:{...q.graph_layout.snapshot,nodes:Q.map(J=>{const{style:se,measured:ce,selected:me,...ie}=J,ye=se?{...se,width:void 0,height:void 0,minWidth:void 0,minHeight:void 0}:void 0;return J.type==="group"?{...ie,style:ye,data:{tareaId:J.data.id&&J.data.id>0?J.data.id:null,clave:J.data.clave,estatus:J.data.estatus,updatedAt:J.data.updatedAt,id:J.data.id}}:{...ie,style:ye,data:{tareaId:J.data.id&&J.data.id>0?J.data.id:null}}}),edges:(q.graph_layout.snapshot.edges||[]).filter(J=>{var se;return!((se=J.data)!=null&&se.isInternal)})}},tasks:{created:(k==null?void 0:k.created)||[],updated:(k==null?void 0:k.updated)||[],deleted:(k==null?void 0:k.deleted)||[]}},re=await E.post("/api/tareas/save-tareas-grafico",{data:ae});if(re.data&&re.status===200){try{const J=await F(S),se=await f(J),ce={...J,graph_layout:{...J.graph_layout,snapshot:{...J.graph_layout.snapshot,nodes:se}},estatus:Te.IDLE};await b(S,ce),_||t(ce)}catch{const se=await w(S);if(se&&!_){const ce={...se,estatus:Te.IDLE};await b(S,ce),t(ce)}}await x.invalidateQueries({queryKey:["template",S]}),await x.invalidateQueries({queryKey:["template"]}),await x.invalidateQueries({queryKey:["templates"]}),h(S),_&&(te(S),d(!1)),n(S,"readonly")}}}catch(S){console.log(S)}finally{M(!1)}},publishTemplate:async _=>{try{U(!0);const S={estatus:Pe.PUBLISHED,publication_date:new Date},q=await E.put(`/api/plantillas/plantilla-update-estatus/${_}`,{data:S});q.data&&q.status===200&&(t({...e,estatusFromStrapi:Pe.PUBLISHED}),c(!1),p.toast.info("Se publicó correctamente el proceso"))}catch(S){console.log(S),p.toast.error("Surgió un error al publicar el proceso")}finally{U(!1)}},deleteTemplate:async _=>{try{I(!0);const S={estatus:Pe.DELETED,sjdaksd:0},q=await E.put(`/api/plantillas/plantilla-update-estatus/${_}`,{data:S});q.data&&q.status===200&&(m(!1),p.toast.info("Se eliminó correctamente el proceso"))}catch(S){console.error(S),p.toast.error("Surgión un error al eliminar el proceso")}finally{I(!1)}},loadingPublishTemplate:X,loadingSaveChanges:z,loadingDeleteTemplate:K}}const Ur=async({tasks_api:e})=>{try{return(await e.get("/api/getAllOBPusers")).data}catch(t){throw console.log("Error al obtener los usuarios de OBP",t),`Error al obtener los usuarios de OBP: ${t}`}},Hr=()=>{const{tasks_api:e}=fe();return{users:de.useQuery({queryKey:["usersOBP"],queryFn:()=>Ur({tasks_api:e}),staleTime:1e3*60*60*24})}},nt=()=>{const{users:e}=Hr(),t=de.useQuery({queryKey:["users_index",e.data],queryFn:()=>Fo({users:e.data||[]}),staleTime:1e3*60*60*24,enabled:!!e.data});return{users:t.data,isLoading:t.isLoading||e.isLoading}},ta=()=>{const{users:e,isLoading:t}=nt(),{getImageOBP:s}=fe();return{getImageByEmail:i=>{const r=e==null?void 0:e[i];return s(r==null?void 0:r.image)},getNameByEmail:i=>{const r=e==null?void 0:e[i];return(r==null?void 0:r.nombre)||""},isLoading:t}},dt=({isLoading:e})=>e?a.jsxs("div",{className:"tm-fixed tm-inset-0 tm-z-50 tm-flex tm-items-center tm-justify-center",children:[a.jsx("div",{className:"tm-absolute tm-inset-0",style:{backgroundColor:"rgba(0, 0, 0, 0.5)"}}),a.jsx("div",{className:"tm-relative tm-flex tm-flex-col tm-items-center tm-justify-center tm-gap-4",children:a.jsx(p.Spinner,{})})]}):null,Pa=({template:e,openModalPublishTemplate:t,onHadleClickEditTemplateParams:s,onEditTasks:o,canDuplicateAndDeleteTemplates:n,onHandleClickDuplicateTemplate:i,openModalDeleteTemplate:r})=>a.jsx(p.Popup,{color:"secondary",pill:"pill",icon:le.faEllipsis,stopPropagationList:!0,children:a.jsxs(p.List,{className:"tm-p-6 tm-gap-4",children:[e.estatus!==Pe.PUBLISHED&&e.counts_tasks>2&&a.jsx(p.ListItem,{icon:le.faArrowUp,onClick:t,children:"Publicar"}),a.jsx(p.ListItem,{icon:le.faEdit,onClick:()=>{s(e)},children:"Editar parámetros"}),a.jsx(p.ListItem,{icon:le.faEdit,onClick:()=>{o&&o(e)},children:"Editar tareas"}),n&&a.jsx(p.ListItem,{icon:le.faClone,onClick:l=>{l.stopPropagation(),i(e)},children:"Duplicar"}),n&&a.jsx(p.ListItem,{color:"red",icon:le.faTrash,onClick:r,children:"Eliminar"})]})}),Es=(e=7)=>{const t=(o,n)=>o>=n?{populate:"*"}:{miembro_padre:{fields:["id"]},idUser:{populate:"*"},miembros:{populate:t(o+1,n),filters:{idUser:{blocked:!1}}}};return{miembros:{populate:t(0,e),filters:{idUser:{blocked:!1}}}}},Kr=e=>{const t=new Set,s=[],o=n=>{var i;if(Array.isArray(n))for(const r of n){const l=r,d=l==null?void 0:l.idUser;(d==null?void 0:d.id)!=null&&(d.email||d.nombre)&&(t.has(d.id)||(t.add(d.id),s.push({id:d.id,nombre:d.nombre??"",email:d.email??"",image:d.image}))),(i=l==null?void 0:l.miembros)!=null&&i.length&&o(l.miembros)}};return o(e),s},Vr=async(e,t)=>{var l;const s=De.stringify({fields:["nombre","id"],populate:Es(2)},{encodeValuesOnly:!0}),o=await e.get(`/api/equipos/${t}?${s}`),n=((l=o.data)==null?void 0:l.data)??o.data,i=je(n),r=Kr((i==null?void 0:i.miembros)??[]);return{team:{nombre:(i==null?void 0:i.nombre)??"",miembros:(i==null?void 0:i.miembros)??[]},members:r}},Gr=e=>{const{tasks_api:t}=fe(),s=typeof e=="number"&&e>0&&!Number.isNaN(e)?e:null;return de.useQuery({queryKey:["equipo-flow-preview",s],queryFn:()=>Vr(t,s),enabled:s!=null,staleTime:300*1e3})},Wr=3,Qr=e=>{if(!(e!=null&&e.id)&&(e==null?void 0:e.id)!==0)return null;const t=Number(e.id);return!Number.isNaN(t)&&t>0?t:null},Xr=({equipo:e})=>{var h;const t=Qr(e),s=((h=e==null?void 0:e.nombre)==null?void 0:h.trim())??"",{data:o,isLoading:n,isError:i}=Gr(t),{getImageByEmail:r,isLoading:l}=ta();if(!t)return null;const d=((o==null?void 0:o.team.nombre)??s).trim()||"Equipo",c=(o==null?void 0:o.members)??[],m=d,f=[...c].map(x=>{var y;return{src:r(x.email),name:((y=x.nombre)==null?void 0:y.trim())||x.email}}).sort((x,y)=>+!!y.src-+!!x.src),g=a.jsx("div",{className:"tm-flex tm-items-center tm-justify-center",children:n||l?a.jsx("div",{className:"tm-flex tm-items-center",children:[0,1,2].map(x=>a.jsx("div",{className:`tm-h-7 tm-w-7 tm-shrink-0 tm-rounded-full tm-bg-neutral-100 tm-ring-2 tm-ring-white ${x>0?"tm-ml-[-12px]":""}`},x))}):c.length>0?a.jsx(p.Avatar,{counterColor:"blue",counterTheme:"solid",maxVisible:Wr,size:"xs",stack:f,stroke:!0}):a.jsx(p.Avatar,{size:"xs",stroke:!0,type:"people"})});return a.jsxs("div",{className:"tm-flex tm-min-w-0 tm-shrink-0 tm-flex-col tm-items-center tm-justify-end tm-gap-2",children:[a.jsx(p.Tooltip,{preserveLayout:!0,label:i&&!s?"Equipo":m,children:g}),a.jsx("p",{className:"tm-text-body-xs-regular tm-text-tertiary tm-font-body-xs-normal",children:"Equipo"})]})},Yr={1:"blue",2:"green",3:"red",4:"yellow"},Jr=({difficulty:e})=>a.jsxs("div",{className:"tm-flex tm-flex-col tm-items-center tm-justify-end tm-gap-2",children:[a.jsx(p.Icon,{name:le.faRhombus,size:"md",color:Yr[e]}),a.jsx("p",{className:"tm-text-body-xs-regular tm-text-tertiary tm-font-body-xs-normal",children:"Dificultad"})]}),Zr=({duration:e})=>a.jsxs("div",{className:"tm-flex tm-flex-col tm-items-center tm-justify-end",children:[a.jsx("p",{className:"tm-text-icon-all-colors-blue tm-text-body-lg-regular tm-leading-none tm-font-semibold",children:e}),a.jsx("p",{className:"tm-text-body-xs-regular tm-text-tertiary tm-font-body-xs-normal",children:"Duración"})]}),ei={1:"neutral",2:"blue",3:"yellow",4:"red"},ti=({priority:e})=>a.jsxs("div",{className:"tm-flex tm-flex-col tm-items-center tm-justify-end tm-gap-2",children:[a.jsx(p.Icon,{name:le.faFlag,size:"md",color:ei[e]}),a.jsx("p",{className:"tm-text-body-xs-regular tm-text-tertiary tm-font-body-xs-normal",children:"Prioridad"})]});class ai{static toUsers(t){return{id:t.id,name:t.nombre,image:t.image,email:t.email}}}const si=async({tasks_api:e})=>{try{const t=De.stringify({filters:{blocked:!1}},{encodeValuesOnly:!0}),s=await e.get(`/api/users?${t}`);return je(s.data).map(ai.toUsers).sort((n,i)=>n.name.localeCompare(i.name))}catch(t){throw console.log("Error al obtener los usuarios comerciales",t),`Error al obtener los usuarios comerciales: ${t}`}},yt=()=>{const{tasks_api:e}=fe(),t=de.useQuery({queryKey:["users-mt"],queryFn:()=>si({tasks_api:e}),staleTime:1e3*60*60*24});return{isLoading:t.isLoading,users:t.data}},ni=(e,t,s)=>{var r;const o=(r=e==null?void 0:e.email)==null?void 0:r.trim();if(o){const l=t(o);return l||o}const n=e==null?void 0:e.id,i=n!==""&&n!=null&&!Number.isNaN(Number(n))?Number(n):NaN;if(!Number.isNaN(i)&&(s!=null&&s.length)){const l=s.find(d=>d.id===i);if(l!=null&&l.name)return l.name}return""},oi=({responsible:e})=>{const{isLoading:t,users:s}=yt(),{getImageByEmail:o,getNameByEmail:n,isLoading:i}=ta();if(t||i)return null;const r=ni(e,n,s),l=a.jsx(p.Avatar,{size:"xs",src:o((e==null?void 0:e.email)??""),type:"people"});return a.jsxs("div",{className:"tw-flex tw-flex-col tw-items-center tw-justify-end",children:[r?a.jsx(p.Tooltip,{label:r,children:l}):l,a.jsx("p",{className:"ui-text-body-xs-regular ui-text-tertiary ui-font-body-xs-normal",children:"Responsable"})]})},As=({layout:e="column"})=>e==="row"?a.jsxs("div",{className:"tm-flex tm-items-center tm-gap-1",children:[a.jsx(p.Icon,{name:le.faCamera,size:"sm",color:"blue"}),a.jsx(p.Text,{size:"xs",weight:"regular",color:"tertiary",children:"Testigos"})]}):a.jsxs("div",{className:"tm-flex tm-flex-col tm-items-center tm-justify-end tm-gap-2",children:[a.jsx(p.Icon,{name:le.faCamera,size:"md",color:"blue"}),a.jsx("p",{className:"tm-text-body-xs-regular tm-text-tertiary tm-font-body-xs-normal",children:"Testigos"})]}),Ps=({fullWidth:e,mode:t="grid",onClick:s,active:o,template:n,withOptions:i=!0})=>{var G;const{openTemplate:r}=qe(),{getImageByEmail:l,getNameByEmail:d}=ta(),{setIsEditTemplate:c,setOpenModalCreateTemplate:m,setCurrentTemplateForEdit:f,setIsDuplicateTemplate:g,setOpenModalPublishTemplate:h,setCurrentTemplateId:x,setOpenModalDeleteTemplate:y}=Le(),j={0:{color:"accent",theme:"solid"},1:{color:"accent",theme:"soft"},2:{color:"warning",theme:"solid"},3:{color:"info",theme:"solid"},4:{color:"gray",theme:"solid"},5:{color:"warning",theme:"soft"},6:{color:"danger",theme:"solid"},7:{color:"info",theme:"soft"},8:{color:"success",theme:"solid"},9:{color:"danger",theme:"solid"}},[b,w]=u.useState(!1),v=async()=>{if(w(!0),t==="grid")try{w(!0),await r({template:n,checkTemplateInIndexedDB:!0})}catch(D){console.error(D)}finally{w(!1)}else w(!1);s==null||s(n==null?void 0:n.id)},N=async()=>{if(!(t!=="grid"||!n)){w(!0);try{await r({template:n,checkTemplateInIndexedDB:!0}),s==null||s(n==null?void 0:n.id)}catch(D){console.error(D)}finally{w(!1)}}},L=D=>{c(!0),m(!0),f(D)},O=D=>{g(!0),m(!0),f(D)},C=()=>{x(n==null?void 0:n.id),h(!0)},F=()=>{x(n==null?void 0:n.id),y(!0)},E=(n==null?void 0:n.dias_duracion)===1?"Día":"Días",X=(n==null?void 0:n.counts_tasks)===1?"Tarea":"Tareas",U=(n==null?void 0:n.estatus)===Pe.PUBLISHED?It(n==null?void 0:n.publication_date).format("DD/MM/YYYY"):It(n==null?void 0:n.createdAt).format("DD/MM/YYYY"),z=(n==null?void 0:n.updated_by)||(n==null?void 0:n.created_by),M=l(z==null?void 0:z.email),K=d(z==null?void 0:z.email)||"",I=(n==null?void 0:n.estatus)===Pe.PUBLISHED?"Fecha de publicación":"Fecha de creación",$=(n==null?void 0:n.estatus)===Pe.DRAFT,R=((G=n==null?void 0:n.tarea_plantillas)==null?void 0:G.some(D=>D.is_monitoring_trigger===!0))??!1,V=D=>{const te=D.split("-");return a.jsx(a.Fragment,{children:te.map((ee,A)=>a.jsxs("span",{children:[ee,A<te.length-1&&a.jsx("span",{className:"tm-text-neutral-200",children:"-"})]},A))})};return a.jsxs(p.Card,{active:o,fullWidth:e,onClick:v,className:`${e?"md:tm-flex-row":"tm-flex-col"}`,children:[a.jsx(dt,{isLoading:b}),a.jsx(p.Card.Header,{children:a.jsx("div",{className:"tm-flex tm-justify-between tm-items-start tm-gap-x-4",children:a.jsxs("div",{className:"tm-flex tm-justify-between tm-items-start tm-gap-4 tm-flex-1",children:[a.jsxs("div",{className:"tm-flex tm-place-items-start tm-gap-x-8",children:[a.jsx("div",{className:"tm-flex tm-items-center",children:a.jsx(p.Icon,{name:Ge.faChartDiagram,colorDuotonePrimary:"blue",colorDuotoneSecondary:"blue",opacityDuotonePrimary:.5,size:"lg"})}),a.jsxs("div",{className:"tm-flex tm-gap-x-8 tm-flex-col tm-gap-y-4",children:[a.jsx(p.Text,{size:"sm",weight:"semibold",color:"primary",truncateLabel:!0,children:V((n==null?void 0:n.clave)||(n==null?void 0:n.nombre_plantilla))}),a.jsxs("div",{className:"tm-flex tm-items-baseline tm-gap-x-1",children:[a.jsx(p.Badge,{size:"sm",theme:"soft",color:(n==null?void 0:n.estatus)===Pe.PUBLISHED?"success":"gray",label:(n==null?void 0:n.estatus)===Pe.PUBLISHED?"Publicado":"Borrador"}),!(typeof U=="string"&&U==="Invalid date")&&a.jsx(p.Tooltip,{label:I,children:a.jsx(p.Text,{size:"sm",weight:"medium",color:"tertiary",children:U})})]})]})]}),!e&&a.jsx(Pa,{template:n,openModalPublishTemplate:C,onHadleClickEditTemplateParams:L,onEditTasks:N,canDuplicateAndDeleteTemplates:$,onHandleClickDuplicateTemplate:O,openModalDeleteTemplate:F})]})})}),a.jsx(p.Card.Separator,{vertical:e}),a.jsx(p.Card.Body,{className:"tm-flex tm-flex-wrap tm-gap-x-6 tm-gap-y-4 tm-w-full md:tm-w-auto tm-flex-1 tm-items-center",children:n==null?void 0:n.params_plantillas.map(D=>{const te=j[D.params_tipo.order-1];return a.jsx(p.Badge,{color:te.color,theme:te.theme,label:D.name,size:"sm"},D.name)})}),!e&&a.jsx(p.Card.Separator,{vertical:e}),a.jsxs(p.Card.Footer,{className:"tm-flex tm-justify-between tm-w-full md:tm-w-auto tm-gap-x-4",children:[a.jsxs("div",{className:`tm-flex tm-flex-1 ${e?"tm-gap-x-2 md:tm-gap-20 lg:tm-gap-32 2xl:tm-gap-44":""}`,children:[a.jsx("div",{className:`tm-flex tm-gap-x-8 tm-justify-center tm-items-center tm-flex-1 ${e?"tm-flex-col":"tm-flex-row"}`,children:a.jsx(p.Tooltip,{label:"Tareas totales",children:a.jsxs("div",{className:`tm-flex tm-items-center tm-gap-8 ${e?"tm-flex-col":"tm-flex-row"}`,children:[a.jsx(p.Text,{size:"xs",weight:"semibold",color:"brand",children:(n==null?void 0:n.counts_tasks)||0}),a.jsx(p.Text,{size:"xs",weight:"regular",color:"tertiary",children:X})]})})}),a.jsx("div",{className:`tm-flex tm-gap-x-8 tm-justify-center tm-items-center tm-flex-1 ${e?"tm-flex-col":"tm-flex-row"}`,children:a.jsx(p.Tooltip,{label:"Tareas totales",children:a.jsxs("div",{className:`tm-flex tm-items-center tm-gap-8 ${e?"tm-flex-col":"tm-flex-row"}`,children:[a.jsx(p.Text,{size:"xs",weight:"semibold",color:"brand",children:(n==null?void 0:n.dias_duracion)||0}),a.jsx(p.Text,{size:"xs",weight:"regular",color:"tertiary",children:E})]})})}),a.jsxs("div",{className:`tm-flex tm-gap-x-8 tm-justify-center tm-items-center tm-flex-1 ${e?"tm-flex-col-reverse tm-gap-y-1":"tm-flex-row"}`,children:[a.jsx(p.Text,{size:"xs",weight:"regular",color:"tertiary",children:"Editor"}),a.jsx(p.Tooltip,{label:K,children:a.jsx(p.Avatar,{src:M,size:"xxs",type:"people"})})]}),R&&a.jsx("div",{className:`tm-flex tm-gap-x-8 tm-justify-center tm-items-center tm-flex-1 ${e?"tm-flex-col":"tm-flex-row"}`,children:a.jsx(As,{layout:"row"})})]}),e&&i&&a.jsx(p.Card.Separator,{vertical:e}),i&&a.jsx("div",{className:`tm-w-auto ${e?"tm-flex tm-items-center":""}`,children:e&&a.jsx(Pa,{template:n,openModalPublishTemplate:C,onHadleClickEditTemplateParams:L,onEditTasks:N,canDuplicateAndDeleteTemplates:$,onHandleClickDuplicateTemplate:O,openModalDeleteTemplate:F})})]})]})},ri=[{label:"Muy alta",value:4,icon:le.faFlag,iconColor:"red"},{label:"Alta",value:3,icon:le.faFlag,iconColor:"yellow"},{label:"Media",value:2,icon:le.faFlag,iconColor:"blue"},{label:"Baja",value:1,icon:le.faFlag,iconColor:"neutral"}],ii=[{label:"Muy alta",value:4,icon:le.faRhombus,iconColor:"red"},{label:"Alta",value:3,icon:le.faRhombus,iconColor:"yellow"},{label:"Media",value:2,icon:le.faRhombus,iconColor:"blue"},{label:"Baja",value:1,icon:le.faRhombus,iconColor:"neutral"}],li=[{label:"1 día",value:1},{label:"2 días",value:2},{label:"3 días",value:3},{label:"4 días",value:4},{label:"5 días",value:5},{label:"6 días",value:6},{label:"7 días",value:7}],Ds=({isOpen:e,onClose:t,onSuccess:s,nodeDataType:o,parentNodeInfo:n,editMode:i=!1,taskToEdit:r})=>{const{data:l}=$a(),{users:d}=yt(),{users:c}=nt(),{getImageOBP:m}=fe(),f=u.useMemo(()=>{try{return!d||!c?[]:d.map(C=>{const F=c[C.email],E=F!=null&&F.image?m(F.image):"";return{label:C.name,value:C.id.toString(),icon:E}})}catch(C){return console.error("Error mapeando usuarios:",C),[]}},[d,c]),g=()=>{if(i&&r){const C=U=>{if(U==null)return"";const z=Number(U);return isNaN(z)?"":z},F=U=>U?typeof U=="string"?Number(U)||"":U.id||"":"",E=U=>{var z;return U?typeof U=="string"?U:((z=U.id)==null?void 0:z.toString())||U.name||U.nombre||"":""};return{title:r.texto_corto||"",description:r.texto_largo||"",priority:C(r.prioridad),difficulty:C(r.nivel_dificultad),duration:C(r.duracion),team:F(r.equipo),responsible:E(r.responsable),type:"tarea",is_monitoring_trigger:r.is_monitoring_trigger===!0}}return{title:"",description:"",priority:"",difficulty:"",duration:"",team:"",responsible:"",type:"tarea",is_monitoring_trigger:!1}},{control:h,handleSubmit:x,formState:{errors:y,isValid:j},reset:b,watch:w}=Ce.useForm({mode:"onChange",defaultValues:g()});u.useEffect(()=>{e&&b(g())},[e,i,r,b]);const v=w(),N=j&&v.title&&v.description&&v.priority&&v.difficulty&&v.duration&&v.team&&Object.keys(y).length===0,L=async C=>{try{if(["title","description","priority","difficulty","duration","team"].filter(X=>!C[X]).length>0)return;s&&await s({...C,parent:n}),i||b()}catch{}},O=()=>{b(),t()};return a.jsx(p.Drawer,{titleIcon:le.faPencil,isOpen:e,onClose:O,onSuccess:()=>{x(C=>{L(C)},C=>{const F=Object.entries(C).map(([E,X])=>`${E}: ${X.message}`).join(`
package/dist/tareas.es.js CHANGED
@@ -4362,7 +4362,7 @@ const ql = ({ idTask: e, setOpen: t, paused: o }) => {
4362
4362
  re(() => {
4363
4363
  K(b ?? 0);
4364
4364
  }, [b]);
4365
- const G = Number(b ?? 0), P = Number(g ?? 0), ae = P > 0 && G === P, ee = P > 1 && !ae, A = P <= 1, U = p === 0, Y = !ee && (ae || A || U) && p !== 2, k = (m ?? "") !== "" && f === 2, { user: D } = Pe(), W = Ht(D == null ? void 0 : D.role, p), _ = ja(), E = !!(_ != null && _.selectedTaskIds.includes(e)), j = Y && (k || !m), O = !!_ && !!S && S !== "Completadas" && !Q, N = O && j, X = O && !j && !!(_ != null && _.isBulkSessionActive), Z = !!(_ != null && _.isMultiSelectActive && N && k), ne = !N || !!(_ != null && _.isBulkLoading), ie = (fe) => {
4365
+ const G = Number(b ?? 0), P = Number(g ?? 0), ae = P > 0 && G === P, ee = P >= 1 && !ae && p === 1, A = P <= 1, U = p === 0, Y = !ee && (ae || A || U) && p !== 2, k = (m ?? "") !== "" && f === 2, { user: D } = Pe(), W = Ht(D == null ? void 0 : D.role, p), _ = ja(), E = !!(_ != null && _.selectedTaskIds.includes(e)), j = Y && (k || !m), O = !!_ && !!S && S !== "Completadas" && !Q, N = O && j, X = O && !j && !!(_ != null && _.isBulkSessionActive), Z = !!(_ != null && _.isMultiSelectActive && N && k), ne = !N || !!(_ != null && _.isBulkLoading), ie = (fe) => {
4366
4366
  !_ || !S || ne || _.toggleTaskSelection(e, S);
4367
4367
  }, J = () => /* @__PURE__ */ w("div", { className: "tm-relative tm-flex tm-h-fit tm-w-full tm-items-center tm-justify-between", children: [
4368
4368
  /* @__PURE__ */ w("div", { className: "tm-flex tm-min-w-0 tm-flex-1 tm-flex-row tm-items-start tm-gap-[8px]", children: [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imj_media/tareas",
3
3
  "private": false,
4
- "version": "1.6.4",
4
+ "version": "1.6.5",
5
5
  "scripts": {
6
6
  "build": "vite build",
7
7
  "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",