import{j as e}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1165.js";import{r as u}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb116.js";import{G as y,ah as N}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb11623.js";import{u as I,r as R}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1164.js";import{p as m,cK as g,r as v,I as x}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1167.js";import{O as F}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1166.js";import"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1163.js";import"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1162.js";import"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1169.js";import"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb11610.js";import"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb11620.js";import"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1168.js";function q({userId:f,create:n,notification:o,onBackBtnClickHnd:h}){const{language:t}=I(),{setNotifications:b,editNotification:w,notifications:S}=y(),[a,_]=u.useState({id:R(),date:"",read:!1,timeOut:!1,time:"",title:"",desc:"",user_id:f}),[p,A]=u.useState(!1);u.useEffect(()=>{o&&_(o)},[o]);const d=(s,i)=>{_({...a,[s]:i})},j=async s=>{if(s.preventDefault(),await N("lembretes"))console.error("User is FREE, cannot proceed.");else{const r={id:a.id||R(),date:a.date,read:!1,timeOut:!1,time:a.time,title:a.title,desc:a.desc,user_id:f};if(p){let l=new Date;l.setHours(l.getHours()-3),l.setMinutes(l.getMinutes()-5);let C=l.toISOString().slice(0,10),D=l.toISOString().slice(11,16).replace(":",""),c="https://calendar.google.com/calendar/render?action=TEMPLATE&text=";c+=`${encodeURIComponent(a.title)}&dates=${C.replace(new RegExp("[-:+]","g"),"")}T${D}/${a.date.replace(new RegExp("[-:+]","g"),"")}T${a.time.replace(new RegExp("[-:+]","g"),"")}`,c+=`&details=${encodeURIComponent(a.desc)}`,c+="&ctz=America/Sao_Paulo",window.open(c,"_blank")}if(r.title.length>0&&r.desc.length>0&&r.date.length>0&&r.time.length>0){if(n)b([...S,r]);else if(o.id)w(o.id,r);else{console.error("Invalid notification ID:",o?.id);return}x({type:"Success",message:`${n?t.modal_createAReminder_alertMessageSucess:t.modal_createAReminder_alertMessageSucessEdit}`,position:"top-right"}),h()}else x({type:"Error",message:t.modal_createAReminder_FillAllFields,position:"top-right"})}},E=s=>{const{value:i}=s.target,r=i,l=new Date().toISOString().slice(0,10);if(r<l){x({type:"Error",message:t.modal_createAReminder_alertMessageDataError,position:"top-right"});return}d("date",i)};return e.jsxs("form",{className:"w-[30rem] h-auto flex flex-col gap-2 p-2",onSubmit:j,children:[e.jsxs("header",{className:"flex flex-col gap-3",children:[e.jsx(m,{size:"20px",weight:"bold",children:n?t.modal_createAReminder_title:t.modal_editAReminder_title}),e.jsx(m,{size:"14px",children:t.modal_createAReminder_subTitle})]}),e.jsxs("main",{className:"flex flex-col gap-2",children:[e.jsx(g,{icon:e.jsx(F,{size:16}),title:t.modal_name,type:"text",placeHolder:t.modal_createAReminder_PlaceHoldertittle,value:a.title,onchange:s=>d("title",s.target.value),maxLength:55}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(m,{size:"17px",weight:"bold",children:t.description}),e.jsx("textarea",{placeholder:t.modal_createAReminder_subDesc,rows:6,maxLength:784,className:"w-full p-2 text-sm leading-5 text-[var(--primary)] bg-base-200 input-bordered rounded-md resize-none",onChange:s=>d("desc",s.target.value),value:a.desc})]}),e.jsx(g,{title:t.modal_date,type:"date",value:a.date,onchange:E}),e.jsx(g,{title:t.modal_hours,type:"time",value:a.time,onchange:s=>d("time",s.target.value)})]}),e.jsxs("footer",{className:"flex flex-col mt-2 gap-3",children:[e.jsxs("div",{className:"flex gap-3 w-full items-center",children:[e.jsx("input",{type:"checkbox",name:"Google Calendar",checked:p,onChange:()=>A(!p)}),e.jsx(m,{children:t.modal_createAReminder_checkBoxText})]}),e.jsxs("div",{className:"flex w-full justify-evenly",children:[e.jsx(v,{funcao:h,name:t.modal_schedulingCallendar_cancelButton}),e.jsx(v,{funcao:j,name:n?t.modal_schedulingCallendar_saveButton:t.modal_schedulingCallendar_editButton})]})]})]})}export{q as default};
