import{api as m}from"./common-DEIQtiPI.js";import"./index-DOFLUERq.js";const n=["email_server","use_imap","use_ssl","use_starttls","use_tls","attachment_limit","smtp_server","smtp_port","use_ssl_for_outgoing","append_emails_to_sent_folder","incoming_port"],r={GMail:{email_server:"imap.gmail.com",incoming_port:993,use_ssl:1,enable_outgoing:1,smtp_server:"smtp.gmail.com",smtp_port:587,use_tls:1,use_imap:1},"Outlook.com":{email_server:"imap-mail.outlook.com",use_ssl:1,enable_outgoing:1,smtp_server:"smtp-mail.outlook.com",smtp_port:587,use_tls:1,use_imap:1},Sendgrid:{enable_outgoing:1,smtp_server:"smtp.sendgrid.net",smtp_port:587,use_tls:1},SparkPost:{enable_incoming:0,enable_outgoing:1,smtp_server:"smtp.sparkpostmail.com",smtp_port:587,use_tls:1},"Yahoo Mail":{email_server:"imap.mail.yahoo.com",use_ssl:1,enable_outgoing:1,smtp_server:"smtp.mail.yahoo.com",smtp_port:587,use_tls:1,use_imap:1},"Yandex.Mail":{email_server:"imap.yandex.com",use_ssl:1,enable_outgoing:1,smtp_server:"smtp.yandex.com",smtp_port:587,use_tls:1,use_imap:1}},l={GMail:{email_server:"pop.gmail.com"},"Outlook.com":{email_server:"pop3-mail.outlook.com"},"Yahoo Mail":{email_server:"pop.mail.yahoo.com"},"Yandex.Mail":{email_server:"pop.yandex.com"}},p={fieldname:"domain",handler:async e=>{const o=e.value;if(o)try{const a=await m.call("jingrow.client.get_value",{pagetype:"Email Domain",fieldname:JSON.stringify(n),filters:JSON.stringify({name:o}),as_dict:1}),s=a?.message??a;if(s&&typeof s=="object")for(const[i,t]of Object.entries(s))t!=null&&(e.record[i]=t)}catch(a){console.error("[EmailAccount] Failed to fetch domain values:",a)}}},_={fieldname:"service",handler:e=>{const o=e.value;if(!o||!r[o])return;const a=r[o];for(const[s,i]of Object.entries(a))e.record[s]=i;if(!e.record.use_imap&&l[o]){const s=l[o];for(const[i,t]of Object.entries(s))e.record[i]=t}}},c={fieldname:"use_imap",handler:e=>{const o=e.record.service;if(o){if(e.value){if(r[o])for(const[a,s]of Object.entries(r[o]))e.record[a]=s}else if(l[o])for(const[a,s]of Object.entries(l[o]))e.record[a]=s}}},u={pagetype:"Email Account",handler:e=>{(!e.imap_folder||!Array.isArray(e.imap_folder)||e.imap_folder.length===0)&&(e.imap_folder=[{folder_name:"INBOX"}])}},g=[p,_,c,u];export{g as default};
