import{a as v}from"./formatters-jmx2pV9o.js";const b=new Date().toISOString().slice(0,10),x={brouillon:"border-gold/30 bg-gold/10 text-gold",deposee:"border-accent/30 bg-accent/10 text-accent",validee:"border-accent2/30 bg-accent2/10 text-accent2"},N={upcoming:"border-border bg-surface2 text-textMuted",due_soon:"border-gold/30 bg-gold/10 text-gold",overdue:"border-danger/30 bg-danger/10 text-danger",filed:"border-accent2/30 bg-accent2/10 text-accent2"},A=[{trimestre:1,label:"1er trimestre",monthsLabel:"Janvier, Fevrier, Mars",deadlineLabel:"20 Avril"},{trimestre:2,label:"2eme trimestre",monthsLabel:"Avril, Mai, Juin",deadlineLabel:"20 Juillet"},{trimestre:3,label:"3eme trimestre",monthsLabel:"Juillet, Aout, Septembre",deadlineLabel:"20 Octobre"},{trimestre:4,label:"4eme trimestre",monthsLabel:"Octobre, Novembre, Decembre",deadlineLabel:"20 Janvier N+1"}],n=e=>String(e??"").trim(),c=e=>Number(Number(e||0).toFixed(2)),l=(e,r="0")=>{if(e==null||e==="")return r;const t=Number(e);return Number.isFinite(t)?String(c(t)):r},i=e=>{if(e==null||e==="")return 0;const r=n(e).replace(/\s+/g,"").replace(",","."),t=Number(r);return Number.isFinite(t)?c(t):0},_=e=>e?e.label&&/^\d{4}$/.test(String(e.label))?String(e.label):e.start_date?String(e.start_date).slice(0,4):e.end_date?String(e.end_date).slice(0,4):String(new Date().getUTCFullYear()):String(new Date().getUTCFullYear()),s=(e=new Date)=>{const r=e instanceof Date?e:new Date(e);return Math.floor(r.getUTCMonth()/3)+1},D=({companyId:e="",companySettings:r=null,profile:t=null,fiscalYear:d=null,item:a=null}={})=>a?{company_id:String(e),fiscal_year_id:String(a.fiscal_year_id||(d==null?void 0:d.id)||""),annee:String(a.annee||_(d)),trimestre:String(a.trimestre||s()),salaires_imposables_t:l(a.salaires_imposables_t),taux_bareme:a.taux_bareme||"Bareme IRG",montant_irg:l(a.montant_irg),quittance_numero:a.quittance_numero||"",quittance_date:a.quittance_date||"",lieu_declaration:a.lieu_declaration||(r==null?void 0:r.city)||"",date_signature:a.date_signature||b,receveur_signature:a.receveur_signature||"",receveur_date:a.receveur_date||"",nif:a.nif||(t==null?void 0:t.nif)||(r==null?void 0:r.nif)||"",nin:a.nin||(t==null?void 0:t.nin)||"",article_imposition:a.article_imposition||(t==null?void 0:t.article_imposition)||(r==null?void 0:r.ai)||"",code_activite:a.code_activite||(t==null?void 0:t.code_activite)||"",activity_description:(t==null?void 0:t.activity_description)||"",company_name:(r==null?void 0:r.name)||"",address:(r==null?void 0:r.address)||"",phone:(r==null?void 0:r.phone)||""}:{company_id:String(e),fiscal_year_id:String((d==null?void 0:d.id)||""),annee:_(d),trimestre:String(s()),salaires_imposables_t:"0",taux_bareme:"Bareme IRG",montant_irg:"0",quittance_numero:"",quittance_date:"",lieu_declaration:(r==null?void 0:r.city)||"",date_signature:b,receveur_signature:"",receveur_date:"",nif:(t==null?void 0:t.nif)||(r==null?void 0:r.nif)||"",nin:(t==null?void 0:t.nin)||"",article_imposition:(t==null?void 0:t.article_imposition)||(r==null?void 0:r.ai)||"",code_activite:(t==null?void 0:t.code_activite)||"",activity_description:(t==null?void 0:t.activity_description)||"",company_name:(r==null?void 0:r.name)||"",address:(r==null?void 0:r.address)||"",phone:(r==null?void 0:r.phone)||""},G=e=>{const r={},t=i(e.salaires_imposables_t),d=i(e.montant_irg);return n(e.fiscal_year_id)||(r.fiscal_year_id="L'exercice fiscal est obligatoire."),n(e.trimestre)||(r.trimestre="Le trimestre est obligatoire."),t<0&&(r.salaires_imposables_t="Le montant des salaires doit etre positif."),d<0&&(r.montant_irg="Le montant IRG doit etre positif."),n(e.quittance_date)&&!/^\d{4}-\d{2}-\d{2}$/.test(e.quittance_date)&&(r.quittance_date="La date de quittance est invalide."),n(e.date_signature)||(r.date_signature="La date de signature est obligatoire."),r},g=e=>({company_id:Number(e.company_id),fiscal_year_id:Number(e.fiscal_year_id),annee:Number(e.annee),trimestre:Number(e.trimestre),salaires_imposables_t:i(e.salaires_imposables_t),taux_bareme:n(e.taux_bareme)||"Bareme IRG",montant_irg:i(e.montant_irg),quittance_numero:n(e.quittance_numero),quittance_date:n(e.quittance_date)||null,lieu_declaration:n(e.lieu_declaration)||null,date_signature:n(e.date_signature)||null,receveur_signature:n(e.receveur_signature)||null,receveur_date:n(e.receveur_date)||null}),q=e=>x[e]||"border-border bg-surface2 text-text",R=e=>N[e]||"border-border bg-surface2 text-textMuted",h=(e,r)=>{const t=Array.isArray(e)?e:[];if(!t.length)return null;const d=Number(_(r)),a=new Date().getUTCFullYear(),o=s();return d===a?t.find(u=>Number(u.trimestre)===o)||t.find(u=>u.statut==="brouillon")||t[0]:t.find(u=>u.statut==="brouillon")||t[0]},m=(e=[])=>A.map(r=>({...r,...e.find(t=>Number(t.trimestre)===r.trimestre)||{}})),E=e=>v(e);export{q as a,D as b,m as c,_ as d,E as e,h as f,R as g,g as s,b as t,G as v};
