@amsom-habitat/cresol 0.2.1 → 0.2.3

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 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@amsom-habitat/ui"),require("vue"),require("@amsom-habitat/nav-tabs"),require("@amsom-habitat/horizontal-stepper"),require("@amsom-habitat/amsom-autocomplete"),require("@amsom-habitat/axios-overlay"),require("@amsom-habitat/user-manager"),require("@fortawesome/fontawesome-svg-core"),require("@amsom-habitat/amsom-textarea"),require("@amsom-habitat/file-manager")):typeof define==`function`&&define.amd?define([`exports`,`@amsom-habitat/ui`,`vue`,`@amsom-habitat/nav-tabs`,`@amsom-habitat/horizontal-stepper`,`@amsom-habitat/amsom-autocomplete`,`@amsom-habitat/axios-overlay`,`@amsom-habitat/user-manager`,`@fortawesome/fontawesome-svg-core`,`@amsom-habitat/amsom-textarea`,`@amsom-habitat/file-manager`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Cresol={},e._amsom_habitat_ui,e.Vue,e._amsom_habitat_nav_tabs,e._amsom_habitat_horizontal_stepper,e._amsom_habitat_amsom_autocomplete,e._amsom_habitat_axios_overlay,e._amsom_habitat_user_manager,e._fortawesome_fontawesome_svg_core,e._amsom_habitat_amsom_textarea,e._amsom_habitat_file_manager))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var d=Object.create,f=Object.defineProperty,p=Object.getOwnPropertyDescriptor,m=Object.getOwnPropertyNames,h=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty,_=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=m(t),a=0,o=i.length,s;a<o;a++)s=i[a],!g.call(e,s)&&s!==n&&f(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=p(t,s))||r.enumerable});return e},v=(e,t,n)=>(n=e==null?{}:d(h(e)),_(t||!e||!e.__esModule||!g.call(e,`default`)?f(n,`default`,{value:e,enumerable:!0}):n,e));i=v(i),o=v(o,1),s=v(s,1);var y=[{id:`T`,libelle:`Téléphone`,icon:`phone`},{id:`M`,libelle:`Email`,icon:`envelope`},{id:`G`,libelle:`Gardien`,icon:`user-shield`},{id:`V`,libelle:`Visite au siège`,icon:`building`},{id:`IP`,libelle:`Incident de permanence`,icon:`exclamation-triangle`},{id:`C`,libelle:`Courrier`,icon:`envelope-open`}],ee=`T`,b=Symbol(`cresol:draft`),x=()=>({idCommune:null,commune:null,idEntree:null,entree:null,etage:null,idModule:null,libelleModule:null,codeProgramme:null,codeTranche:null,codeBatiment:null,codeEscalier:null,typeContratActuel:null,idContratActuel:null,occupantActuel:null}),S=()=>({idMotif:null,idCategorie:null,idType:null,idNature:null,libelle:null,responsable:null,cibleOverride:!1,cibleMode:null,contratReclamant:!0,contratCible:null,reprendreLocataireActuel:!1,patrimoine:null,description:null,dateFaits:null,dateFaitsOverride:!1,fichier:null}),C=[`reclamant`,`provenance`,`motif`,`cible`,`description`,`dateFaits`,`responsable`,`fichier`],te=[`D`,`U`,`T`],w=(e=`T`)=>({reclamant:{type:null,id:null},provenance:e,lignes:[{...S(),cibleMode:`contrat`,patrimoine:x(),description:``}]}),ne=e=>e?.id??e??null,re=e=>{if(!e)return`Cible non définie`;let t=[e.commune,e.entree,e.libelleModule].filter(Boolean);return e.etage!=null&&!e.libelleModule&&t.push(`Étage ${e.etage}`),t.length?t.join(` — `):`Cible non définie`},ie=e=>!!e&&(e.idModule!=null||e.idEntree!=null),ae=(e,t)=>e.cibleMode===`demande`||!e.cibleOverride&&e.patrimoine==null?!0:e.cibleMode===`contrat`?!!(e.contratReclamant&&t||e.contratCible)&&e.patrimoine?.idModule!=null:ie(e.patrimoine),oe=(e,t)=>e.description==null?!t:e.description.trim().length>0,T=(e={})=>{let t={...S(),...e};return e.patrimoine&&(t.patrimoine={...x(),...e.patrimoine}),t},se=e=>{let t=w();if(!e)return t;let n=Array.isArray(e.lignes)&&e.lignes.length?e.lignes:null;return{...t,...e,reclamant:{...t.reclamant,...e.reclamant??{}},provenance:e.provenance??t.provenance,lignes:n?n.map((e,n)=>n===0?{...t.lignes[0],...T(e)}:T(e)):t.lignes}};function ce({reclamants:e,modules:t,idModulePrefere:r=(0,n.ref)(null),readonly:i=(0,n.ref)(!1)}={}){let a=(0,n.reactive)(w()),o=(0,n.computed)(()=>{let e=(0,n.unref)(i);return e===!0?C:Array.isArray(e)?e:[]}),s=e=>o.value.includes(e),c=(0,n.computed)(()=>a.lignes[0]),l=(0,n.computed)(()=>a.lignes.slice(1)),u=(0,n.computed)(()=>(0,n.unref)(e)??[]),d=(0,n.ref)(null),f=(e,t)=>e.type===t.type&&String(e.id)===String(t.id),p=(0,n.computed)(()=>{let e=d.value;return!e||u.value.some(t=>f(t,e))?u.value:[...u.value,e]}),m=(0,n.computed)(()=>p.value.find(e=>f(e,a.reclamant))??p.value[0]??null),h=(0,n.computed)(()=>{let e=(0,n.unref)(t)??[],i=(0,n.unref)(r);return(i==null?null:e.find(e=>String(e.idModule)===String(i)))??e.find(e=>e.estModulePrincipal)??e[0]??null}),g=(0,n.computed)(()=>!!m.value&&!te.includes(m.value.type)),_={draft:a,lignePrincipale:c,lignesAssociees:l,reclamantsFournis:u,reclamantsDisponibles:p,reclamantSelectionne:m,moduleReclamantPrincipal:h,reclamantEstContrat:g,ciblesValid:(0,n.computed)(()=>a.lignes.every(e=>ae(e,g.value))),detailsValid:(0,n.computed)(()=>a.lignes.every((e,t)=>oe(e,t===0))),isReadonly:s,reset(e=null){let t=se(e);Object.assign(a,t),a.lignes=t.lignes},setProvenance(e){a.provenance=e},syncReclamant(){let e=m.value;_.setReclamant({type:e?.type??null,id:e?.id??null})},selectReclamant(e){e&&(u.value.some(t=>f(t,e))||(d.value=e),_.setReclamant(e))},setReclamant({type:e,id:t}){if(a.reclamant={type:e??null,id:t??null},s(`cible`))return;let n=a.lignes[0];e===`D`?(n.cibleMode=`demande`,n.patrimoine=null):(n.cibleMode=g.value?`contrat`:`patrimoine`,n.contratReclamant=g.value,n.contratCible=null,n.reprendreLocataireActuel=!1,n.patrimoine=x(),_.prefillCiblePrincipale())},prefillCiblePrincipale(){if(s(`cible`))return;let e=h.value;e&&_.prefillFromModule(0,e)},_resetAfterNomenclature(){a.lignes[0].responsable=null,a.lignes.splice(1)},setCategorie(e){let t=a.lignes[0];t.idCategorie=e,t.idType=null,t.idNature=null,t.idMotif=null,_._resetAfterNomenclature()},setType(e){let t=a.lignes[0];t.idType=e,t.idNature=null,t.idMotif=null,_._resetAfterNomenclature()},setNature(e){let t=a.lignes[0];t.idNature=e,t.idMotif=null,_._resetAfterNomenclature()},setMotif(e){a.lignes[0].idMotif=e,_._resetAfterNomenclature()},selectMotifChain(e){let t=a.lignes[0];t.idCategorie=e?.idCategorie??null,t.idType=e?.idType??null,t.idNature=e?.idNature??null,t.idMotif=e?.id??null,_._resetAfterNomenclature()},toggleLigneAssociee(e,t={}){let n=a.lignes.findIndex((t,n)=>n>0&&t.idMotif===e);n===-1?a.lignes.push({...S(),idMotif:e,...t}):a.lignes.splice(n,1)},_patrimoine(e){return a.lignes[e]?.patrimoine??null},setCibleMode(e,t){let n=a.lignes[e];n&&(n.cibleMode=t,n.reprendreLocataireActuel=!1,n.contratReclamant=t===`contrat`&&g.value,n.contratCible=null,t===`demande`?n.patrimoine=null:n.patrimoine??=x())},toggleContratReclamant(e,t){let n=a.lignes[e];n&&(n.contratReclamant=t??!n.contratReclamant,n.contratCible=null,n.patrimoine&&_.setPatrimoineModule(e,null))},setContratCible(e,t){let n=a.lignes[e];n&&(n.contratCible=t?{typeContrat:t.typeContrat,idContrat:t.idContrat,libelle:t.libelleContrat??null}:null,_.setPatrimoineModule(e,null))},setPatrimoineCommune(e,t){let n=_._patrimoine(e);n&&(n.idCommune=t?.idCommune??null,n.commune=t?.commune??null,_.setPatrimoineEntree(e,null))},setPatrimoineEntree(e,t){let n=_._patrimoine(e);n&&(n.idEntree=t?.idEntree??null,n.entree=t?.entree??null,n.codeProgramme=t?.codeProgramme??null,n.codeTranche=t?.codeTranche??null,n.codeBatiment=t?.codeBatiment??null,n.codeEscalier=t?.codeEscalier??null,n.etage=null,_.setPatrimoineModule(e,null))},setPatrimoineEtage(e,t){let n=_._patrimoine(e);n&&(n.etage=t,_.setPatrimoineModule(e,null))},setPatrimoineModule(e,t){let n=_._patrimoine(e);n&&(n.idModule=t?.idModule??null,n.libelleModule=t?.libelleModule??null,n.typeContratActuel=t?.typeContratActuel??null,n.idContratActuel=t?.idContratActuel??null,n.occupantActuel=t?.occupantActuel??null,t&&(n.codeProgramme=t.codeProgramme??n.codeProgramme,n.codeTranche=t.codeTranche??n.codeTranche,n.codeBatiment=t.codeBatiment??n.codeBatiment,n.codeEscalier=t.codeEscalier??n.codeEscalier,t.idEntree!=null&&(n.idEntree=t.idEntree),t.etage!=null&&(n.etage=t.etage)))},prefillFromModule(e,t){let n=_._patrimoine(e);n&&t&&(n.idCommune=t.idCommune??null,n.commune=t.commune??null,n.idEntree=t.idEntree??null,n.entree=t.adresse??t.numeroRue??null,n.codeProgramme=t.codeProgramme??null,n.codeTranche=t.codeTranche??null,n.codeBatiment=t.codeBatiment??null,n.codeEscalier=t.codeEscalier??null,n.etage=t.etage??null,n.idModule=t.idModule??null,n.libelleModule=t.libelleModule??t.adresse??null,n.typeContratActuel=t.typeContratActuel??null,n.idContratActuel=t.idContratActuel??null,n.occupantActuel=t.occupantActuel??null)},toggleCibleOverride(e){let t=a.lignes[e];if(!t)return;let n=a.lignes[0];t.cibleOverride?(t.cibleOverride=!1,t.cibleMode=null,t.patrimoine=null,t.reprendreLocataireActuel=!1,t.contratReclamant=!0,t.contratCible=null):(t.cibleOverride=!0,t.cibleMode=n.cibleMode,t.patrimoine=n.cibleMode===`demande`?null:{...n.patrimoine},t.reprendreLocataireActuel=n.reprendreLocataireActuel,t.contratReclamant=n.contratReclamant,t.contratCible=n.contratCible?{...n.contratCible}:null)},setReprendreLocataireActuel(e,t){let n=a.lignes[e];n&&(n.reprendreLocataireActuel=!!t)},setDescription(e,t){let n=a.lignes[e];n&&(n.description=t)},setDateFaits(e,t){let n=a.lignes[e];n&&(n.dateFaits=t)},setResponsable(e,t){let n=a.lignes[e];n&&(n.responsable=t)},setFichier(e,t){let n=a.lignes[e];n&&(n.fichier=t)},toggleDescriptionOverride(e){let t=a.lignes[e];t&&(t.description=t.description==null?``:null)},toggleDateFaitsOverride(e){let t=a.lignes[e];t&&(t.dateFaitsOverride=!t.dateFaitsOverride,t.dateFaits=t.dateFaitsOverride?a.lignes[0].dateFaits:null)},_patrimoinePayload(e){return e.idModule==null?{idProgramme:e.codeProgramme,idTranche:e.codeTranche,idBatiment:e.codeBatiment,idEscalier:e.codeEscalier,etage:e.etage}:{idModule:e.idModule}},_lignePayload(e,t){let n=a.lignes[0],r=t>0&&!e.cibleOverride?n:e,i=(e.description??``).trim()||(n.description??``).trim(),o=e.dateFaits==null?n.dateFaits:e.dateFaits,s=a.reclamant.type===`D`,c={categorie:e.idCategorie,type:e.idType,nature:e.idNature,motif:e.idMotif,description:i,dateFaits:o,responsable:ne(e.responsable)};if(r.cibleMode===`demande`)return{...c,codeTypeCible:`D`,idCible:a.reclamant.id,deduireCible:!1};let l=_._patrimoinePayload(r.patrimoine);if(r.cibleMode===`contrat`&&!r.reprendreLocataireActuel){let e=r.contratReclamant&&g.value?{typeContrat:a.reclamant.type,idContrat:a.reclamant.id}:r.contratCible;return{...c,patrimoine:l,codeTypeCible:e?.typeContrat??null,idCible:e?.idContrat??null,deduireCible:!1}}return{...c,patrimoine:l,codeTypeCible:null,idCible:null,deduireCible:r.patrimoine?.idModule!=null&&!s}},cibleResume(e){let t=a.lignes[0],n=e!==t&&!e.cibleOverride?t:e;if(n.cibleMode===`demande`)return`La demande`;let r=re(n.patrimoine);if(n.cibleMode!==`contrat`)return r;let i=`Contrat non défini`;if(n.contratReclamant&&g.value)i=`Contrat du réclamant`;else if(n.contratCible){let e=n.contratCible;i=`${e.libelle??`Contrat`} (${e.typeContrat}/${e.idContrat})`}return`${i} — ${r}`},lignesPayload(){return a.lignes.map((e,t)=>_._lignePayload(e,t))},creationPayload(){let e=m.value;return{typeReclamant:e?.type??null,reclamant:e?.id??null,lignes:_.lignesPayload(),provenance:a.provenance}}};return(0,n.reactive)(_)}function le(e){return(0,n.provide)(b,e),e}function E(){let e=(0,n.inject)(b,null);if(!e)throw Error(`useSollicitationDraft() hors de <creer-sollicitation-form>`);return e}var D=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},ue={name:`AsideBlock`,components:{AmsomNavTabsHorizontal:r.AmsomNavTabsHorizontal},props:{nbSimilaires:{type:Number,default:0}},setup(){return{draft:E()}},data(){return{activeTab:null}},computed:{lignePrincipale(){return this.draft.lignePrincipale},scope(){let e=this.lignePrincipale,t=e?.cibleMode===`demande`;return{idMotif:e?.idMotif??null,codeProgramme:t?null:e?.patrimoine?.codeProgramme??null,idCible:t?this.draft.draft.reclamant?.id??null:null,reclamant:this.draft.reclamantSelectionne}},tabs(){return[...this.$slots.similaires?[{id:`similarite`,label:`Similarité`,icon:`layer-group`}]:[],...this.$slots.evenements?[{id:`evenements`,label:`Événements`,icon:`circle-exclamation`}]:[]]}},watch:{tabs:{immediate:!0,handler(e){e.some(e=>e.id===this.activeTab)||(this.activeTab=e[0]?.id??null)}}}},de={key:0,class:`badge bg-danger ms-1`},fe={style:{"min-height":`320px`}},pe={key:0},me={key:1};function he(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`font-awesome-icon`),c=(0,n.resolveComponent)(`amsom-nav-tabs-horizontal`);return o.tabs.length?((0,n.openBlock)(),(0,n.createBlock)(c,{key:0,modelValue:a.activeTab,"onUpdate:modelValue":t[0]||=e=>a.activeTab=e,items:o.tabs,"item-key":`id`,"tab-spacing":1},{libelle:(0,n.withCtx)(({item:e})=>[(0,n.createVNode)(s,{icon:e.icon},null,8,[`icon`]),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.label),1),e.id===`similarite`&&r.nbSimilaires>0?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,de,(0,n.toDisplayString)(r.nbSimilaires),1)):(0,n.createCommentVNode)(``,!0)]),content:(0,n.withCtx)(()=>[(0,n.createElementVNode)(`div`,fe,[e.$slots.similaires?(0,n.withDirectives)(((0,n.openBlock)(),(0,n.createElementBlock)(`div`,pe,[(0,n.renderSlot)(e.$slots,`similaires`,(0,n.normalizeProps)((0,n.guardReactiveProps)(o.scope)))],512)),[[n.vShow,a.activeTab===`similarite`]]):(0,n.createCommentVNode)(``,!0),e.$slots.evenements?(0,n.withDirectives)(((0,n.openBlock)(),(0,n.createElementBlock)(`div`,me,[(0,n.renderSlot)(e.$slots,`evenements`)],512)),[[n.vShow,a.activeTab===`evenements`]]):(0,n.createCommentVNode)(``,!0)])]),_:3},8,[`modelValue`,`items`])):(0,n.createCommentVNode)(``,!0)}var ge=D(ue,[[`render`,he]]),O={baseUrl:``,getToken:()=>s.default.getToken(),setToken:e=>s.default.setToken(e),logout:()=>s.default.logout(),goToLoginPage:()=>s.default.goToLoginPage()};function _e(e={}){Object.assign(O,e)}var k=()=>O;function ve(e,t={}){let n=k(),r={getToken:()=>n.getToken?.()??null,setToken:e=>n.setToken?.(e),logout:()=>n.logout?.(),errorsHandlers:{default:({error:e,reject:t})=>{console.error(`Erreur API (cresol):`,e),t(e)},401:({error:e,overlayConfig:t,reject:r})=>{t.allowRedirect&&n.goToLoginPage?.(),r(e)},498:({error:e,overlayConfig:t,reject:r})=>{t.allowRedirect&&n.goToLoginPage?.(),r(e)}}};return t.functions={...r,...t.functions??{}},t.functions.errorsHandlers={...r.errorsHandlers,...t.functions.errorsHandlers??{}},(0,o.default)(e,t)}var ye=(e,t)=>{let n=t||k().baseUrl;if(!n)throw Error(`Cresol : baseUrl non renseignée (configureCresol ou prop baseUrl)`);return`${n}${e}`},be=(e={})=>{let t=new URLSearchParams;Object.entries(e).forEach(([e,n])=>{n!=null&&n!==``&&t.append(e,typeof n==`object`?JSON.stringify(n):n)});let n=t.toString();return n?`?${n}`:``},xe=(e={},t)=>t?{...e,functions:{...e.functions??{},getToken:()=>t}}:e,A=({method:e,path:t,params:n,data:r,signal:i,token:a,baseUrl:o},s={})=>ve({url:ye(`${t}${be(n)}`,o),method:e,...r===void 0?{}:{data:r},...i?{signal:i}:{}},xe(s,a)),j=(e,{params:t,signal:n,overlay:r,token:i,baseUrl:a}={})=>A({method:`GET`,path:e,params:t,signal:n,token:i,baseUrl:a},r).then(e=>e.data),M=(e,t,{params:n,signal:r,overlay:i,token:a,baseUrl:o}={})=>A({method:`POST`,path:e,params:n,data:t,signal:r,token:a,baseUrl:o},i).then(e=>e.data),Se={mustBeAuthenticated:!1},N=(e,{signal:t,token:n,baseUrl:r}={})=>j(e,{signal:t,token:n,baseUrl:r,overlay:Se}),Ce=e=>N(`/v2/sollicitation/motifs`,e),we=e=>N(`/v2/sollicitation/categories`,e),Te=e=>N(`/v2/sollicitation/types`,e),Ee=e=>N(`/v2/sollicitation/natures`,e),De=e=>N(`/v2/sollicitation/etats`,e),Oe=({signal:e,token:t,baseUrl:n}={})=>j(`/collaborateurs`,{params:{actif:!0},signal:e,token:t,baseUrl:n}),ke=async({signal:e,token:t,baseUrl:n}={})=>(await j(`/v2/patrimoine/communes`,{signal:e,token:t,baseUrl:n})??[]).map(e=>({idCommune:e.id,commune:e.libelle})),Ae=(e,{signal:t,token:n,baseUrl:r}={})=>j(`/v2/patrimoine/entrees`,{params:{idCommune:e},signal:t,token:n,baseUrl:r}),je=(e,{signal:t,token:n,baseUrl:r}={})=>j(`/v2/patrimoine/modules`,{params:{codeProgramme:e},signal:t,token:n,baseUrl:r}),Me=({idContrat:e,typeContrat:t},{signal:n,token:r,baseUrl:i}={})=>j(`/v2/patrimoine/contrat_modules`,{params:{idContrat:e,typeContrat:t},signal:n,token:r,baseUrl:i}),Ne=({motif:e,categorie:t,type:n,nature:r},{signal:i,token:a,baseUrl:o}={})=>j(`/v2/sollicitation/responsables`,{params:{motif:e,categorie:t,type:n,nature:r},signal:i,token:a,baseUrl:o}),Pe=(e,{signal:t,token:n,baseUrl:r}={})=>j(`/v2/patrimoine/contrat_module_rechercher`,{params:{recherche:e},signal:t,token:n,baseUrl:r}),Fe=({categorie:e,recherche:t},{signal:n,token:r,baseUrl:i}={})=>j(`/v2/cresol/reclamant_rechercher`,{params:{categorie:e,recherche:t},signal:n,token:r,baseUrl:i});function P(e){let t=e?.response?.data;return t?.error?t.error:t?.errorList?t.errorList.map(e=>e.message).join(`, `):e?.response?.status===500?`Erreur interne`:e?.response?.status===401?`Non autorisé à faire cette action`:`Erreur`}var F=e=>e?.name===`AbortError`||e?.name===`CanceledError`,I=Symbol(`cresol:data`),Ie=()=>({motifs:null,categories:null,types:null,natures:null,etats:null,collaborateurs:null,communes:null,adressesByCommune:{},modulesByProgramme:{},modulesByContrat:{},responsablesByMotif:{}}),L=new Map,Le=e=>(L.has(e)||L.set(e,(0,n.reactive)(Ie())),L.get(e)),R=new Map;function Re(){L.clear(),R.clear()}var z=(e,t,n)=>e?.find(e=>e[t]===n)?.libelle??n,B=(e,t,n)=>e?.find(e=>e[t]===n)?.icon??null;function ze({onError:e,token:t,baseUrl:r}={}){let i=(0,n.ref)(0),a=()=>({token:(0,n.unref)(t)||null,baseUrl:(0,n.unref)(r)||null}),o=()=>(0,n.unref)(r)||k().baseUrl||``,s=()=>Le(o()),c=(t,n)=>{let r=`${o()}|${t}`;if(R.has(r))return R.get(r);i.value+=1;let a=Promise.resolve().then(n).catch(t=>(F(t)||e?.(P(t)),null)).finally(()=>{--i.value,R.delete(r)});return R.set(r,a),a},l=(e,t)=>s()[e]?.length?Promise.resolve(s()[e]):c(`referentiel:${e}`,async()=>(s()[e]=await t(a()),s()[e])),u={get cache(){return s()},loading:i,isLoading:(0,n.computed)(()=>i.value>0),loadNomenclature(){return Promise.all([l(`motifs`,Ce),l(`categories`,we),l(`types`,Te),l(`natures`,Ee),l(`etats`,De)])},loadCollaborateurs:()=>l(`collaborateurs`,Oe),loadCommunes(){return s().communes?.length?Promise.resolve(s().communes):c(`communes`,async()=>(s().communes=await ke(a()),s().communes))},loadAdresses(e){return e==null?Promise.resolve([]):s().adressesByCommune[e]?Promise.resolve(s().adressesByCommune[e]):c(`adresses:${e}`,async()=>{let t=await Ae(e,a());return s().adressesByCommune[e]=t??[],t})},loadModulesOfProgramme(e){return e==null?Promise.resolve([]):s().modulesByProgramme[e]?Promise.resolve(s().modulesByProgramme[e]):c(`modules:${e}`,async()=>{let t=await je(e,a());return s().modulesByProgramme[e]=t??[],t})},loadModulesOfContrat({idContrat:e,typeContrat:t}){if(e==null)return Promise.resolve([]);let n=`${t??``}|${e}`;return s().modulesByContrat[n]?Promise.resolve(s().modulesByContrat[n]):c(`contratModules:${n}`,async()=>{let r=await Me({idContrat:e,typeContrat:t},a());return s().modulesByContrat[n]=r??[],r})},async searchContrats(e,{signal:t}={}){let n=(e??``).trim();if(!n)return[];let r=await Pe(n,{...a(),signal:t}),i=new Map;for(let e of r??[]){let t=`${e.typeContrat}|${e.idContrat}`;i.has(t)||i.set(t,{typeContrat:e.typeContrat,idContrat:e.idContrat,libelle:e.libelle??null,estSorti:!!e.estContratSorti,nbModules:e.nbModulesContrat??1})}return[...i.values()].sort((e,t)=>Number(e.estSorti)-Number(t.estSorti)||(e.libelle??``).localeCompare(t.libelle??``))},async searchReclamants(e,t,{signal:n}={}){let r=(t??``).trim();if(!r)return[];let i=await Fe({categorie:e,recherche:r},{...a(),signal:n}),o=new Map;for(let t of i??[]){let n=`${t.typeReclamant}|${t.idReclamant}`;o.has(n)||o.set(n,{type:t.typeReclamant,id:t.idReclamant,categorie:t.categorie?.toLowerCase()??e,libelleReclamant:t.libelleReclamant,adresse:t.adresse,estActif:!1,individus:[]});let r=o.get(n);r.estActif||=!!t.estActif,r.individus.push(t)}return[...o.values()].sort((e,t)=>Number(t.estActif)-Number(e.estActif)).map(e=>{let t=e.individus.map(e=>[e.nom,e.prenom].filter(Boolean).join(` `)).filter(Boolean).join(`, `),n={locataire:`${e.libelleReclamant||t} — Contrat ${e.type}/${e.id}`,demandeur:`${t} — ${e.libelleReclamant}`}[e.categorie];return{...e,libelle:n??e.libelleReclamant}})},loadResponsables({motif:e,categorie:t,type:n,nature:r}){return e==null?Promise.resolve([]):s().responsablesByMotif[e]?Promise.resolve(s().responsablesByMotif[e]):c(`responsables:${e}`,async()=>{let i=await Ne({motif:e,categorie:t,type:n,nature:r},a());return s().responsablesByMotif[e]=i??[],i})},adressesOfCommune:e=>s().adressesByCommune[e]??null,modulesOfProgramme:e=>s().modulesByProgramme[e]??null,modulesOfContrat:({idContrat:e,typeContrat:t})=>s().modulesByContrat[`${t??``}|${e}`]??null,allAdresses:()=>Object.values(s().adressesByCommune).flat(),getResponsableSuggere({idMotif:e,codeProgramme:t,codeTranche:n,codeBatiment:r,codeEscalier:i}){let a=s().responsablesByMotif[e];if(!a?.length||t==null)return null;let o=a.filter(e=>String(e.codeProgramme)===String(t)&&(e.codeTranche==null||e.codeTranche===n)&&(e.codeBatiment==null||e.codeBatiment===r)&&(e.codeEscalier==null||e.codeEscalier===i));if(!o.length)return null;let c=e=>(e.codeEscalier==null?0:4)+(e.codeBatiment==null?0:2)+(e.codeTranche==null?0:1),l=o.reduce((e,t)=>c(t)>c(e)?t:e);return{idResponsable:l.idResponsable,libelle:l.libelleResponsable}},motifLibelle:e=>z(s().motifs,`id`,e),categorieLibelle:e=>z(s().categories,`id`,e),typeLibelle:e=>z(s().types,`id`,e),natureLibelle:e=>z(s().natures,`id`,e),etatLibelle:e=>z(s().etats,`code`,e),motifIcon:e=>B(s().motifs,`id`,e),categorieIcon:e=>B(s().categories,`id`,e),typeIcon:e=>B(s().types,`id`,e),natureIcon:e=>B(s().natures,`id`,e)};return(0,n.reactive)(u)}function Be(e){return(0,n.provide)(I,e),e}function V(){let e=(0,n.inject)(I,null);if(!e)throw Error(`useCresolData() hors de <creer-sollicitation-form>`);return e}var Ve=e=>`fa`+e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);async function H(e){let t=await import(`@fortawesome/free-solid-svg-icons`);[...new Set(e.filter(Boolean))].forEach(e=>{let n=t[Ve(e)];n&&c.library.add(n)})}var U=[{key:`locataire`,label:`Locataire`,icon:`house-user`,recherche:`Rechercher un locataire`,aucun:`Aucun locataire trouvé.`,placeholder:`Nom, prénom, n° de contrat, adresse, téléphone ou mail…`},{key:`demandeur`,label:`Demandeur`,icon:`hourglass-half`,recherche:`Rechercher un demandeur`,aucun:`Aucun demandeur trouvé.`,placeholder:`Nom, prénom, n° de demande ou unique, téléphone ou mail…`},{key:`tiers`,label:`Tiers`,icon:`user-tie`,recherche:`Rechercher un tiers`,aucun:`Aucun tiers trouvé.`,placeholder:`Raison sociale, adresse, téléphone ou mail…`},{key:`autre`,label:`Autre`,icon:`user`,recherche:`Rechercher un individu « Autre »`,aucun:`Aucun individu « Autre » trouvé.`,placeholder:`Nom, prénom, adresse, téléphone ou mail…`},{key:`tout`,label:`Tout`,icon:`magnifying-glass`,recherche:`Rechercher parmi tous les réclamants`,aucun:`Aucun réclamant trouvé.`,placeholder:`Nom, prénom, n° de contrat ou de demande, adresse, téléphone ou mail…`}],W={signataire:`Signataire`,occupant:`Occupant`,demandeur:`Demandeur`},G=e=>e?e.categorie?e.categorie:{D:`demandeur`,T:`tiers`,U:`autre`}[e.type]??`locataire`:null,He={name:`ReclamantRechercheBlock`,components:{AmsomAutocomplete:a.AmsomAutocomplete},setup(){return{draft:E(),data:V()}},data(){return{iconsReady:!1,categorie:G(this.draft.reclamantSelectionne)??`locataire`,trouves:[],rechercheEnCours:!1,rechercheFaite:!1}},computed:{categories(){return U},categorieCourante(){return U.find(e=>e.key===this.categorie)},selectionne(){return this.draft.reclamantSelectionne},selectedTrouve:{get(){return this.categorie===`tout`||G(this.selectionne)===this.categorie?this.selectionne:null},set(e){this.select(e)}}},async created(){await H(U.map(e=>e.icon)),this.iconsReady=!0},beforeUnmount(){clearTimeout(this.rechercheTimeout),this.controller?.abort()},methods:{select(e){e&&(this.draft.selectReclamant(e),this.categorie!==`tout`&&(this.categorie=G(e)))},setCategorie(e){e!==this.categorie&&(this.categorie=e,clearTimeout(this.rechercheTimeout),this.controller?.abort(),this.trouves=[],this.rechercheEnCours=!1,this.rechercheFaite=!1)},rechercherPlusTard(e){clearTimeout(this.rechercheTimeout),this.rechercheTimeout=setTimeout(()=>this.rechercher(e),400)},rechercher(e){let t=(e??``).trim();t.length<2?(this.trouves=[],this.rechercheEnCours=!1,this.rechercheFaite=!1):(this.controller?.abort(),this.controller=new AbortController,this.rechercheEnCours=!0,this.data.searchReclamants(this.categorie,t,{signal:this.controller.signal}).then(e=>{this.trouves=e??[],this.rechercheFaite=!0,this.rechercheEnCours=!1}).catch(()=>{this.rechercheEnCours=!1}))},cleReclamant(e){return e?`${e.type}|${e.id}`:null},categorieOf:G,iconOf(e){return U.find(t=>t.key===G(e))?.icon??`user`},nomsOf(e){return(e?.individus??[]).map(e=>[e.nom,e.prenom].filter(Boolean).join(` `)).filter(Boolean).join(`, `)},titreOf(e){if(!e?.individus)return e?.libelle??``;let t=G(e);return t===`locataire`?e.libelleReclamant||this.nomsOf(e):t===`demandeur`?this.nomsOf(e):e.libelleReclamant},referenceOf(e){if(!e?.individus)return``;let t=G(e);return t===`locataire`?`Contrat ${e.type}/${e.id}`:t===`demandeur`?e.libelleReclamant:t===`autre`?`Individu « Autre »`:`Tiers`},detailOf(e){let t=e?.individus??[];if([`tiers`,`autre`].includes(G(e))){let e=t[0];return e?[e.telephone,e.mail].filter(Boolean).join(` — `):``}return t.map(e=>{let t=[e.nom,e.prenom].filter(Boolean).join(` `);return W[e.role]?`${t} (${W[e.role].toLowerCase()})`:t}).join(`, `)}}},Ue={key:0,class:`d-flex flex-column gap-3`},We={class:`d-flex flex-wrap gap-2`},Ge=[`onClick`],Ke={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},qe={class:`min-w-0`},Je={key:0,class:`badge bg-warning-subtle text-warning-emphasis ms-1`},Ye={class:`text-muted d-block text-truncate`},Xe={key:0},Ze={key:0,class:`text-muted d-block text-truncate`},Qe={key:0,class:`text-muted`},$e={key:0,class:`alert alert-primary py-2 px-3 mb-0 fs-7 d-flex align-items-start gap-2`},et={class:`min-w-0`},tt={class:`fw-semibold`},nt={key:0,class:`text-truncate`},rt={key:1,class:`text-truncate`},it={key:1,class:`fs-7 text-danger`};function at(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`font-awesome-icon`),c=(0,n.resolveComponent)(`amsom-autocomplete`);return a.iconsReady?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Ue,[(0,n.createElementVNode)(`div`,null,[t[1]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Le réclamant est… `,-1),(0,n.createElementVNode)(`div`,We,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.categories,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.key,type:`button`,class:(0,n.normalizeClass)([`btn btn-sm d-inline-flex align-items-center gap-2`,a.categorie===e.key?`btn-primary`:`btn-outline-primary`]),onClick:t=>o.setCategorie(e.key)},[(0,n.createVNode)(s,{icon:e.icon,"fixed-width":``},null,8,[`icon`]),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.label),1)],10,Ge))),128))])]),(0,n.createElementVNode)(`div`,null,[(0,n.createElementVNode)(`label`,Ke,(0,n.toDisplayString)(o.categorieCourante.recherche),1),((0,n.openBlock)(),(0,n.createBlock)(c,{key:a.categorie,modelValue:o.selectedTrouve,"onUpdate:modelValue":t[0]||=e=>o.selectedTrouve=e,items:a.trouves,"filtering-function":({items:e})=>e,loading:a.rechercheEnCours,"get-id":o.cleReclamant,"get-input-libelle":e=>e?.libelle??``,placeholder:o.categorieCourante.placeholder,"input-size":`sm`,"hide-choices":``,"debounce-delay":0,onSearch:o.rechercherPlusTard},{options:(0,n.withCtx)(e=>[(0,n.createElementVNode)(`div`,qe,[(0,n.createElementVNode)(`div`,{class:(0,n.normalizeClass)([`fw-medium text-truncate`,e?.estActif?``:`text-muted`])},[(0,n.createTextVNode)((0,n.toDisplayString)(o.titreOf(e))+` `,1),e?.estActif?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`span`,Je,(0,n.toDisplayString)(o.categorieOf(e)===`demandeur`?`inactive`:`sorti`),1))],2),(0,n.createElementVNode)(`small`,Ye,[(0,n.createTextVNode)((0,n.toDisplayString)(o.referenceOf(e))+` `,1),e?.adresse?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,Xe,` — `+(0,n.toDisplayString)(e.adresse),1)):(0,n.createCommentVNode)(``,!0)]),o.detailOf(e)?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,Ze,(0,n.toDisplayString)(o.detailOf(e)),1)):(0,n.createCommentVNode)(``,!0)])]),_:1},8,[`modelValue`,`items`,`filtering-function`,`loading`,`get-id`,`get-input-libelle`,`placeholder`,`onSearch`])),a.rechercheFaite&&!a.rechercheEnCours&&!a.trouves.length?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,Qe,(0,n.toDisplayString)(o.categorieCourante.aucun),1)):(0,n.createCommentVNode)(``,!0)]),o.selectionne?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,$e,[(0,n.createVNode)(s,{icon:o.iconOf(o.selectionne),class:`mt-1`},null,8,[`icon`]),(0,n.createElementVNode)(`div`,et,[(0,n.createElementVNode)(`div`,tt,(0,n.toDisplayString)(o.selectionne.libelle),1),o.selectionne.adresse?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,nt,(0,n.toDisplayString)(o.selectionne.adresse),1)):(0,n.createCommentVNode)(``,!0),o.detailOf(o.selectionne)?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,rt,(0,n.toDisplayString)(o.detailOf(o.selectionne)),1)):(0,n.createCommentVNode)(``,!0)])])):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,it,`Recherchez puis sélectionnez le réclamant.`))])):(0,n.createCommentVNode)(``,!0)}var ot=D(He,[[`render`,at]]),st={name:`ProvenanceSelecteurBlock`,setup(){return{draft:E()}},computed:{provenances(){return y},selected(){return this.draft.draft.provenance},provenanceChoisie(){return this.provenances.find(e=>e.id===this.selected)??null}}},ct={key:0,class:`fs-7 text-muted`},lt={class:`fw-medium`},ut={key:1},dt={class:`d-flex flex-wrap gap-2`},ft=[`onClick`],pt={key:0,class:`fs-7 text-danger mt-1`};function mt(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`font-awesome-icon`);return i.draft.isReadonly(`provenance`)?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ct,[t[0]||=(0,n.createTextVNode)(` Provenance du contact : `,-1),(0,n.createElementVNode)(`span`,lt,[o.provenanceChoisie?.icon?((0,n.openBlock)(),(0,n.createBlock)(s,{key:0,icon:o.provenanceChoisie.icon,"fixed-width":``},null,8,[`icon`])):(0,n.createCommentVNode)(``,!0),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(o.provenanceChoisie?.libelle??`—`),1)])])):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ut,[t[1]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},[(0,n.createTextVNode)(` Provenance du contact `),(0,n.createElementVNode)(`span`,{class:`text-danger`},`*`)],-1),(0,n.createElementVNode)(`div`,dt,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.provenances,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.id,type:`button`,class:(0,n.normalizeClass)([`btn btn-sm d-inline-flex align-items-center gap-2`,e.id===o.selected?`btn-primary`:`btn-outline-primary`]),onClick:t=>i.draft.setProvenance(e.id)},[(0,n.createVNode)(s,{icon:e.icon,"fixed-width":``},null,8,[`icon`]),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.libelle),1)],10,ft))),128))]),o.selected?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,pt,` Sélectionnez par quel canal la sollicitation vous est parvenue. `))]))}var K=D(st,[[`render`,mt]]),ht={name:`EtapeReclamantBlock`,components:{ReclamantRechercheBlock:ot,ProvenanceSelecteurBlock:K},props:{premiere:{type:Boolean,default:!1}},setup(){return{draft:E()}}},gt={class:`d-flex flex-column gap-3`},_t={class:`alert alert-light border py-2 px-3 mb-0 fs-7`};function vt(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`provenance-selecteur-block`),c=(0,n.resolveComponent)(`font-awesome-icon`),l=(0,n.resolveComponent)(`reclamant-recherche-block`);return(0,n.openBlock)(),(0,n.createElementBlock)(`div`,gt,[r.premiere?((0,n.openBlock)(),(0,n.createBlock)(s,{key:0})):(0,n.createCommentVNode)(``,!0),(0,n.renderSlot)(e.$slots,`reclamant`,{reclamant:i.draft.reclamantSelectionne,select:i.draft.selectReclamant},()=>[(0,n.createElementVNode)(`div`,_t,[(0,n.createVNode)(c,{icon:`user`,class:`text-primary me-2`}),t[0]||=(0,n.createTextVNode)(` Pour qui cette sollicitation est-elle créée\xA0? `,-1)]),(0,n.createVNode)(l)])])}var yt=D(ht,[[`render`,vt]]),q=Symbol(`cresol:options`),bt=e=>(0,n.provide)(q,e),J=()=>(0,n.inject)(q,{});function Y(e,t=!0){if(!e)return null;let n=e.toString().normalize(`NFD`).replace(/[̀-ͯ]/g,``);return t?n.toLowerCase():n}var xt={name:`ReclamantSelecteurBlock`,components:{AmsomAutocomplete:a.AmsomAutocomplete},props:{mode:{type:String,default:null},inline:{type:Boolean,default:!0}},setup(){return{draft:E(),options:J()}},computed:{reclamants(){return this.draft.reclamantsDisponibles},reclamantSelectionne(){return this.draft.reclamantSelectionne},presentation(){return this.mode??this.options.reclamantMode},estFige(){return this.reclamants.length<=1||this.draft.isReadonly(`reclamant`)}},methods:{reclamantId(e){let t=this.reclamants.indexOf(e);return t<0?null:t},select(e){this.draft.selectReclamant(e)},filterReclamants({search:e,items:t}){let n=(Y(e)??``).trim();return n?t.filter(e=>(Y(e?.libelle)??``).includes(n)):t}}},St={key:0,class:`fs-7 text-muted`},Ct={class:`fw-medium`},wt={key:0,class:`btn-group btn-group-sm`,role:`group`},Tt=[`onClick`],Et=[`value`],Dt=[`value`];function Ot(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`amsom-autocomplete`);return o.estFige?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,St,[t[2]||=(0,n.createTextVNode)(` Réclamant : `,-1),(0,n.createElementVNode)(`span`,Ct,(0,n.toDisplayString)(o.reclamantSelectionne?.libelle),1)])):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:1,class:(0,n.normalizeClass)(r.inline?`d-flex align-items-center justify-content-between gap-2 border-bottom pb-2`:`d-flex flex-column gap-1`)},[t[3]||=(0,n.createElementVNode)(`span`,{class:`fs-7 fw-semibold text-muted text-uppercase`},`Réclamant`,-1),o.presentation===`switch`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,wt,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.reclamants,(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:t,type:`button`,class:(0,n.normalizeClass)([`btn btn-sm py-0`,e===o.reclamantSelectionne?`btn-primary`:`btn-outline-primary`]),onClick:t=>o.select(e)},(0,n.toDisplayString)(e.libelle),11,Tt))),128))])):o.presentation===`autocomplete`?((0,n.openBlock)(),(0,n.createBlock)(s,{key:1,"model-value":o.reclamantSelectionne,items:o.reclamants,"get-id":o.reclamantId,"get-input-libelle":e=>e?.libelle??``,"filtering-function":o.filterReclamants,placeholder:`Rechercher un réclamant…`,"input-size":`sm`,"hide-choices":``,class:(0,n.normalizeClass)(r.inline?``:`w-100`),"onUpdate:modelValue":t[0]||=e=>o.select(e)},null,8,[`model-value`,`items`,`get-id`,`get-input-libelle`,`filtering-function`,`class`])):((0,n.openBlock)(),(0,n.createElementBlock)(`select`,{key:2,class:(0,n.normalizeClass)([`form-select form-select-sm`,r.inline?`w-auto`:``]),value:o.reclamants.indexOf(o.reclamantSelectionne),onChange:t[1]||=e=>o.select(o.reclamants[e.target.value])},[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.reclamants,(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`option`,{key:t,value:t},(0,n.toDisplayString)(e.libelle),9,Dt))),128))],42,Et))],2))}var kt=D(xt,[[`render`,Ot]]),At={name:`EtapeCategorieBlock`,components:{AmsomOverlay:t.AmsomOverlay,AmsomAutocomplete:a.AmsomAutocomplete,ReclamantSelecteurBlock:kt,ProvenanceSelecteurBlock:K},props:{premiere:{type:Boolean,default:!1}},setup(){return{draft:E(),data:V(),options:J()}},data(){return{iconsReady:!1}},computed:{mainLigne(){return this.draft.lignePrincipale},motifFige(){return this.draft.isReadonly(`motif`)},activeMotifs(){return(this.data.cache.motifs??[]).filter(e=>!e.estDesactive).slice().sort((e,t)=>(e.categorie??``).localeCompare(t.categorie??``)||(e.type??``).localeCompare(t.type??``)||(e.nature??``).localeCompare(t.nature??``)||(e.libelle??``).localeCompare(t.libelle??``))},allowedMotifs(){let e=this.options.nomenclatureFilter;if(typeof e!=`function`)return this.activeMotifs;let t=this.draft.reclamantSelectionne;return this.activeMotifs.filter(n=>e(n,{reclamant:t}))},categoriesList(){return this.distinct(this.allowedMotifs,`idCategorie`,`categorie`,e=>this.data.categorieIcon(e))},typesList(){return this.mainLigne.idCategorie?this.distinct(this.allowedMotifs.filter(e=>e.idCategorie===this.mainLigne.idCategorie),`idType`,`type`,e=>this.data.typeIcon(e)):[]},naturesList(){return this.mainLigne.idType?this.distinct(this.allowedMotifs.filter(e=>e.idType===this.mainLigne.idType),`idNature`,`nature`,e=>this.data.natureIcon(e)):[]},motifsList(){return this.mainLigne.idNature?this.allowedMotifs.filter(e=>e.idNature===this.mainLigne.idNature).map(e=>({id:e.id,libelle:e.libelle,icon:e.icon})):[]},selectedMotif(){return this.mainLigne.idMotif?this.activeMotifs.find(e=>e.id===this.mainLigne.idMotif)??null:null},motifsAssocies(){let e=this.selectedMotif?.association;return e?Object.entries(e).map(([e,t])=>({libelle:e,idMotif:t})):[]},selectionChain(){let e=[];return this.mainLigne.idCategorie&&e.push({level:`categorie`,libelle:this.data.categorieLibelle(this.mainLigne.idCategorie),icon:this.data.categorieIcon(this.mainLigne.idCategorie)}),this.mainLigne.idType&&e.push({level:`type`,libelle:this.data.typeLibelle(this.mainLigne.idType),icon:this.data.typeIcon(this.mainLigne.idType)}),this.mainLigne.idNature&&e.push({level:`nature`,libelle:this.data.natureLibelle(this.mainLigne.idNature),icon:this.data.natureIcon(this.mainLigne.idNature)}),this.mainLigne.idMotif&&e.push({level:`motif`,libelle:this.data.motifLibelle(this.mainLigne.idMotif),icon:this.data.motifIcon(this.mainLigne.idMotif)}),e},currentLevel(){return this.mainLigne.idCategorie?this.mainLigne.idType?this.mainLigne.idNature?this.mainLigne.idMotif?null:{title:`Motif`,options:this.motifsList,select:e=>this.draft.setMotif(e)}:{title:`Nature`,options:this.naturesList,select:e=>this.draft.setNature(e)}:{title:`Type`,options:this.typesList,select:e=>this.draft.setType(e)}:{title:`Catégorie`,options:this.categoriesList,select:e=>this.draft.setCategorie(e)}},motifRecherche:{get(){return this.selectedMotif},set(e){let t=e&&typeof e==`object`?e:e?this.activeMotifs.find(t=>t.id===e):null;t?this.draft.selectMotifChain(t):this.draft.setCategorie(null)}}},async created(){await this.data.loadNomenclature(),await this.registerIcons(),this.iconsReady=!0},methods:{goBackTo(e){e===`categorie`?this.draft.setCategorie(null):e===`type`?this.draft.setType(null):e===`nature`?this.draft.setNature(null):e===`motif`&&this.draft.setMotif(null)},isActive(e){return this.draft.lignesAssociees.some(t=>t.idMotif===e)},toggleMotifAssocie(e){let t=this.activeMotifs.find(t=>t.id===e.idMotif);this.draft.toggleLigneAssociee(e.idMotif,{libelle:e.libelle,idCategorie:t?.idCategorie??null,idType:t?.idType??null,idNature:t?.idNature??null})},registerIcons(){return H([...this.data.cache.categories??[],...this.data.cache.types??[],...this.data.cache.natures??[],...this.activeMotifs].map(e=>e.icon))},filterMotifs({search:e,items:t}){let n=(Y(e)??``).trim();if(!n)return t;let r=n.split(/\s+/);return t.filter(e=>{let t=Y(`${e.libelle} ${e.categorie} ${e.type} ${e.nature}`)??``;return r.every(e=>t.includes(e))})},getMotifId(e){return e?e.id:null},getMotifInputLibelle(e){return e?e.libelle:``},distinct(e,t,n,r){let i=new Map;for(let a of e)a[t]!=null&&!i.has(a[t])&&i.set(a[t],{id:a[t],libelle:a[n]??a[t],icon:r?r(a[t]):null});return[...i.values()].sort((e,t)=>(e.libelle??``).localeCompare(t.libelle??``))},motifLibelleFromId(e){return this.activeMotifs.find(t=>t.id===e)?.libelle??e}}},jt={key:0,class:`d-flex flex-column gap-3`},Mt={key:2},Nt={class:`d-flex flex-wrap align-items-center gap-2`},Pt={class:`badge rounded-pill bg-primary d-inline-flex align-items-center gap-2`},Ft={key:3},It={class:`d-flex align-items-center gap-2`},Lt={class:`min-w-0`},Rt={class:`fw-medium text-truncate`},zt={class:`text-muted d-block text-truncate`},Bt={key:4,class:`d-flex align-items-center gap-2 text-muted fs-7`},Vt={key:5,class:`d-flex flex-wrap align-items-center gap-2`},Ht=[`onClick`],Ut={key:6},Wt={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-2`},Gt={class:`row justify-content-around g-3`},Kt=[`title`,`onClick`],qt={class:`fs-7 mt-1 lh-sm`},Jt={key:0,class:`col-12 text-muted fs-7`},Yt=[`id`,`checked`,`disabled`,`onChange`],Xt=[`for`];function Zt(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`provenance-selecteur-block`),c=(0,n.resolveComponent)(`reclamant-selecteur-block`),l=(0,n.resolveComponent)(`font-awesome-icon`),u=(0,n.resolveComponent)(`amsom-autocomplete`),d=(0,n.resolveComponent)(`amsom-overlay`);return(0,n.openBlock)(),(0,n.createBlock)(d,{loading:i.data.isLoading&&!i.data.cache.motifs||!a.iconsReady},{default:(0,n.withCtx)(()=>[a.iconsReady?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,jt,[r.premiere?((0,n.openBlock)(),(0,n.createBlock)(s,{key:0})):(0,n.createCommentVNode)(``,!0),i.options.reclamantMode===`step`?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createBlock)(c,{key:1})),o.motifFige&&o.selectionChain.length?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Mt,[t[1]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Motif`,-1),(0,n.createElementVNode)(`div`,Nt,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.selectionChain,(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:e.level},[t>0?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,icon:`fa-solid fa-chevron-right`,class:`text-muted fs-7`})):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,Pt,[e.icon?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,icon:e.icon,"fixed-width":``},null,8,[`icon`])):(0,n.createCommentVNode)(``,!0),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(e.libelle),1)])],64))),128))])])):(0,n.createCommentVNode)(``,!0),o.motifFige?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Ft,[t[2]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Rechercher un motif `,-1),(0,n.createVNode)(u,{modelValue:o.motifRecherche,"onUpdate:modelValue":t[0]||=e=>o.motifRecherche=e,items:o.allowedMotifs,"get-id":o.getMotifId,"get-input-libelle":o.getMotifInputLibelle,"get-input-libelle-from-id":o.motifLibelleFromId,"filtering-function":o.filterMotifs,placeholder:`Rechercher (motif, catégorie, type, nature)…`,"input-size":`sm`,"hide-choices":``},{options:(0,n.withCtx)(e=>[(0,n.createElementVNode)(`div`,It,[e?.icon?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,icon:e.icon,class:`text-primary`,"fixed-width":``},null,8,[`icon`])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,Lt,[(0,n.createElementVNode)(`div`,Rt,(0,n.toDisplayString)(e?.libelle),1),(0,n.createElementVNode)(`small`,zt,(0,n.toDisplayString)(e?.categorie)+` › `+(0,n.toDisplayString)(e?.type)+` › `+(0,n.toDisplayString)(e?.nature),1)])])]),_:1},8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`get-input-libelle-from-id`,`filtering-function`])])),o.motifFige?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Bt,[...t[3]||=[(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`},null,-1),(0,n.createElementVNode)(`span`,null,`ou sélection guidée`,-1),(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`},null,-1)]])),!o.motifFige&&o.selectionChain.length?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Vt,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.selectionChain,(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:e.level},[t>0?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,icon:`fa-solid fa-chevron-right`,class:`text-muted fs-7`})):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`button`,{type:`button`,class:`btn btn-sm btn-primary rounded-pill d-inline-flex align-items-center gap-2`,onClick:t=>o.goBackTo(e.level)},[e.icon?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,icon:e.icon,"fixed-width":``},null,8,[`icon`])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.libelle),1),(0,n.createVNode)(l,{icon:`fa-solid fa-xmark`,class:`fs-7 opacity-75`})],8,Ht)],64))),128))])):(0,n.createCommentVNode)(``,!0),!o.motifFige&&o.currentLevel?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Ut,[(0,n.createElementVNode)(`label`,Wt,(0,n.toDisplayString)(o.currentLevel.title),1),(0,n.createElementVNode)(`div`,Gt,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.currentLevel.options,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:e.id,class:`col-3 text-center`},[(0,n.createElementVNode)(`button`,{type:`button`,class:`btn btn-lg btn-outline-primary btn-circle d-flex align-items-center justify-content-center mx-auto`,title:e.libelle,onClick:t=>o.currentLevel.select(e.id)},[e.icon?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,icon:e.icon,size:`lg`},null,8,[`icon`])):(0,n.createCommentVNode)(``,!0)],8,Kt),(0,n.createElementVNode)(`div`,qt,(0,n.toDisplayString)(e.libelle),1)]))),128)),o.currentLevel.options.length?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Jt,` Aucun choix disponible `))])])):(0,n.createCommentVNode)(``,!0),o.motifsAssocies.length?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:7},[t[4]||=(0,n.createElementVNode)(`div`,{class:`d-flex align-items-center gap-2 text-muted fs-7`},[(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`}),(0,n.createElementVNode)(`span`,null,`Autres motifs liés`),(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`})],-1),((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.motifsAssocies,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:e.idMotif,class:`form-check form-switch`},[(0,n.createElementVNode)(`input`,{id:`assoc-${e.idMotif}`,class:`form-check-input`,type:`checkbox`,checked:o.isActive(e.idMotif),disabled:o.motifFige,onChange:t=>o.toggleMotifAssocie(e)},null,40,Yt),(0,n.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`assoc-${e.idMotif}`},(0,n.toDisplayString)(e.libelle)+` ? `,9,Xt)]))),128))],64)):(0,n.createCommentVNode)(``,!0)])):(0,n.createCommentVNode)(``,!0)]),_:1},8,[`loading`])}var Qt=D(At,[[`render`,Zt]]),$t={B:`briefcase`,M:`store`,W:`dungeon`,E:`user-graduate`,K:`building-shield`,F:`person-shelter`,S:`square-parking`,V:`hands-holding`};function en(e,t=!1,n=`circle-question`){return e===`L`?t?`building`:`house`:$t[e]??n}function tn(e){return e?e.idCategorieModule===`L`?e.estCollectif?`Appartement`:`Maison`:e.categorieModule??``:``}var nn=0,rn={name:`CiblePickerBlock`,components:{AmsomAutocomplete:a.AmsomAutocomplete},props:{patrimoine:{type:Object,default:null},cibleMode:{type:String,default:`contrat`},reclamantModules:{type:Array,default:()=>[]},reclamantType:{type:String,default:null},contratReclamant:{type:Boolean,default:!0},contratCible:{type:Object,default:null},afficheCaseContratReclamant:{type:Boolean,default:!1},locataireActuelOption:{type:Object,default:null}},emits:[`change-mode`,`select-commune`,`select-adresse`,`select-etage`,`select-module`,`select-contrat`,`toggle-contrat-reclamant`,`toggle-reprendre-locataire-actuel`],setup(){return{data:V()}},data(){return{uid:++nn,rechercheContrat:``,contratsTrouves:[],rechercheEnCours:!1,rechercheFaite:!1}},computed:{availableModes(){return this.reclamantType===`D`?[{key:`demande`,label:`La demande`,icon:`hourglass`,aide:`Cible la demande elle-même (sans localisation).`}]:[{key:`contrat`,label:`Un contrat`,icon:`file-signature`,aide:`Cible un contrat et l’un de ses modules.`},{key:`patrimoine`,label:`Du patrimoine`,icon:`building`,aide:`Une adresse seule pour une partie commune, un module pour un logement précis.`}]},currentMode(){return this.availableModes.find(e=>e.key===this.cibleMode)},contratModules(){return this.contratReclamant?this.reclamantModules:this.contratCible?this.data.modulesOfContrat(this.contratCible)??[]:[]},areModulesLocked(){return this.cibleMode===`contrat`?this.contratModules.length<=1:!this.patrimoine?.idEntree},adresses(){let e=this.patrimoine?.idCommune;return e==null?[]:this.data.adressesOfCommune(e)??[]},programmeModules(){let e=this.patrimoine?.codeProgramme;return e==null?[]:this.data.modulesOfProgramme(e)??[]},adresseModules(){let e=this.patrimoine?.idEntree;return e==null?[]:this.programmeModules.filter(t=>t.idEntree===e)},autresModules(){let e=this.patrimoine?.idEntree,t=Object.fromEntries(this.data.allAdresses().map(e=>[e.idEntree,e]));return this.programmeModules.map(n=>{let r=t[n.idEntree]?.entree??`Adresse ${n.idEntree}`;return{...n,_autreLibelle:n.idEntree===e&&n.etage!=null?`${r} — Étage ${n.etage}`:r}})},modules(){if(this.cibleMode===`contrat`)return this.contratModules.slice().sort((e,t)=>e.estModulePrincipal&&!t.estModulePrincipal?-1:!e.estModulePrincipal&&t.estModulePrincipal?1:t.dateDebut-e.dateDebut);let e=this.patrimoine?.etage,t=e==null?this.adresseModules:this.adresseModules.filter(t=>String(t.etage)===String(e)),n=new Set(t.map(e=>e.idModule));return[...t,...this.autresModules.filter(e=>!n.has(e.idModule))]},etages(){return[...new Set(this.adresseModules.map(e=>e.etage).filter(e=>e!=null))].sort((e,t)=>String(e).localeCompare(String(t),`fr`,{numeric:!0})).map(e=>({id:e,libelle:`Étage ${e}`}))},selectedContrat:{get(){let e=this.contratCible;return e?this.contratsTrouves.find(t=>String(t.idContrat)===String(e.idContrat)&&t.typeContrat===e.typeContrat)??{...e,libelle:e.libelle}:null},set(e){this.$emit(`select-contrat`,e??null)}},selectedCommune:{get(){let e=this.patrimoine?.idCommune;return e==null?null:(this.data.cache.communes||[]).find(t=>t.idCommune===e)??null},set(e){this.$emit(`select-commune`,e??null)}},selectedAdresse:{get(){let e=this.patrimoine?.idEntree;return e==null?null:this.adresses.find(t=>t.idEntree===e)??null},set(e){this.$emit(`select-adresse`,e??null)}},selectedEtage:{get(){let e=this.patrimoine?.etage;return e==null?null:this.etages.find(t=>t.id===e)??null},set(e){this.$emit(`select-etage`,e?.id??null)}},selectedModule:{get(){let e=this.patrimoine?.idModule;return e==null?null:this.modules.find(t=>t.idModule===e)??null},set(e){this.$emit(`select-module`,e??null)}}},watch:{modules:{immediate:!0,handler(e){this.cibleMode===`contrat`&&e.length===1&&this.patrimoine?.idModule==null&&this.$emit(`select-module`,e[0])}},contratReclamant(){this.contratsTrouves=[],this.rechercheFaite=!1}},beforeUnmount(){clearTimeout(this.rechercheTimeout),this.controller?.abort()},methods:{rechercherPlusTard(e){clearTimeout(this.rechercheTimeout),this.rechercheTimeout=setTimeout(()=>this.rechercherContrat(e),400)},rechercherContrat(e){let t=(e??``).trim();t.length<2?(this.contratsTrouves=[],this.rechercheEnCours=!1):(this.controller?.abort(),this.controller=new AbortController,this.rechercheEnCours=!0,this.data.searchContrats(t,{signal:this.controller.signal}).then(e=>{this.contratsTrouves=e??[],this.rechercheEnCours=!1}).catch(()=>{this.rechercheEnCours=!1}))},contratInputLibelle(e){return e?[e.libelle,`${e.typeContrat}/${e.idContrat}`].filter(Boolean).join(` — `):``},filterOn(e){return({search:t,items:n})=>{let r=(Y(t)??``).trim();return r?n.filter(t=>(Y(t?.[e])??``).includes(r)):n}},filterModules({search:e,items:t}){let n=(Y(e)??``).trim();return n?t.filter(e=>(Y(this.moduleInputLibelle(e))??``).includes(n)||(Y(e?._autreLibelle)??``).includes(n)):t},getCategorieModuleIcon:en,categorieLibelle:tn,moduleLibelle(e){return e?e.libelleModule??e.adresse??`Module ${e.idModule}`:``},moduleInputLibelle(e){let t=this.categorieLibelle(e);return t?`${t} — ${this.moduleLibelle(e)}`:this.moduleLibelle(e)},isExit(e){return!!e?.dateFin&&e.dateFin<Math.floor(Date.now()/1e3)}}},an={class:`d-flex flex-column gap-3`},on={class:`btn-group w-100`,role:`group`},sn=[`onClick`],cn={class:`text-muted d-block mt-1`},ln={key:0,class:`form-check`},un=[`id`,`checked`],dn=[`for`],fn={key:1},pn={class:`min-w-0`},mn={class:`fw-medium text-truncate text-capitalize`},hn={class:`text-muted d-block text-truncate`},gn={key:0},_n={key:1,class:`text-warning`},vn={class:`min-w-0`},yn={class:`fw-medium text-truncate`},bn={class:`text-muted d-block text-truncate`},xn={key:2,class:`row g-2`},Sn={class:`col-12 col-md-5`},Cn=[`value`],wn={class:`col-12 col-md-5`},Tn=[`value`],En={class:`col-12 col-md-2`},Dn=[`value`],On={key:3},kn={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},An={key:0,class:`text-lowercase fw-normal`},jn={class:`d-flex flex-wrap align-items-center gap-1`},Mn=[`title`],Nn={class:`text-muted`},Pn={key:1,class:`d-block text-truncate`},Fn={key:2,class:`text-muted d-block`},In={key:0,class:`text-muted d-block`},Ln={key:1,class:`mt-2 d-flex flex-column gap-2`},Rn={class:`form-check mb-0 ms-3`},zn=[`id`,`checked`],Bn=[`for`];function Vn(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`font-awesome-icon`),c=(0,n.resolveComponent)(`amsom-autocomplete`);return(0,n.openBlock)(),(0,n.createElementBlock)(`div`,an,[(0,n.createElementVNode)(`div`,null,[t[7]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` La sollicitation concerne… `,-1),(0,n.createElementVNode)(`div`,on,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.availableModes,t=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:t.key,type:`button`,class:(0,n.normalizeClass)([`btn btn-sm`,r.cibleMode===t.key?`btn-primary`:`btn-outline-primary`]),onClick:n=>e.$emit(`change-mode`,t.key)},[(0,n.createVNode)(s,{icon:t.icon,class:`me-1`},null,8,[`icon`]),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(t.label),1)],10,sn))),128))]),(0,n.createElementVNode)(`small`,cn,(0,n.toDisplayString)(o.currentMode?.aide),1)]),r.cibleMode===`contrat`?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:0},[r.afficheCaseContratReclamant?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ln,[(0,n.createElementVNode)(`input`,{id:`contrat-reclamant-${a.uid}`,class:`form-check-input`,type:`checkbox`,checked:r.contratReclamant,onChange:t[0]||=t=>e.$emit(`toggle-contrat-reclamant`,t.target.checked)},null,40,un),(0,n.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`contrat-reclamant-${a.uid}`},` Contrat du réclamant `,8,dn)])):(0,n.createCommentVNode)(``,!0),r.contratReclamant?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,fn,[t[8]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Contrat ciblé `,-1),(0,n.createVNode)(c,{modelValue:o.selectedContrat,"onUpdate:modelValue":t[1]||=e=>o.selectedContrat=e,items:a.contratsTrouves,"filtering-function":({items:e})=>e,loading:a.rechercheEnCours,"get-id":e=>e?`${e.typeContrat}|${e.idContrat}`:null,"get-input-libelle":o.contratInputLibelle,placeholder:`N° de contrat, locataire, module ou adresse…`,"input-size":`sm`,"hide-choices":``,"debounce-delay":0,onSearch:o.rechercherPlusTard},{options:(0,n.withCtx)(e=>[(0,n.createElementVNode)(`div`,pn,[(0,n.createElementVNode)(`div`,mn,(0,n.toDisplayString)(e?.libelle??`Contrat ${e?.idContrat}`),1),(0,n.createElementVNode)(`small`,hn,[(0,n.createTextVNode)((0,n.toDisplayString)(e?.typeContrat)+`/`+(0,n.toDisplayString)(e?.idContrat)+` `,1),e?.nbModules>1?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,gn,` — `+(0,n.toDisplayString)(e.nbModules)+` modules`,1)):(0,n.createCommentVNode)(``,!0),e?.estSorti?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,_n,` — sorti`)):(0,n.createCommentVNode)(``,!0)])])]),_:1},8,[`modelValue`,`items`,`filtering-function`,`loading`,`get-id`,`get-input-libelle`,`onSearch`])]))],64)):(0,n.createCommentVNode)(``,!0),r.cibleMode===`patrimoine`?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:1},[(0,n.createElementVNode)(`div`,null,[t[9]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Commune`,-1),(0,n.createVNode)(c,{modelValue:o.selectedCommune,"onUpdate:modelValue":t[2]||=e=>o.selectedCommune=e,items:i.data.cache.communes||[],"get-id":e=>e?.idCommune,"get-input-libelle":e=>e?.commune??``,"filtering-function":o.filterOn(`commune`),placeholder:`Rechercher une commune…`,"input-size":`sm`,"hide-choices":``},null,8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`filtering-function`])]),(0,n.createElementVNode)(`div`,null,[t[10]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Adresse`,-1),(0,n.createVNode)(c,{modelValue:o.selectedAdresse,"onUpdate:modelValue":t[3]||=e=>o.selectedAdresse=e,items:o.adresses,"get-id":e=>e?.idEntree,"get-input-libelle":e=>e?.entree??``,"filtering-function":o.filterOn(`entree`),disabled:!r.patrimoine.idCommune,placeholder:`Rechercher une adresse…`,"input-size":`sm`,"hide-choices":``},{options:(0,n.withCtx)(e=>[(0,n.createElementVNode)(`div`,vn,[(0,n.createElementVNode)(`div`,yn,(0,n.toDisplayString)(e?.entree),1),(0,n.createElementVNode)(`small`,bn,(0,n.toDisplayString)(e?.commune)+` — Programme `+(0,n.toDisplayString)(e?.codeProgramme),1)])]),_:1},8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`filtering-function`,`disabled`])]),(0,n.createElementVNode)(`div`,null,[t[11]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Étage`,-1),(0,n.createVNode)(c,{modelValue:o.selectedEtage,"onUpdate:modelValue":t[4]||=e=>o.selectedEtage=e,items:o.etages,"get-id":e=>e?.id,"get-input-libelle":e=>e?.libelle??``,disabled:!r.patrimoine.idEntree,placeholder:`Tous les étages…`,"input-size":`sm`,"hide-choices":``},null,8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`disabled`])])],64)):(0,n.createCommentVNode)(``,!0),r.cibleMode===`contrat`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,xn,[(0,n.createElementVNode)(`div`,Sn,[t[12]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Commune`,-1),(0,n.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:r.patrimoine.commune??`—`},null,8,Cn)]),(0,n.createElementVNode)(`div`,wn,[t[13]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Adresse`,-1),(0,n.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:r.patrimoine.entree??`—`},null,8,Tn)]),(0,n.createElementVNode)(`div`,En,[t[14]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Étage`,-1),(0,n.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:r.patrimoine.etage??`—`},null,8,Dn)])])):(0,n.createCommentVNode)(``,!0),r.cibleMode===`contrat`||r.cibleMode===`patrimoine`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,On,[(0,n.createElementVNode)(`label`,kn,[t[15]||=(0,n.createTextVNode)(` Module `,-1),r.cibleMode===`patrimoine`?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,An,`(facultatif)`)):(0,n.createCommentVNode)(``,!0)]),(0,n.createVNode)(c,{modelValue:o.selectedModule,"onUpdate:modelValue":t[5]||=e=>o.selectedModule=e,items:o.modules,"get-id":e=>e?.idModule,"get-input-libelle":e=>o.moduleInputLibelle(e),"filtering-function":o.filterModules,disabled:o.areModulesLocked,placeholder:`Rechercher un module…`,"input-size":`sm`,"hide-choices":``},{options:(0,n.withCtx)(e=>[(0,n.createElementVNode)(`div`,{class:(0,n.normalizeClass)([`min-w-0 w-100 rounded position-relative`,e?._autreLibelle?`bg-yellow-subtle p-2`:``])},[e?._autreLibelle?((0,n.openBlock)(),(0,n.createBlock)(s,{key:0,icon:`building`,class:`position-absolute top-0 end-0 m-1 text-muted`,title:`Autre adresse ou étage du même programme`})):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,{class:(0,n.normalizeClass)([`fw-medium text-truncate`,[e?._autreLibelle?`text-muted`:``,o.isExit(e)?`text-decoration-line-through`:``]])},(0,n.toDisplayString)(o.moduleLibelle(e)),3),(0,n.createElementVNode)(`div`,jn,[o.categorieLibelle(e)?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,{key:0,class:`badge bg-info`,title:e?.categorieModule},[(0,n.createVNode)(s,{icon:o.getCategorieModuleIcon(e?.idCategorieModule,e?.estCollectif)},null,8,[`icon`])],8,Mn)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`small`,Nn,`N° `+(0,n.toDisplayString)(e?.idModule),1)]),e?._autreLibelle?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,Pn,(0,n.toDisplayString)(e._autreLibelle),1)):e?.etage==null?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`small`,Fn,` Étage `+(0,n.toDisplayString)(e.etage),1))],2)]),_:1},8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`filtering-function`,`disabled`]),r.cibleMode===`patrimoine`&&!r.patrimoine.idModule?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,In,` Sans module, la sollicitation cible la partie commune de l’adresse. `)):(0,n.createCommentVNode)(``,!0),r.locataireActuelOption?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Ln,[(0,n.createElementVNode)(`div`,{class:(0,n.normalizeClass)([`alert d-flex align-items-start gap-2 py-2 px-3 mt-2 mb-0 fs-7`,r.locataireActuelOption.reprendre?`alert-warning`:`alert-secondary border`])},[(0,n.createVNode)(s,{icon:`circle-info`,class:`mt-1`}),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(r.locataireActuelOption.hint),1)],2),(0,n.createElementVNode)(`div`,Rn,[(0,n.createElementVNode)(`input`,{id:`locataire-actuel-${a.uid}`,class:`form-check-input`,type:`checkbox`,checked:r.locataireActuelOption.reprendre,onChange:t[6]||=t=>e.$emit(`toggle-reprendre-locataire-actuel`,t.target.checked)},null,40,zn),(0,n.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`locataire-actuel-${a.uid}`},` Rattacher au locataire actuel du module `,8,Bn)])])):(0,n.createCommentVNode)(``,!0)])):(0,n.createCommentVNode)(``,!0)])}var Hn=D(rn,[[`render`,Vn]]),Un={name:`EtapeCibleBlock`,components:{AmsomOverlay:t.AmsomOverlay,CiblePickerBlock:Hn},setup(){return{draft:E(),data:V(),options:J()}},computed:{lignePrincipale(){return this.draft.lignePrincipale},lignesAssociees(){return this.draft.lignesAssociees},reclamantModules(){return this.options.modulesReclamant??[]},mainModule(){return this.draft.moduleReclamantPrincipal},cibleFigee(){return this.draft.isReadonly(`cible`)},reclamantType(){return this.draft.draft.reclamant.type},motifLibelle(){let e=this.lignePrincipale.idMotif;return e==null?null:this.data.motifLibelle(e)}},async created(){if(this.reclamantType===`D`||this.cibleFigee)return;await this.data.loadCommunes(),!this.draft.reclamantEstContrat&&this.lignePrincipale.cibleMode===`contrat`&&this.draft.setCibleMode(0,`patrimoine`);let e=this.lignePrincipale.patrimoine;await this.data.loadAdresses(e?.idCommune??null),this.lignePrincipale.cibleMode!==`contrat`&&await this.data.loadModulesOfProgramme(e?.codeProgramme??null)},methods:{pickerProps(e){return{patrimoine:e.patrimoine,cibleMode:e.cibleMode,reclamantModules:this.reclamantModules,reclamantType:this.reclamantType,contratReclamant:e.contratReclamant,contratCible:e.contratCible,afficheCaseContratReclamant:this.draft.reclamantEstContrat,locataireActuelOption:this.locataireActuelOption(e)}},onChangeMode(e,t=0){this.draft.setCibleMode(t,e),this.applyMode(e,t)},onSelectCommune(e,t=0){this.draft.setPatrimoineCommune(t,e??null),e?.idCommune!=null&&this.data.loadAdresses(e.idCommune)},onSelectAdresse(e,t=0){this.draft.setPatrimoineEntree(t,e??null),e?.codeProgramme!=null&&this.data.loadModulesOfProgramme(e.codeProgramme)},onSelectEtage(e,t=0){this.draft.setPatrimoineEtage(t,e??null)},onSelectModule(e,t=0){let n=this.draft.draft.lignes[t];e&&n?.cibleMode===`contrat`?this.draft.prefillFromModule(t,e):this.draft.setPatrimoineModule(t,e??null)},onToggleReprendre(e,t=0){this.draft.setReprendreLocataireActuel(t,e)},onToggleContratReclamant(e,t=0){this.draft.toggleContratReclamant(t,e),e&&this.draft.prefillFromModule(t,this.mainModule)},onSelectContrat(e,t=0){this.draft.setContratCible(t,e),e&&this.data.loadModulesOfContrat({idContrat:e.idContrat,typeContrat:e.typeContrat})},locataireActuelOption(e){if(e?.cibleMode!==`contrat`)return null;let t=e?.patrimoine;if(!t||t.idModule==null)return null;let n=e.contratReclamant&&this.draft.reclamantEstContrat,r=n?{typeContrat:this.draft.draft.reclamant.type,idContrat:this.draft.draft.reclamant.id}:e.contratCible;if(!r?.idContrat||String(t.idContratActuel)===String(r.idContrat)&&String(t.typeContratActuel)===String(r.typeContrat))return null;let i=!!e.reprendreLocataireActuel,a=n?`Le réclamant n’occupe plus ce module : `:`Le contrat ciblé n’occupe plus ce module : `;if(!i)a+=`la cible restera le contrat ciblé, ancien occupant de ce module.`;else if(t.idContratActuel==null)a+=`ce module est vacant, la sollicitation ne sera rattachée à aucun contrat.`;else{let e=t.occupantActuel??`contrat sans libellé`,n=(t.typeContratActuel?`${t.typeContratActuel}/`:``)+t.idContratActuel;a+=`la cible sera le locataire actuel du module : ${e} ${n}.`}return{reprendre:i,hint:a}},async applyMode(e,t=0){e===`contrat`?this.draft.prefillFromModule(t,this.mainModule):this.mainModule&&(this.draft.prefillFromModule(t,this.mainModule),this.mainModule.idCommune!=null&&await this.data.loadAdresses(this.mainModule.idCommune),this.mainModule.codeProgramme!=null&&await this.data.loadModulesOfProgramme(this.mainModule.codeProgramme))}}},Wn={class:`d-flex flex-column gap-3`},Gn={key:0,class:`alert alert-light border py-2 px-3 mb-0 d-flex align-items-center gap-2`},Kn={class:`fs-7`},qn={key:1,class:`d-flex flex-column gap-1`},Jn={key:0,class:`text-muted me-1`},Yn={class:`d-flex align-items-center gap-2`},Xn={class:`fw-medium fs-7`},Zn={class:`form-check form-switch mb-0`},Qn=[`id`,`checked`,`onChange`],$n=[`for`],er={key:0,class:`mt-2`};function tr(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`font-awesome-icon`),c=(0,n.resolveComponent)(`cible-picker-block`),l=(0,n.resolveComponent)(`amsom-overlay`);return(0,n.openBlock)(),(0,n.createBlock)(l,{loading:i.data.isLoading},{default:(0,n.withCtx)(()=>[(0,n.createElementVNode)(`div`,Wn,[o.motifLibelle?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Gn,[(0,n.createVNode)(s,{icon:`tag`,class:`text-primary`}),(0,n.createElementVNode)(`span`,Kn,[t[8]||=(0,n.createElementVNode)(`span`,{class:`text-muted text-uppercase fw-semibold me-1`},`Motif`,-1),(0,n.createTextVNode)((0,n.toDisplayString)(o.motifLibelle),1)])])):(0,n.createCommentVNode)(``,!0),o.cibleFigee?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,qn,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(i.draft.draft.lignes,(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`span`,{key:t,class:`fs-7`},[(0,n.createVNode)(s,{icon:`location-dot`,class:`text-primary me-2`}),o.lignesAssociees.length?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,Jn,(0,n.toDisplayString)(t===0?o.motifLibelle:e.libelle)+` : `,1)):(0,n.createCommentVNode)(``,!0),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(i.draft.cibleResume(e)),1)]))),128))])):((0,n.openBlock)(),(0,n.createBlock)(c,(0,n.mergeProps)({key:2},o.pickerProps(o.lignePrincipale),{onChangeMode:t[0]||=e=>o.onChangeMode(e),onSelectCommune:t[1]||=e=>o.onSelectCommune(e),onSelectAdresse:t[2]||=e=>o.onSelectAdresse(e),onSelectEtage:t[3]||=e=>o.onSelectEtage(e),onSelectModule:t[4]||=e=>o.onSelectModule(e),onSelectContrat:t[5]||=e=>o.onSelectContrat(e),onToggleContratReclamant:t[6]||=e=>o.onToggleContratReclamant(e),onToggleReprendreLocataireActuel:t[7]||=e=>o.onToggleReprendre(e)}),null,16)),!o.cibleFigee&&o.lignesAssociees.length&&o.reclamantType!==`D`?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:3},[t[9]||=(0,n.createElementVNode)(`div`,{class:`d-flex align-items-center gap-2 text-muted fs-7`},[(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`}),(0,n.createElementVNode)(`span`,null,`Cible des autres motifs`),(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`})],-1),((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.lignesAssociees,(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:e.idMotif,class:`border rounded p-2`},[(0,n.createElementVNode)(`div`,Yn,[(0,n.createElementVNode)(`span`,Xn,(0,n.toDisplayString)(e.libelle),1),(0,n.createElementVNode)(`div`,Zn,[(0,n.createElementVNode)(`input`,{id:`memecible-${e.idMotif}`,class:`form-check-input`,type:`checkbox`,checked:!e.patrimoine,onChange:e=>i.draft.toggleCibleOverride(t+1)},null,40,Qn),(0,n.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`memecible-${e.idMotif}`},` Même cible que la ligne principale `,8,$n)])]),e.patrimoine?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,er,[(0,n.createVNode)(c,(0,n.mergeProps)({ref_for:!0},o.pickerProps(e),{onChangeMode:e=>o.onChangeMode(e,t+1),onSelectCommune:e=>o.onSelectCommune(e,t+1),onSelectAdresse:e=>o.onSelectAdresse(e,t+1),onSelectEtage:e=>o.onSelectEtage(e,t+1),onSelectModule:e=>o.onSelectModule(e,t+1),onSelectContrat:e=>o.onSelectContrat(e,t+1),onToggleContratReclamant:e=>o.onToggleContratReclamant(e,t+1),onToggleReprendreLocataireActuel:e=>o.onToggleReprendre(e,t+1)}),null,16,[`onChangeMode`,`onSelectCommune`,`onSelectAdresse`,`onSelectEtage`,`onSelectModule`,`onSelectContrat`,`onToggleContratReclamant`,`onToggleReprendreLocataireActuel`])])):(0,n.createCommentVNode)(``,!0)]))),128))],64)):(0,n.createCommentVNode)(``,!0)])]),_:1},8,[`loading`])}var nr=D(Un,[[`render`,tr]]),rr={name:`LigneDocumentBlock`,components:{AmsomUploadFile:u.AmsomUploadFile},props:{index:{type:Number,required:!0},fichier:{type:[Object,Array],default:null},readonly:{type:Boolean,default:!1}},emits:[`update`]};function ir(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`amsom-upload-file`);return(0,n.openBlock)(),(0,n.createElementBlock)(`div`,null,[t[1]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Document`,-1),(0,n.createVNode)(s,{"model-value":r.fichier,renameable:``,"output-format":`object`,name:`cresol-creation-ged-${r.index}`,"merge-pdfs":``,"read-only":r.readonly,"onUpdate:modelValue":t[0]||=t=>e.$emit(`update`,t)},null,8,[`model-value`,`name`,`read-only`])])}var ar=D(rr,[[`render`,ir]]);function or(e){return e==null?``:new Date(e*1e3).toISOString().slice(0,10)}function sr(e){return e?Math.floor(new Date(e).getTime()/1e3):null}var cr=4e3,lr={name:`LigneDetailBlock`,components:{AmsomAutocomplete:a.AmsomAutocomplete,AmsomTextarea:l.AmsomTextarea,LigneDocumentBlock:ar},props:{index:{type:Number,required:!0}},setup(){return{draft:E(),data:V()}},computed:{descriptionMaxLength:()=>cr,isPrincipale(){return this.index===0},ligne(){return this.draft.draft.lignes[this.index]},lignePrincipale(){return this.draft.lignePrincipale},collaborateurs(){return(this.data.cache.collaborateurs??[]).filter(e=>e.actif!==!1)},dateFaits(){return this.isPrincipale||this.ligne.dateFaitsOverride?this.ligne.dateFaits:this.lignePrincipale.dateFaits}},methods:{timestampToDateInput:or,dateInputToTimestamp:sr,responsableLibelle(e){let t=e&&typeof e!=`object`?this.collaborateurs.find(t=>String(t.id)===String(e)):e;return t?`${t.prenom} ${t.nom}`:``},filterCollaborateurs({search:e,items:t}){let n=(Y(e)??``).trim();return n?t.filter(e=>(Y(`${e.prenom} ${e.nom} ${e.service}`)??``).includes(n)):t}}},ur={class:`d-flex flex-column gap-2`},dr={class:`d-flex align-items-center gap-2 mb-1`},fr={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-0`},pr={key:0,class:`ms-1 text-danger`},mr={key:0,class:`form-check form-switch mb-0`},hr=[`id`,`checked`,`disabled`],gr=[`for`],_r={key:1,class:`text-muted d-block`,style:{"white-space":`pre-line`}},vr={class:`row g-3`},yr={class:`col-6`},br={class:`d-flex align-items-center gap-2 mb-1`},xr={key:0,class:`form-check form-switch mb-0`},Sr=[`id`,`checked`,`disabled`],Cr=[`for`],wr=[`value`],Tr={key:1,class:`text-muted d-block`},Er={key:0,class:`text-muted d-block`},Dr={class:`min-w-0`},Or={class:`fw-medium text-truncate`},kr={key:0,class:`text-muted d-block`},Ar={key:2,class:`text-muted`},jr={class:`col-12 col-md-6`};function Mr(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`amsom-textarea`),c=(0,n.resolveComponent)(`amsom-autocomplete`),l=(0,n.resolveComponent)(`ligne-document-block`);return(0,n.openBlock)(),(0,n.createElementBlock)(`div`,ur,[(0,n.createElementVNode)(`div`,null,[(0,n.createElementVNode)(`div`,dr,[(0,n.createElementVNode)(`label`,fr,[t[6]||=(0,n.createTextVNode)(` Description`,-1),o.isPrincipale?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,pr,`*`)):(0,n.createCommentVNode)(``,!0)]),o.isPrincipale?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,mr,[(0,n.createElementVNode)(`input`,{id:`memedetail-${o.ligne.idMotif}`,class:`form-check-input`,type:`checkbox`,checked:o.ligne.description==null,disabled:i.draft.isReadonly(`description`),onChange:t[0]||=e=>i.draft.toggleDescriptionOverride(r.index)},null,40,hr),(0,n.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`memedetail-${o.ligne.idMotif}`},` Même description `,8,gr)]))]),!i.draft.isReadonly(`description`)&&(o.isPrincipale||o.ligne.description!=null)?((0,n.openBlock)(),(0,n.createBlock)(s,{key:0,"model-value":o.ligne.description,"input-size":`sm`,rows:o.isPrincipale?4:3,maxlength:o.descriptionMaxLength,placeholder:o.isPrincipale?`Décrivez la sollicitation…`:`Décrivez ce motif…`,"onUpdate:modelValue":t[1]||=e=>i.draft.setDescription(r.index,e)},null,8,[`model-value`,`rows`,`maxlength`,`placeholder`])):((0,n.openBlock)(),(0,n.createElementBlock)(`small`,_r,(0,n.toDisplayString)((o.ligne.description??o.lignePrincipale.description)||`—`),1))]),(0,n.createElementVNode)(`div`,vr,[(0,n.createElementVNode)(`div`,yr,[(0,n.createElementVNode)(`div`,null,[(0,n.createElementVNode)(`div`,br,[t[7]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-0`},` Date des faits `,-1),o.isPrincipale?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,xr,[(0,n.createElementVNode)(`input`,{id:`memedate-${o.ligne.idMotif}`,class:`form-check-input`,type:`checkbox`,checked:!o.ligne.dateFaitsOverride,disabled:i.draft.isReadonly(`dateFaits`),onChange:t[2]||=e=>i.draft.toggleDateFaitsOverride(r.index)},null,40,Sr),(0,n.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`memedate-${o.ligne.idMotif}`},` Même date `,8,Cr)]))]),!i.draft.isReadonly(`dateFaits`)&&(o.isPrincipale||o.ligne.dateFaitsOverride)?((0,n.openBlock)(),(0,n.createElementBlock)(`input`,{key:0,value:o.timestampToDateInput(o.ligne.dateFaits),type:`date`,class:`form-control form-control-sm`,onInput:t[3]||=e=>i.draft.setDateFaits(r.index,o.dateInputToTimestamp(e.target.value))},null,40,wr)):((0,n.openBlock)(),(0,n.createElementBlock)(`small`,Tr,(0,n.toDisplayString)(o.timestampToDateInput(o.dateFaits)||`—`),1))]),(0,n.createElementVNode)(`div`,null,[t[8]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Responsable `,-1),i.draft.isReadonly(`responsable`)?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,Er,(0,n.toDisplayString)(o.responsableLibelle(o.ligne.responsable)||`Déterminé automatiquement`),1)):((0,n.openBlock)(),(0,n.createBlock)(c,{key:1,"model-value":o.ligne.responsable,items:o.collaborateurs,"get-id":e=>e?.id,"get-input-libelle":o.responsableLibelle,"filtering-function":o.filterCollaborateurs,placeholder:`Rechercher un responsable…`,"input-size":`sm`,"hide-choices":``,"onUpdate:modelValue":t[4]||=e=>i.draft.setResponsable(r.index,e??null)},{options:(0,n.withCtx)(e=>[(0,n.createElementVNode)(`div`,Dr,[(0,n.createElementVNode)(`div`,Or,(0,n.toDisplayString)(e?.prenom)+` `+(0,n.toDisplayString)(e?.nom),1),e?.service?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,kr,(0,n.toDisplayString)(e.service),1)):(0,n.createCommentVNode)(``,!0)])]),_:1},8,[`model-value`,`items`,`get-id`,`get-input-libelle`,`filtering-function`])),o.isPrincipale&&!o.ligne.responsable&&!i.draft.isReadonly(`responsable`)?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,Ar,` Aucun paramétrage trouvé : le responsable sera déterminé automatiquement. `)):(0,n.createCommentVNode)(``,!0)])]),(0,n.createElementVNode)(`div`,jr,[(0,n.createVNode)(l,{index:r.index,fichier:o.ligne.fichier,readonly:i.draft.isReadonly(`fichier`),onUpdate:t[5]||=e=>i.draft.setFichier(r.index,e)},null,8,[`index`,`fichier`,`readonly`])])])])}var Nr=D(lr,[[`render`,Mr]]),Pr={name:`EtapeDetailsBlock`,components:{AmsomOverlay:t.AmsomOverlay,LigneDetailBlock:Nr},setup(){return{draft:E(),data:V()}},computed:{lignePrincipale(){return this.draft.lignePrincipale},lignesAssociees(){return this.draft.lignesAssociees},collaborateurs(){return(this.data.cache.collaborateurs??[]).filter(e=>e.actif!==!1)},motifLibelle(){let e=this.lignePrincipale.idMotif;return e==null?null:this.data.motifLibelle(e)}},async created(){await this.data.loadCollaborateurs(),await this.prefillResponsables()},methods:{codeOfPatrimoine(e){return{codeProgramme:e?.codeProgramme,codeTranche:e?.codeTranche,codeBatiment:e?.codeBatiment,codeEscalier:e?.codeEscalier}},async suggestResponsable(e,t=null){await this.data.loadResponsables({motif:e.idMotif,categorie:e.idCategorie,type:e.idType,nature:e.idNature});let n=this.codeOfPatrimoine(t??this.lignePrincipale.patrimoine),r=this.data.getResponsableSuggere({idMotif:e.idMotif,...n});return r?this.collaborateurs.find(e=>String(e.id)===String(r.idResponsable))??null:null},async prefillResponsables(){if(!this.draft.isReadonly(`responsable`))for(let[e,t]of this.draft.draft.lignes.entries()){if(t.responsable!=null||t.idMotif==null)continue;let n=await this.suggestResponsable(t,t.patrimoine??null);n&&this.draft.setResponsable(e,n)}}}},Fr={class:`d-flex flex-column gap-3`},Ir={class:`alert alert-light border py-2 px-3 mb-0 d-flex flex-column gap-1`},Lr={key:0,class:`fs-7`},Rr={class:`fs-7`},zr={class:`bg-light rounded px-2 py-1 d-flex flex-column gap-1`},Br={class:`fs-7`},Vr={class:`fs-7`};function Hr(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`font-awesome-icon`),c=(0,n.resolveComponent)(`ligne-detail-block`),l=(0,n.resolveComponent)(`amsom-overlay`);return(0,n.openBlock)(),(0,n.createBlock)(l,{loading:i.data.isLoading&&!i.data.cache.collaborateurs},{default:(0,n.withCtx)(()=>[(0,n.createElementVNode)(`div`,Fr,[(0,n.createElementVNode)(`div`,Ir,[o.motifLibelle?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,Lr,[(0,n.createVNode)(s,{icon:`tag`,class:`text-primary me-2`}),t[0]||=(0,n.createElementVNode)(`span`,{class:`text-muted text-uppercase fw-semibold me-1`},`Motif`,-1),(0,n.createTextVNode)((0,n.toDisplayString)(o.motifLibelle),1)])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,Rr,[(0,n.createVNode)(s,{icon:`location-dot`,class:`text-primary me-2`}),t[1]||=(0,n.createElementVNode)(`span`,{class:`text-muted text-uppercase fw-semibold me-1`},`Cible`,-1),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(i.draft.cibleResume(o.lignePrincipale)),1)])]),(0,n.createVNode)(c,{index:0}),o.lignesAssociees.length?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:0},[t[4]||=(0,n.createElementVNode)(`div`,{class:`d-flex align-items-center gap-2 text-muted fs-7`},[(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`}),(0,n.createElementVNode)(`span`,null,`Détail des autres motifs`),(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`})],-1),((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.lignesAssociees,(e,r)=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:e.idMotif,class:`border rounded p-2 d-flex flex-column gap-2`},[(0,n.createElementVNode)(`div`,zr,[(0,n.createElementVNode)(`span`,Br,[(0,n.createVNode)(s,{icon:`tag`,class:`text-primary me-2`}),t[2]||=(0,n.createElementVNode)(`span`,{class:`text-muted text-uppercase fw-semibold me-1`},`Motif`,-1),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(e.libelle),1)]),(0,n.createElementVNode)(`span`,Vr,[(0,n.createVNode)(s,{icon:`location-dot`,class:`text-primary me-2`}),t[3]||=(0,n.createElementVNode)(`span`,{class:`text-muted text-uppercase fw-semibold me-1`},`Cible`,-1),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(i.draft.cibleResume(e)),1)])]),(0,n.createVNode)(c,{index:r+1},null,8,[`index`])]))),128))],64)):(0,n.createCommentVNode)(``,!0)])]),_:1},8,[`loading`])}var Ur=D(Pr,[[`render`,Hr]]),Wr={name:`StepperBlock`,components:{AmsomHorizontalStepper:i.default,AmsomOverlay:t.AmsomOverlay,EtapeReclamantBlock:yt,EtapeCategorieBlock:Qt,EtapeCibleBlock:nr,EtapeDetailsBlock:Ur},props:{step:{type:Number,default:1},creating:{type:Boolean,default:!1}},emits:[`update:step`,`stepChange`,`submit`],setup(){return{draft:E(),data:V(),options:J()}},computed:{steps(){return[...this.options.reclamantMode===`step`?[{key:`reclamant`,label:`Réclamant`,icon:`user`}]:[],{key:`categorie`,label:`Catégorisation`,icon:`tag`},{key:`cible`,label:`Cible`,icon:`location-dot`},{key:`details`,label:`Détails`,icon:`info`}]},currentKey(){return this.steps[this.step-1]?.key??null},lignePrincipale(){return this.draft.lignePrincipale},aideMotif(){let e=this.lignePrincipale.idMotif;return e?this.data.cache.motifs?.find(t=>t.id===e)?.aide??null:null},canGoNext(){return this.gatePassed(this.currentKey)},canCreer(){return!!this.lignePrincipale.idMotif&&!!this.draft.draft.provenance&&this.draft.ciblesValid&&this.draft.detailsValid&&this.draft.reclamantSelectionne!=null},stepperSteps(){return this.steps.map((e,t)=>{let n=t+1;return{numero:n,subtitle:e.label,subtitleColor:n===this.step?`primary`:`muted`,icon:n<this.step?`check`:e.icon,iconColor:`white`,bubbleBgColor:n>this.step?`gray`:`primary`,clickable:n<this.step}})}},watch:{step(e,t){this.$emit(`stepChange`,{step:e,key:this.currentKey,previous:{step:t,key:this.steps[t-1]?.key??null}})}},methods:{gatePassed(e){return e===`reclamant`?this.draft.reclamantSelectionne!=null&&!!this.draft.draft.provenance:e===`categorie`?!!this.lignePrincipale.idMotif&&!!this.draft.draft.provenance:e!==`cible`||this.draft.ciblesValid},onStepClick(e){e<this.step&&this.$emit(`update:step`,e)},goPrevious(){this.step>1&&this.$emit(`update:step`,this.step-1)},goNext(){this.step>=this.steps.length||!this.canGoNext||(this.currentKey===`categorie`&&this.preloadResponsables(),this.$emit(`update:step`,this.step+1))},preloadResponsables(){this.draft.draft.lignes.forEach(e=>this.data.loadResponsables({motif:e.idMotif,categorie:e.idCategorie,type:e.idType,nature:e.idNature}))}}},Gr={class:`d-flex flex-column gap-3`},Kr={key:0,class:`w-100 fs-6 fw-medium my-3 alert alert-info`,style:{"white-space":`pre-line`}},qr={style:{"min-height":`260px`}},Jr={class:`d-flex justify-content-between`},Yr={key:1},Xr=[`disabled`],Zr=[`disabled`];function Qr(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`amsom-horizontal-stepper`),c=(0,n.resolveComponent)(`font-awesome-icon`),l=(0,n.resolveComponent)(`etape-reclamant-block`),u=(0,n.resolveComponent)(`etape-categorie-block`),d=(0,n.resolveComponent)(`etape-cible-block`),f=(0,n.resolveComponent)(`etape-details-block`),p=(0,n.resolveComponent)(`amsom-overlay`);return(0,n.openBlock)(),(0,n.createBlock)(p,{loading:r.creating},{default:(0,n.withCtx)(()=>[(0,n.createElementVNode)(`div`,Gr,[(0,n.createVNode)(s,{steps:o.stepperSteps,size:`md`,onStepClick:o.onStepClick},null,8,[`steps`,`onStepClick`]),o.aideMotif?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Kr,[(0,n.createVNode)(c,{icon:`circle-info`,class:`text-info-emphasis me-2`}),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(o.aideMotif),1)])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,qr,[o.currentKey===`reclamant`?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,premiere:r.step===1},(0,n.createSlots)({_:2},[e.$slots.reclamant?{name:`reclamant`,fn:(0,n.withCtx)(t=>[(0,n.renderSlot)(e.$slots,`reclamant`,(0,n.normalizeProps)((0,n.guardReactiveProps)(t)))]),key:`0`}:void 0]),1032,[`premiere`])):o.currentKey===`categorie`?((0,n.openBlock)(),(0,n.createBlock)(u,{key:1,premiere:r.step===1},null,8,[`premiere`])):o.currentKey===`cible`?((0,n.openBlock)(),(0,n.createBlock)(d,{key:2})):o.currentKey===`details`?((0,n.openBlock)(),(0,n.createBlock)(f,{key:3})):(0,n.createCommentVNode)(``,!0)]),(0,n.createElementVNode)(`div`,Jr,[r.step>1?((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:0,class:`btn btn-sm btn-outline-secondary`,onClick:t[0]||=(...e)=>o.goPrevious&&o.goPrevious(...e)},[(0,n.createVNode)(c,{icon:`chevron-left`,class:`me-1`}),t[3]||=(0,n.createTextVNode)(` Précédent `,-1)])):((0,n.openBlock)(),(0,n.createElementBlock)(`span`,Yr)),r.step<o.steps.length?((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:2,class:`btn btn-sm btn-primary`,disabled:!o.canGoNext,onClick:t[1]||=(...e)=>o.goNext&&o.goNext(...e)},[t[4]||=(0,n.createTextVNode)(` Suivant `,-1),(0,n.createVNode)(c,{icon:`chevron-right`,class:`ms-1`})],8,Xr)):((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:3,class:`btn btn-sm btn-success`,disabled:!o.canCreer||r.creating,onClick:t[2]||=t=>e.$emit(`submit`)},[(0,n.createVNode)(c,{icon:`check`,class:`me-1`}),t[5]||=(0,n.createTextVNode)(` Créer la sollicitation `,-1)],8,Zr))])])]),_:3},8,[`loading`])}var $r=D(Wr,[[`render`,Qr]]),ei=(e,{signal:t,token:n,baseUrl:r}={})=>M(`/v2/cresol/creer_sollicitation`,e,{signal:t,token:n,baseUrl:r}),ti=({idSollicitation:e,pj:t},{signal:n,token:r,baseUrl:i}={})=>M(`/v2/cresol/upload_sollicitation_ged`,{idSollicitation:e,pj:t},{signal:n,token:r,baseUrl:i}),X={modelValue:{type:Object,default:null},reclamants:{type:Array,default:()=>[]},reclamantMode:{type:String,default:`select`,validator:e=>[`select`,`switch`,`autocomplete`,`step`].includes(e)},readonly:{type:[Boolean,Array],default:!1,validator:e=>typeof e==`boolean`||e.every(e=>C.includes(e))},modules:{type:Array,default:null},idModule:{type:[String,Number],default:null},nomenclatureFilter:{type:Function,default:null},aside:{type:Boolean,default:!0},nbSimilaires:{type:Number,default:0},baseUrl:{type:String,default:null},token:{type:String,default:null}},ni=Object.keys(X),Z=[`update:modelValue`,`reclamantChange`,`motifChange`,`stepChange`,`beforeCreate`,`created`,`createError`,`error`],ri={name:`CreerSollicitationForm`,components:{AsideBlock:ge,StepperBlock:$r},props:{...X},emits:[...Z],setup(e,{emit:t}){let r=e=>t(`error`,e),i={token:(0,n.toRef)(e,`token`),baseUrl:(0,n.toRef)(e,`baseUrl`)},a=Be(ze({onError:r,...i})),o=(0,n.ref)(null),s=(0,n.computed)(()=>o.value??e.modules??[]),c=le(ce({reclamants:(0,n.computed)(()=>e.reclamantMode===`step`?[]:e.reclamants),modules:s,idModulePrefere:(0,n.toRef)(e,`idModule`),readonly:(0,n.toRef)(e,`readonly`)}));return bt((0,n.reactive)({nomenclatureFilter:(0,n.toRef)(e,`nomenclatureFilter`),reclamantMode:(0,n.toRef)(e,`reclamantMode`),modulesReclamant:s,...i})),{data:a,draft:c,modulesCharges:o,onError:r}},data(){return{currentStep:1,creating:!1}},computed:{requestOptions(){return{token:this.token,baseUrl:this.baseUrl}},motifChoisi(){let[e,...t]=this.draft.draft.lignes;return{idCategorie:e.idCategorie,idType:e.idType,idNature:e.idNature,idMotif:e.idMotif,motifsAssocies:t.map(e=>e.idMotif)}}},watch:{"draft.draft":{deep:!0,handler(e){this.$emit(`update:modelValue`,e)}}},async created(){this.draft.reset(this.modelValue),this.draft.syncReclamant();let e=this.draft.reclamantSelectionne;this.$watch(`draft.reclamantSelectionne`,async t=>{this.$emit(`reclamantChange`,t),await this.chargerModulesReclamant(t,e)&&this.draft.syncReclamant()}),this.$watch(()=>JSON.stringify(this.motifChoisi),()=>this.$emit(`motifChange`,this.motifChoisi)),this.data.loadNomenclature(),await this.chargerModulesReclamant(e,e)&&this.draft.prefillCiblePrincipale()},methods:{async chargerModulesReclamant(e,t){if(this.modules&&e===t)return this.modulesCharges=null,!0;if(!this.draft.reclamantEstContrat)return this.modulesCharges=[],!0;let n=await this.data.loadModulesOfContrat({idContrat:e.id,typeContrat:e.type});return e===this.draft.reclamantSelectionne&&(this.modulesCharges=n??[],!0)},async creer(){if(!this.creating){this.creating=!0;try{let e=this.draft.creationPayload();if(!await this.autoriserCreation(e))return;let t;try{t=await ei(e,this.requestOptions)??[]}catch(t){if(F(t))return;let n=P(t);this.$emit(`createError`,{error:t,message:n,payload:e}),this.onError(n);return}let n=await this.sendFiles(t);this.$emit(`created`,t,{payload:e,fichiers:n})}finally{this.creating=!1}}},async autoriserCreation(e){let t=!1,n=[];if(this.$emit(`beforeCreate`,{payload:e,cancel:()=>{t=!0},waitUntil:e=>{n.push(e)}}),t)return!1;try{let e=await Promise.all(n);return!t&&!e.includes(!1)}catch{return!1}},sendFiles(e){let t=[...e],n=this.draft.draft.lignes.filter(e=>e.fichier?.[0]).map(e=>{let n=e.fichier[0],r=e.libelle||e.idMotif,i=t.findIndex(t=>String(t.idMotif)===String(e.idMotif)),a=i===-1?null:t.splice(i,1)[0],o={idMotif:e.idMotif,nom:n.name,idSollicitation:a?.id??null},s=e=>{let t=`Document non envoyé (${r}) : ${e}`;return this.onError(t),{...o,ok:!1,message:t}};return a?.id?ti({idSollicitation:a.id,pj:{name:n.name,type:n.type||`application/pdf`,file:n.file}},this.requestOptions).then(()=>({...o,ok:!0,message:null})).catch(e=>s(P(e))):Promise.resolve(s(`sollicitation introuvable dans la réponse`))});return Promise.all(n)}}},ii={class:`row g-3`},ai={key:0,class:`col-12 col-lg-4`};function oi(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`aside-block`),c=(0,n.resolveComponent)(`stepper-block`);return(0,n.openBlock)(),(0,n.createElementBlock)(`div`,ii,[e.aside?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ai,[(0,n.renderSlot)(e.$slots,`aside`,{},()=>[(0,n.createVNode)(s,{"nb-similaires":e.nbSimilaires},(0,n.createSlots)({_:2},[e.$slots[`aside-similaires`]?{name:`similaires`,fn:(0,n.withCtx)(t=>[(0,n.renderSlot)(e.$slots,`aside-similaires`,(0,n.normalizeProps)((0,n.guardReactiveProps)(t)))]),key:`0`}:void 0,e.$slots[`aside-evenements`]?{name:`evenements`,fn:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`aside-evenements`)]),key:`1`}:void 0]),1032,[`nb-similaires`])])])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,{class:(0,n.normalizeClass)([`col-12`,e.aside?`col-lg-8`:``])},[(0,n.createVNode)(c,{step:a.currentStep,"onUpdate:step":t[0]||=e=>a.currentStep=e,creating:a.creating,onStepChange:t[1]||=t=>e.$emit(`stepChange`,t),onSubmit:o.creer},(0,n.createSlots)({_:2},[e.$slots.reclamant?{name:`reclamant`,fn:(0,n.withCtx)(t=>[(0,n.renderSlot)(e.$slots,`reclamant`,(0,n.normalizeProps)((0,n.guardReactiveProps)(t)))]),key:`0`}:void 0]),1032,[`step`,`creating`,`onSubmit`])],2)])}var Q=D(ri,[[`render`,oi]]),si={name:`CreerSollicitationModal`,components:{AmsomModal:t.AmsomModal,CreerSollicitationForm:Q},props:{...X,titre:{type:String,default:`Nouvelle sollicitation`},closeOnCreated:{type:Boolean,default:!0}},emits:[...Z,`close`],computed:{formProps(){return Object.fromEntries(ni.map(e=>[e,this[e]]))},formListeners(){return Object.fromEntries(Z.filter(e=>e!==`created`).map(e=>[e,(...t)=>this.$emit(e,...t)]))}},methods:{onCreated(...e){this.$emit(`created`,...e),this.closeOnCreated&&this.$emit(`close`)}}},ci={class:`fw-medium fs-5`};function li(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`creer-sollicitation-form`),c=(0,n.resolveComponent)(`amsom-modal`);return(0,n.openBlock)(),(0,n.createBlock)(c,{"close-option":``,size:`xl`,onClose:t[0]||=t=>e.$emit(`close`)},{default:(0,n.withCtx)(()=>[(0,n.createElementVNode)(`span`,ci,(0,n.toDisplayString)(r.titre),1),(0,n.createVNode)(s,(0,n.mergeProps)({class:`pt-3`},o.formProps,(0,n.toHandlers)(o.formListeners),{onCreated:o.onCreated}),(0,n.createSlots)({_:2},[(0,n.renderList)(e.$slots,(t,r)=>({name:r,fn:(0,n.withCtx)(t=>[(0,n.renderSlot)(e.$slots,r,(0,n.normalizeProps)((0,n.guardReactiveProps)(t??{})))])}))]),1040,[`onCreated`])]),_:3})}var $=D(si,[[`render`,li]]),ui={CreerSollicitationModal:$,CreerSollicitationForm:Q};e.CreerSollicitationForm=Q,e.CreerSollicitationModal=$,e.DEFAULT_PROVENANCE_CONTACT=ee,e.PROVENANCES_CONTACT=y,e.READONLY_FIELDS=C,e.configureCresol=_e,e.default=ui,e.getDefaultDraft=w,e.getDefaultLigne=S,e.getDefaultPatrimoine=x,e.resetCresolCache=Re});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@amsom-habitat/ui"),require("vue"),require("@amsom-habitat/nav-tabs"),require("@amsom-habitat/horizontal-stepper"),require("@amsom-habitat/amsom-autocomplete"),require("@amsom-habitat/axios-overlay"),require("@amsom-habitat/user-manager"),require("@fortawesome/fontawesome-svg-core"),require("@amsom-habitat/amsom-textarea"),require("@amsom-habitat/file-manager")):typeof define==`function`&&define.amd?define([`exports`,`@amsom-habitat/ui`,`vue`,`@amsom-habitat/nav-tabs`,`@amsom-habitat/horizontal-stepper`,`@amsom-habitat/amsom-autocomplete`,`@amsom-habitat/axios-overlay`,`@amsom-habitat/user-manager`,`@fortawesome/fontawesome-svg-core`,`@amsom-habitat/amsom-textarea`,`@amsom-habitat/file-manager`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Cresol={},e._amsom_habitat_ui,e.Vue,e._amsom_habitat_nav_tabs,e._amsom_habitat_horizontal_stepper,e._amsom_habitat_amsom_autocomplete,e._amsom_habitat_axios_overlay,e._amsom_habitat_user_manager,e._fortawesome_fontawesome_svg_core,e._amsom_habitat_amsom_textarea,e._amsom_habitat_file_manager))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var d=Object.create,f=Object.defineProperty,p=Object.getOwnPropertyDescriptor,m=Object.getOwnPropertyNames,h=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty,_=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=m(t),a=0,o=i.length,s;a<o;a++)s=i[a],!g.call(e,s)&&s!==n&&f(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=p(t,s))||r.enumerable});return e},v=(e,t,n)=>(n=e==null?{}:d(h(e)),_(t||!e||!e.__esModule||!g.call(e,`default`)?f(n,`default`,{value:e,enumerable:!0}):n,e));i=v(i),o=v(o,1),s=v(s,1);var y=[{id:`T`,libelle:`Téléphone`,icon:`phone`},{id:`M`,libelle:`Email`,icon:`envelope`},{id:`G`,libelle:`Gardien`,icon:`user-shield`},{id:`V`,libelle:`Visite au siège`,icon:`building`},{id:`IP`,libelle:`Incident de permanence`,icon:`exclamation-triangle`},{id:`C`,libelle:`Courrier`,icon:`envelope-open`}],ee=`T`,b=Symbol(`cresol:draft`),x=()=>({idCommune:null,commune:null,idEntree:null,entree:null,etage:null,idModule:null,libelleModule:null,codeProgramme:null,codeTranche:null,codeBatiment:null,codeEscalier:null,typeContratActuel:null,idContratActuel:null,occupantActuel:null}),S=()=>({idMotif:null,idCategorie:null,idType:null,idNature:null,libelle:null,responsable:null,cibleOverride:!1,cibleMode:null,contratReclamant:!0,contratCible:null,reprendreLocataireActuel:!1,modulePrecis:!0,patrimoine:null,description:null,dateFaits:null,dateFaitsOverride:!1,fichier:null}),C=[`reclamant`,`provenance`,`motif`,`cible`,`description`,`dateFaits`,`responsable`,`fichier`],te=[`D`,`U`,`T`],w=(e=`T`)=>({reclamant:{type:null,id:null},provenance:e,lignes:[{...S(),cibleMode:`contrat`,patrimoine:x(),description:``}]}),ne=e=>e?.id??e??null,re=e=>{if(!e)return`Cible non définie`;let t=[e.commune,e.entree,e.libelleModule].filter(Boolean);return e.etage!=null&&!e.libelleModule&&t.push(`Étage ${e.etage}`),t.length?t.join(` — `):`Cible non définie`},ie=e=>!!e&&(e.idModule!=null||e.idEntree!=null),ae=(e,t)=>e.cibleMode===`demande`||!e.cibleOverride&&e.patrimoine==null?!0:e.cibleMode===`contrat`?!!(e.contratReclamant&&t||e.contratCible)&&e.patrimoine?.idModule!=null:e.modulePrecis?e.patrimoine?.idModule!=null:ie(e.patrimoine),oe=(e,t)=>e.description==null?!t:e.description.trim().length>0,T=(e={})=>{let t={...S(),...e};return e.patrimoine&&(t.patrimoine={...x(),...e.patrimoine}),t},se=e=>{let t=w();if(!e)return t;let n=Array.isArray(e.lignes)&&e.lignes.length?e.lignes:null;return{...t,...e,reclamant:{...t.reclamant,...e.reclamant??{}},provenance:e.provenance??t.provenance,lignes:n?n.map((e,n)=>n===0?{...t.lignes[0],...T(e)}:T(e)):t.lignes}};function ce({reclamants:e,modules:t,idModulePrefere:r=(0,n.ref)(null),readonly:i=(0,n.ref)(!1)}={}){let a=(0,n.reactive)(w()),o=(0,n.computed)(()=>{let e=(0,n.unref)(i);return e===!0?C:Array.isArray(e)?e:[]}),s=e=>o.value.includes(e),c=(0,n.computed)(()=>a.lignes[0]),l=(0,n.computed)(()=>a.lignes.slice(1)),u=(0,n.computed)(()=>(0,n.unref)(e)??[]),d=(0,n.ref)(null),f=(e,t)=>e.type===t.type&&String(e.id)===String(t.id),p=(0,n.computed)(()=>{let e=d.value;return!e||u.value.some(t=>f(t,e))?u.value:[...u.value,e]}),m=(0,n.computed)(()=>p.value.find(e=>f(e,a.reclamant))??p.value[0]??null),h=(0,n.computed)(()=>{let e=(0,n.unref)(t)??[],i=(0,n.unref)(r);return(i==null?null:e.find(e=>String(e.idModule)===String(i)))??e.find(e=>e.estModulePrincipal)??e[0]??null}),g=(0,n.computed)(()=>!!m.value&&!te.includes(m.value.type)),_={draft:a,lignePrincipale:c,lignesAssociees:l,reclamantsFournis:u,reclamantsDisponibles:p,reclamantSelectionne:m,moduleReclamantPrincipal:h,reclamantEstContrat:g,ciblesValid:(0,n.computed)(()=>a.lignes.every(e=>ae(e,g.value))),detailsValid:(0,n.computed)(()=>a.lignes.every((e,t)=>oe(e,t===0))),isReadonly:s,reset(e=null){let t=se(e);Object.assign(a,t),a.lignes=t.lignes},setProvenance(e){a.provenance=e},syncReclamant(){let e=m.value;_.setReclamant({type:e?.type??null,id:e?.id??null})},selectReclamant(e){e&&(u.value.some(t=>f(t,e))||(d.value=e),_.setReclamant(e))},setReclamant({type:e,id:t}){if(a.reclamant={type:e??null,id:t??null},s(`cible`))return;let n=a.lignes[0];e===`D`?(n.cibleMode=`demande`,n.patrimoine=null):(n.cibleMode=g.value?`contrat`:`patrimoine`,n.contratReclamant=g.value,n.contratCible=null,n.reprendreLocataireActuel=!1,n.patrimoine=x(),_.prefillCiblePrincipale())},prefillCiblePrincipale(){if(s(`cible`))return;let e=h.value;e&&_.prefillFromModule(0,e)},_resetAfterNomenclature(){a.lignes[0].responsable=null,a.lignes.splice(1)},setCategorie(e){let t=a.lignes[0];t.idCategorie=e,t.idType=null,t.idNature=null,t.idMotif=null,_._resetAfterNomenclature()},setType(e){let t=a.lignes[0];t.idType=e,t.idNature=null,t.idMotif=null,_._resetAfterNomenclature()},setNature(e){let t=a.lignes[0];t.idNature=e,t.idMotif=null,_._resetAfterNomenclature()},setMotif(e){a.lignes[0].idMotif=e,_._resetAfterNomenclature()},selectMotifChain(e){let t=a.lignes[0];t.idCategorie=e?.idCategorie??null,t.idType=e?.idType??null,t.idNature=e?.idNature??null,t.idMotif=e?.id??null,_._resetAfterNomenclature()},toggleLigneAssociee(e,t={}){let n=a.lignes.findIndex((t,n)=>n>0&&t.idMotif===e);n===-1?a.lignes.push({...S(),idMotif:e,...t}):a.lignes.splice(n,1)},_patrimoine(e){return a.lignes[e]?.patrimoine??null},setCibleMode(e,t){let n=a.lignes[e];n&&(n.cibleMode=t,n.reprendreLocataireActuel=!1,n.modulePrecis=!0,n.contratReclamant=t===`contrat`&&g.value,n.contratCible=null,t===`demande`?n.patrimoine=null:n.patrimoine??=x())},setModulePrecis(e,t){let n=a.lignes[e];n&&(n.modulePrecis=!!t,n.modulePrecis||_.setPatrimoineModule(e,null))},toggleContratReclamant(e,t){let n=a.lignes[e];n&&(n.contratReclamant=t??!n.contratReclamant,n.contratCible=null,n.patrimoine&&_.setPatrimoineModule(e,null))},setContratCible(e,t){let n=a.lignes[e];n&&(n.contratCible=t?{typeContrat:t.typeContrat,idContrat:t.idContrat,libelle:t.libelle??null}:null,_.setPatrimoineModule(e,null))},setPatrimoineCommune(e,t){let n=_._patrimoine(e);n&&(n.idCommune=t?.idCommune??null,n.commune=t?.commune??null,_.setPatrimoineEntree(e,null))},setPatrimoineEntree(e,t){let n=_._patrimoine(e);n&&(n.idEntree=t?.idEntree??null,n.entree=t?.entree??null,n.codeProgramme=t?.codeProgramme??null,n.codeTranche=t?.codeTranche??null,n.codeBatiment=t?.codeBatiment??null,n.codeEscalier=t?.codeEscalier??null,n.etage=null,_.setPatrimoineModule(e,null))},setPatrimoineEtage(e,t){let n=_._patrimoine(e);n&&(n.etage=t,_.setPatrimoineModule(e,null))},setPatrimoineModule(e,t){let n=_._patrimoine(e);n&&(n.idModule=t?.idModule??null,n.libelleModule=t?.libelleModule??null,n.typeContratActuel=t?.typeContratActuel??null,n.idContratActuel=t?.idContratActuel??null,n.occupantActuel=t?.occupantActuel??null,t&&(n.codeProgramme=t.codeProgramme??n.codeProgramme,n.codeTranche=t.codeTranche??n.codeTranche,n.codeBatiment=t.codeBatiment??n.codeBatiment,n.codeEscalier=t.codeEscalier??n.codeEscalier,t.idEntree!=null&&(n.idEntree=t.idEntree),t.etage!=null&&(n.etage=t.etage)))},prefillFromModule(e,t){let n=_._patrimoine(e);n&&t&&(n.idCommune=t.idCommune??null,n.commune=t.commune??null,n.idEntree=t.idEntree??null,n.entree=t.adresse??t.numeroRue??null,n.codeProgramme=t.codeProgramme??null,n.codeTranche=t.codeTranche??null,n.codeBatiment=t.codeBatiment??null,n.codeEscalier=t.codeEscalier??null,n.etage=t.etage??null,n.idModule=t.idModule??null,n.libelleModule=t.libelleModule??t.adresse??null,n.typeContratActuel=t.typeContratActuel??null,n.idContratActuel=t.idContratActuel??null,n.occupantActuel=t.occupantActuel??null)},toggleCibleOverride(e){let t=a.lignes[e];if(!t)return;let n=a.lignes[0];t.cibleOverride?(t.cibleOverride=!1,t.cibleMode=null,t.patrimoine=null,t.reprendreLocataireActuel=!1,t.modulePrecis=!0,t.contratReclamant=!0,t.contratCible=null):(t.cibleOverride=!0,t.cibleMode=n.cibleMode,t.patrimoine=n.cibleMode===`demande`?null:{...n.patrimoine},t.reprendreLocataireActuel=n.reprendreLocataireActuel,t.modulePrecis=n.modulePrecis,t.contratReclamant=n.contratReclamant,t.contratCible=n.contratCible?{...n.contratCible}:null)},setReprendreLocataireActuel(e,t){let n=a.lignes[e];n&&(n.reprendreLocataireActuel=!!t)},setDescription(e,t){let n=a.lignes[e];n&&(n.description=t)},setDateFaits(e,t){let n=a.lignes[e];n&&(n.dateFaits=t)},setResponsable(e,t){let n=a.lignes[e];n&&(n.responsable=t)},setFichier(e,t){let n=a.lignes[e];n&&(n.fichier=t)},toggleDescriptionOverride(e){let t=a.lignes[e];t&&(t.description=t.description==null?``:null)},toggleDateFaitsOverride(e){let t=a.lignes[e];t&&(t.dateFaitsOverride=!t.dateFaitsOverride,t.dateFaits=t.dateFaitsOverride?a.lignes[0].dateFaits:null)},_patrimoinePayload(e){return e.idModule==null?{idProgramme:e.codeProgramme,idTranche:e.codeTranche,idBatiment:e.codeBatiment,idEscalier:e.codeEscalier,etage:e.etage}:{idModule:e.idModule}},_lignePayload(e,t){let n=a.lignes[0],r=t>0&&!e.cibleOverride?n:e,i=(e.description??``).trim()||(n.description??``).trim(),o=e.dateFaits==null?n.dateFaits:e.dateFaits,s=a.reclamant.type===`D`,c={categorie:e.idCategorie,type:e.idType,nature:e.idNature,motif:e.idMotif,description:i,dateFaits:o,responsable:ne(e.responsable)};if(r.cibleMode===`demande`)return{...c,codeTypeCible:`D`,idCible:a.reclamant.id,deduireCible:!1};let l=_._patrimoinePayload(r.patrimoine);if(r.cibleMode===`contrat`&&!r.reprendreLocataireActuel){let e=r.contratReclamant&&g.value?{typeContrat:a.reclamant.type,idContrat:a.reclamant.id}:r.contratCible;return{...c,patrimoine:l,codeTypeCible:e?.typeContrat??null,idCible:e?.idContrat??null,deduireCible:!1}}return{...c,patrimoine:l,codeTypeCible:null,idCible:null,deduireCible:r.patrimoine?.idModule!=null&&!s}},cibleResume(e){let t=a.lignes[0],n=e!==t&&!e.cibleOverride?t:e;if(n.cibleMode===`demande`)return`La demande`;let r=re(n.patrimoine);if(n.cibleMode===`patrimoine`&&!n.modulePrecis)return`Parties communes — ${r}`;if(n.cibleMode!==`contrat`)return r;let i=`Contrat non défini`;if(n.contratReclamant&&g.value)i=`Contrat du réclamant`;else if(n.contratCible){let e=n.contratCible;i=`${e.libelle??`Contrat`} (${e.typeContrat}/${e.idContrat})`}return`${i} — ${r}`},lignesPayload(){return a.lignes.map((e,t)=>_._lignePayload(e,t))},creationPayload(){let e=m.value;return{typeReclamant:e?.type??null,reclamant:e?.id??null,lignes:_.lignesPayload(),provenance:a.provenance}}};return(0,n.reactive)(_)}function le(e){return(0,n.provide)(b,e),e}function E(){let e=(0,n.inject)(b,null);if(!e)throw Error(`useSollicitationDraft() hors de <creer-sollicitation-form>`);return e}var D=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},ue={name:`AsideBlock`,components:{AmsomNavTabsHorizontal:r.AmsomNavTabsHorizontal},props:{nbSimilaires:{type:Number,default:0}},setup(){return{draft:E()}},data(){return{activeTab:null}},computed:{lignePrincipale(){return this.draft.lignePrincipale},scope(){let e=this.lignePrincipale,t=e?.cibleMode===`demande`;return{idMotif:e?.idMotif??null,codeProgramme:t?null:e?.patrimoine?.codeProgramme??null,idCible:t?this.draft.draft.reclamant?.id??null:null,reclamant:this.draft.reclamantSelectionne}},tabs(){return[...this.$slots.similaires?[{id:`similarite`,label:`Similarité`,icon:`layer-group`}]:[],...this.$slots.evenements?[{id:`evenements`,label:`Événements`,icon:`circle-exclamation`}]:[]]}},watch:{tabs:{immediate:!0,handler(e){e.some(e=>e.id===this.activeTab)||(this.activeTab=e[0]?.id??null)}}}},de={key:0,class:`badge bg-danger ms-1`},fe={style:{"min-height":`320px`}},pe={key:0},me={key:1};function he(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`font-awesome-icon`),c=(0,n.resolveComponent)(`amsom-nav-tabs-horizontal`);return o.tabs.length?((0,n.openBlock)(),(0,n.createBlock)(c,{key:0,modelValue:a.activeTab,"onUpdate:modelValue":t[0]||=e=>a.activeTab=e,items:o.tabs,"item-key":`id`,"tab-spacing":1},{libelle:(0,n.withCtx)(({item:e})=>[(0,n.createVNode)(s,{icon:e.icon},null,8,[`icon`]),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.label),1),e.id===`similarite`&&r.nbSimilaires>0?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,de,(0,n.toDisplayString)(r.nbSimilaires),1)):(0,n.createCommentVNode)(``,!0)]),content:(0,n.withCtx)(()=>[(0,n.createElementVNode)(`div`,fe,[e.$slots.similaires?(0,n.withDirectives)(((0,n.openBlock)(),(0,n.createElementBlock)(`div`,pe,[(0,n.renderSlot)(e.$slots,`similaires`,(0,n.normalizeProps)((0,n.guardReactiveProps)(o.scope)))],512)),[[n.vShow,a.activeTab===`similarite`]]):(0,n.createCommentVNode)(``,!0),e.$slots.evenements?(0,n.withDirectives)(((0,n.openBlock)(),(0,n.createElementBlock)(`div`,me,[(0,n.renderSlot)(e.$slots,`evenements`)],512)),[[n.vShow,a.activeTab===`evenements`]]):(0,n.createCommentVNode)(``,!0)])]),_:3},8,[`modelValue`,`items`])):(0,n.createCommentVNode)(``,!0)}var ge=D(ue,[[`render`,he]]),O={baseUrl:``,getToken:()=>s.default.getToken(),setToken:e=>s.default.setToken(e),logout:()=>s.default.logout(),goToLoginPage:()=>s.default.goToLoginPage()};function _e(e={}){Object.assign(O,e)}var k=()=>O;function ve(e,t={}){let n=k(),r={getToken:()=>n.getToken?.()??null,setToken:e=>n.setToken?.(e),logout:()=>n.logout?.(),errorsHandlers:{default:({error:e,reject:t})=>{console.error(`Erreur API (cresol):`,e),t(e)},401:({error:e,overlayConfig:t,reject:r})=>{t.allowRedirect&&n.goToLoginPage?.(),r(e)},498:({error:e,overlayConfig:t,reject:r})=>{t.allowRedirect&&n.goToLoginPage?.(),r(e)}}};return t.functions={...r,...t.functions??{}},t.functions.errorsHandlers={...r.errorsHandlers,...t.functions.errorsHandlers??{}},(0,o.default)(e,t)}var ye=(e,t)=>{let n=t||k().baseUrl;if(!n)throw Error(`Cresol : baseUrl non renseignée (configureCresol ou prop baseUrl)`);return`${n}${e}`},be=(e={})=>{let t=new URLSearchParams;Object.entries(e).forEach(([e,n])=>{n!=null&&n!==``&&t.append(e,typeof n==`object`?JSON.stringify(n):n)});let n=t.toString();return n?`?${n}`:``},A=({method:e,path:t,params:n,data:r,signal:i,baseUrl:a},o={})=>ve({url:ye(`${t}${be(n)}`,a),method:e,...r===void 0?{}:{data:r},...i?{signal:i}:{}},o),j=(e,{params:t,signal:n,overlay:r,baseUrl:i}={})=>A({method:`GET`,path:e,params:t,signal:n,baseUrl:i},r).then(e=>e.data),M=(e,t,{params:n,signal:r,overlay:i,baseUrl:a}={})=>A({method:`POST`,path:e,params:n,data:t,signal:r,baseUrl:a},i).then(e=>e.data),xe={mustBeAuthenticated:!1},N=(e,{signal:t,baseUrl:n}={})=>j(e,{signal:t,baseUrl:n,overlay:xe}),Se=e=>N(`/v2/sollicitation/motifs`,e),Ce=e=>N(`/v2/sollicitation/categories`,e),we=e=>N(`/v2/sollicitation/types`,e),Te=e=>N(`/v2/sollicitation/natures`,e),Ee=e=>N(`/v2/sollicitation/etats`,e),De=({signal:e,baseUrl:t}={})=>j(`/collaborateurs`,{params:{actif:!0},signal:e,baseUrl:t}),Oe=async({signal:e,baseUrl:t}={})=>(await j(`/v2/patrimoine/communes`,{signal:e,baseUrl:t})??[]).map(e=>({idCommune:e.id,commune:e.libelle})),ke=(e,{signal:t,baseUrl:n}={})=>j(`/v2/patrimoine/entrees`,{params:{idCommune:e},signal:t,baseUrl:n}),Ae=(e,{signal:t,baseUrl:n}={})=>j(`/v2/patrimoine/modules`,{params:{codeProgramme:e},signal:t,baseUrl:n}),je=({idContrat:e,typeContrat:t},{signal:n,baseUrl:r}={})=>j(`/v2/patrimoine/contrat_modules`,{params:{idContrat:e,typeContrat:t},signal:n,baseUrl:r}),Me=({motif:e,categorie:t,type:n,nature:r},{signal:i,baseUrl:a}={})=>j(`/v2/sollicitation/responsables`,{params:{motif:e,categorie:t,type:n,nature:r},signal:i,baseUrl:a}),Ne=(e,{signal:t,baseUrl:n}={})=>j(`/v2/patrimoine/contrat_module_rechercher`,{params:{recherche:e},signal:t,baseUrl:n}),Pe=({categorie:e,recherche:t},{signal:n,baseUrl:r}={})=>j(`/v2/cresol/reclamant_rechercher`,{params:{categorie:e,recherche:t},signal:n,baseUrl:r});function P(e){let t=e?.response?.data;return t?.error?t.error:t?.errorList?t.errorList.map(e=>e.message).join(`, `):e?.response?.status===500?`Erreur interne`:e?.response?.status===401?`Non autorisé à faire cette action`:`Erreur`}var F=e=>e?.name===`AbortError`||e?.name===`CanceledError`,I=Symbol(`cresol:data`),Fe=()=>({motifs:null,categories:null,types:null,natures:null,etats:null,collaborateurs:null,communes:null,adressesByCommune:{},modulesByProgramme:{},modulesByContrat:{},responsablesByMotif:{}}),L=new Map,Ie=e=>(L.has(e)||L.set(e,(0,n.reactive)(Fe())),L.get(e)),R=new Map;function Le(){L.clear(),R.clear()}var z=(e,t,n)=>e?.find(e=>e[t]===n)?.libelle??n,B=(e,t,n)=>e?.find(e=>e[t]===n)?.icon??null;function Re({onError:e,baseUrl:t}={}){let r=(0,n.ref)(0),i=()=>({baseUrl:(0,n.unref)(t)||null}),a=()=>(0,n.unref)(t)||k().baseUrl||``,o=()=>Ie(a()),s=(t,n)=>{let i=`${a()}|${t}`;if(R.has(i))return R.get(i);r.value+=1;let o=Promise.resolve().then(n).catch(t=>(F(t)||e?.(P(t)),null)).finally(()=>{--r.value,R.delete(i)});return R.set(i,o),o},c=(e,t)=>o()[e]?.length?Promise.resolve(o()[e]):s(`referentiel:${e}`,async()=>(o()[e]=await t(i()),o()[e])),l={get cache(){return o()},loading:r,isLoading:(0,n.computed)(()=>r.value>0),loadNomenclature(){return Promise.all([c(`motifs`,Se),c(`categories`,Ce),c(`types`,we),c(`natures`,Te),c(`etats`,Ee)])},loadCollaborateurs:()=>c(`collaborateurs`,De),loadCommunes(){return o().communes?.length?Promise.resolve(o().communes):s(`communes`,async()=>(o().communes=await Oe(i()),o().communes))},loadAdresses(e){return e==null?Promise.resolve([]):o().adressesByCommune[e]?Promise.resolve(o().adressesByCommune[e]):s(`adresses:${e}`,async()=>{let t=await ke(e,i());return o().adressesByCommune[e]=t??[],t})},loadModulesOfProgramme(e){return e==null?Promise.resolve([]):o().modulesByProgramme[e]?Promise.resolve(o().modulesByProgramme[e]):s(`modules:${e}`,async()=>{let t=await Ae(e,i());return o().modulesByProgramme[e]=t??[],t})},loadModulesOfContrat({idContrat:e,typeContrat:t}){if(e==null)return Promise.resolve([]);let n=`${t??``}|${e}`;return o().modulesByContrat[n]?Promise.resolve(o().modulesByContrat[n]):s(`contratModules:${n}`,async()=>{let r=await je({idContrat:e,typeContrat:t},i());return o().modulesByContrat[n]=r??[],r})},async searchContrats(e,{signal:t}={}){let n=(e??``).trim();if(!n)return[];let r=await Ne(n,{...i(),signal:t}),a=new Map;for(let e of r??[]){let t=`${e.typeContrat}|${e.idContrat}`;(!a.has(t)||e.estModulePrincipal)&&a.set(t,{typeContrat:e.typeContrat,idContrat:e.idContrat,libelle:e.libelle??null,adresse:e.adresse??null,commune:e.commune??null,estSorti:!!e.estContratSorti,nbModules:e.nbModulesContrat??1})}return[...a.values()].sort((e,t)=>Number(e.estSorti)-Number(t.estSorti)||(e.libelle??``).localeCompare(t.libelle??``))},async searchReclamants(e,t,{signal:n}={}){let r=(t??``).trim();if(!r)return[];let a=await Pe({categorie:e,recherche:r},{...i(),signal:n}),o=new Map;for(let t of a??[]){let n=`${t.typeReclamant}|${t.idReclamant}`;o.has(n)||o.set(n,{type:t.typeReclamant,id:t.idReclamant,categorie:t.categorie?.toLowerCase()??e,libelleReclamant:t.libelleReclamant,adresse:t.adresse,estActif:!1,individus:[]});let r=o.get(n);r.estActif||=!!t.estActif,r.individus.push(t)}return[...o.values()].sort((e,t)=>Number(t.estActif)-Number(e.estActif)).map(e=>{let t=e.individus.map(e=>[e.nom,e.prenom].filter(Boolean).join(` `)).filter(Boolean).join(`, `),n={locataire:`${e.libelleReclamant||t} — Contrat ${e.type}/${e.id}`,demandeur:`${t} — ${e.libelleReclamant}`}[e.categorie];return{...e,libelle:n??e.libelleReclamant}})},loadResponsables({motif:e,categorie:t,type:n,nature:r}){return e==null?Promise.resolve([]):o().responsablesByMotif[e]?Promise.resolve(o().responsablesByMotif[e]):s(`responsables:${e}`,async()=>{let a=await Me({motif:e,categorie:t,type:n,nature:r},i());return o().responsablesByMotif[e]=a??[],a})},adressesOfCommune:e=>o().adressesByCommune[e]??null,modulesOfProgramme:e=>o().modulesByProgramme[e]??null,modulesOfContrat:({idContrat:e,typeContrat:t})=>o().modulesByContrat[`${t??``}|${e}`]??null,allAdresses:()=>Object.values(o().adressesByCommune).flat(),getResponsableSuggere({idMotif:e,codeProgramme:t,codeTranche:n,codeBatiment:r,codeEscalier:i}){let a=o().responsablesByMotif[e];if(!a?.length||t==null)return null;let s=a.filter(e=>String(e.codeProgramme)===String(t)&&(e.codeTranche==null||e.codeTranche===n)&&(e.codeBatiment==null||e.codeBatiment===r)&&(e.codeEscalier==null||e.codeEscalier===i));if(!s.length)return null;let c=e=>(e.codeEscalier==null?0:4)+(e.codeBatiment==null?0:2)+(e.codeTranche==null?0:1),l=s.reduce((e,t)=>c(t)>c(e)?t:e);return{idResponsable:l.idResponsable,libelle:l.libelleResponsable}},motifLibelle:e=>z(o().motifs,`id`,e),categorieLibelle:e=>z(o().categories,`id`,e),typeLibelle:e=>z(o().types,`id`,e),natureLibelle:e=>z(o().natures,`id`,e),etatLibelle:e=>z(o().etats,`code`,e),motifIcon:e=>B(o().motifs,`id`,e),categorieIcon:e=>B(o().categories,`id`,e),typeIcon:e=>B(o().types,`id`,e),natureIcon:e=>B(o().natures,`id`,e)};return(0,n.reactive)(l)}function ze(e){return(0,n.provide)(I,e),e}function V(){let e=(0,n.inject)(I,null);if(!e)throw Error(`useCresolData() hors de <creer-sollicitation-form>`);return e}var Be=e=>`fa`+e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);async function H(e){let t=await import(`@fortawesome/free-solid-svg-icons`);[...new Set(e.filter(Boolean))].forEach(e=>{let n=t[Be(e)];n&&c.library.add(n)})}var U=[{key:`locataire`,label:`Locataire`,icon:`house-user`,recherche:`Rechercher un locataire`,aucun:`Aucun locataire trouvé.`,placeholder:`Nom, prénom, n° de contrat, adresse, téléphone ou mail…`},{key:`demandeur`,label:`Demandeur`,icon:`hourglass-half`,recherche:`Rechercher un demandeur`,aucun:`Aucun demandeur trouvé.`,placeholder:`Nom, prénom, n° de demande ou unique, téléphone ou mail…`},{key:`tiers`,label:`Tiers`,icon:`user-tie`,recherche:`Rechercher un tiers`,aucun:`Aucun tiers trouvé.`,placeholder:`Raison sociale, adresse, téléphone ou mail…`},{key:`autre`,label:`Autre`,icon:`user`,recherche:`Rechercher un individu « Autre »`,aucun:`Aucun individu « Autre » trouvé.`,placeholder:`Nom, prénom, adresse, téléphone ou mail…`},{key:`tout`,label:`Tout`,icon:`magnifying-glass`,recherche:`Rechercher parmi tous les réclamants`,aucun:`Aucun réclamant trouvé.`,placeholder:`Nom, prénom, n° de contrat ou de demande, adresse, téléphone ou mail…`}],W={signataire:`Signataire`,occupant:`Occupant`,demandeur:`Demandeur`},G=e=>e?e.categorie?e.categorie:{D:`demandeur`,T:`tiers`,U:`autre`}[e.type]??`locataire`:null,Ve={name:`ReclamantRechercheBlock`,components:{AmsomAutocomplete:a.AmsomAutocomplete},setup(){return{draft:E(),data:V()}},data(){return{iconsReady:!1,categorie:G(this.draft.reclamantSelectionne)??`locataire`,trouves:[],rechercheEnCours:!1,rechercheFaite:!1}},computed:{categories(){return U},categorieCourante(){return U.find(e=>e.key===this.categorie)},selectionne(){return this.draft.reclamantSelectionne},selectedTrouve:{get(){return this.categorie===`tout`||G(this.selectionne)===this.categorie?this.selectionne:null},set(e){this.select(e)}}},async created(){await H(U.map(e=>e.icon)),this.iconsReady=!0},beforeUnmount(){clearTimeout(this.rechercheTimeout),this.controller?.abort()},methods:{select(e){e&&(this.draft.selectReclamant(e),this.categorie!==`tout`&&(this.categorie=G(e)))},setCategorie(e){e!==this.categorie&&(this.categorie=e,clearTimeout(this.rechercheTimeout),this.controller?.abort(),this.trouves=[],this.rechercheEnCours=!1,this.rechercheFaite=!1)},rechercherPlusTard(e){clearTimeout(this.rechercheTimeout),this.rechercheTimeout=setTimeout(()=>this.rechercher(e),400)},rechercher(e){let t=(e??``).trim();t.length<2?(this.trouves=[],this.rechercheEnCours=!1,this.rechercheFaite=!1):(this.controller?.abort(),this.controller=new AbortController,this.rechercheEnCours=!0,this.data.searchReclamants(this.categorie,t,{signal:this.controller.signal}).then(e=>{this.trouves=e??[],this.rechercheFaite=!0,this.rechercheEnCours=!1}).catch(()=>{this.rechercheEnCours=!1}))},cleReclamant(e){return e?`${e.type}|${e.id}`:null},categorieOf:G,iconOf(e){return U.find(t=>t.key===G(e))?.icon??`user`},nomsOf(e){return(e?.individus??[]).map(e=>[e.nom,e.prenom].filter(Boolean).join(` `)).filter(Boolean).join(`, `)},titreOf(e){if(!e?.individus)return e?.libelle??``;let t=G(e);return t===`locataire`?e.libelleReclamant||this.nomsOf(e):t===`demandeur`?this.nomsOf(e):e.libelleReclamant},referenceOf(e){if(!e?.individus)return``;let t=G(e);return t===`locataire`?`Contrat ${e.type}/${e.id}`:t===`demandeur`?e.libelleReclamant:t===`autre`?`Individu « Autre »`:`Tiers`},detailOf(e){let t=e?.individus??[];if([`tiers`,`autre`].includes(G(e))){let e=t[0];return e?[e.telephone,e.mail].filter(Boolean).join(` — `):``}return t.map(e=>{let t=[e.nom,e.prenom].filter(Boolean).join(` `);return W[e.role]?`${t} (${W[e.role].toLowerCase()})`:t}).join(`, `)}}},He={key:0,class:`d-flex flex-column gap-3`},Ue={class:`d-flex flex-wrap gap-2`},We=[`onClick`],Ge={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},Ke={class:`min-w-0`},qe={key:0,class:`badge bg-warning-subtle text-warning-emphasis ms-1`},Je={class:`text-muted d-block text-truncate`},Ye={key:0},Xe={key:0,class:`text-muted d-block text-truncate`},Ze={key:0,class:`text-muted`};function Qe(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`font-awesome-icon`),c=(0,n.resolveComponent)(`amsom-autocomplete`);return a.iconsReady?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,He,[(0,n.createElementVNode)(`div`,null,[t[1]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Le réclamant est… `,-1),(0,n.createElementVNode)(`div`,Ue,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.categories,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.key,type:`button`,class:(0,n.normalizeClass)([`btn btn-sm d-inline-flex align-items-center gap-2`,a.categorie===e.key?`btn-primary`:`btn-outline-primary`]),onClick:t=>o.setCategorie(e.key)},[(0,n.createVNode)(s,{icon:e.icon,"fixed-width":``},null,8,[`icon`]),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.label),1)],10,We))),128))])]),(0,n.createElementVNode)(`div`,null,[(0,n.createElementVNode)(`label`,Ge,(0,n.toDisplayString)(o.categorieCourante.recherche),1),((0,n.openBlock)(),(0,n.createBlock)(c,{key:a.categorie,modelValue:o.selectedTrouve,"onUpdate:modelValue":t[0]||=e=>o.selectedTrouve=e,items:a.trouves,"filtering-function":({items:e})=>e,loading:a.rechercheEnCours,"get-id":o.cleReclamant,"get-input-libelle":e=>e?.libelle??``,placeholder:o.categorieCourante.placeholder,"input-size":`sm`,"hide-choices":``,"debounce-delay":0,onSearch:o.rechercherPlusTard},{options:(0,n.withCtx)(e=>[(0,n.createElementVNode)(`div`,Ke,[(0,n.createElementVNode)(`div`,{class:(0,n.normalizeClass)([`fw-medium text-truncate`,e?.estActif?``:`text-muted`])},[(0,n.createTextVNode)((0,n.toDisplayString)(o.titreOf(e))+` `,1),e?.estActif?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`span`,qe,(0,n.toDisplayString)(o.categorieOf(e)===`demandeur`?`inactive`:`sorti`),1))],2),(0,n.createElementVNode)(`small`,Je,[(0,n.createTextVNode)((0,n.toDisplayString)(o.referenceOf(e))+` `,1),e?.adresse?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,Ye,` — `+(0,n.toDisplayString)(e.adresse),1)):(0,n.createCommentVNode)(``,!0)]),o.detailOf(e)?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,Xe,(0,n.toDisplayString)(o.detailOf(e)),1)):(0,n.createCommentVNode)(``,!0)])]),_:1},8,[`modelValue`,`items`,`filtering-function`,`loading`,`get-id`,`get-input-libelle`,`placeholder`,`onSearch`])),a.rechercheFaite&&!a.rechercheEnCours&&!a.trouves.length?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,Ze,(0,n.toDisplayString)(o.categorieCourante.aucun),1)):(0,n.createCommentVNode)(``,!0)])])):(0,n.createCommentVNode)(``,!0)}var $e=D(Ve,[[`render`,Qe]]),et={name:`ProvenanceSelecteurBlock`,setup(){return{draft:E()}},computed:{provenances(){return y},selected(){return this.draft.draft.provenance},provenanceChoisie(){return this.provenances.find(e=>e.id===this.selected)??null}}},tt={key:0,class:`fs-7 text-muted`},nt={class:`fw-medium`},rt={key:1},it={class:`d-flex flex-wrap gap-2`},at=[`onClick`],ot={key:0,class:`fs-7 text-danger mt-1`};function st(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`font-awesome-icon`);return i.draft.isReadonly(`provenance`)?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,tt,[t[0]||=(0,n.createTextVNode)(` Provenance du contact : `,-1),(0,n.createElementVNode)(`span`,nt,[o.provenanceChoisie?.icon?((0,n.openBlock)(),(0,n.createBlock)(s,{key:0,icon:o.provenanceChoisie.icon,"fixed-width":``},null,8,[`icon`])):(0,n.createCommentVNode)(``,!0),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(o.provenanceChoisie?.libelle??`—`),1)])])):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,rt,[t[1]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},[(0,n.createTextVNode)(` Provenance du contact `),(0,n.createElementVNode)(`span`,{class:`text-danger`},`*`)],-1),(0,n.createElementVNode)(`div`,it,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.provenances,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.id,type:`button`,class:(0,n.normalizeClass)([`btn btn-sm d-inline-flex align-items-center gap-2`,e.id===o.selected?`btn-primary`:`btn-outline-primary`]),onClick:t=>i.draft.setProvenance(e.id)},[(0,n.createVNode)(s,{icon:e.icon,"fixed-width":``},null,8,[`icon`]),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.libelle),1)],10,at))),128))]),o.selected?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ot,` Sélectionnez par quel canal la sollicitation vous est parvenue. `))]))}var K=D(et,[[`render`,st]]),ct={name:`EtapeReclamantBlock`,components:{ReclamantRechercheBlock:$e,ProvenanceSelecteurBlock:K},props:{premiere:{type:Boolean,default:!1}},setup(){return{draft:E()}}},lt={class:`d-flex flex-column gap-3`},ut={class:`alert alert-light border py-2 px-3 mb-0 fs-7`};function dt(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`provenance-selecteur-block`),c=(0,n.resolveComponent)(`font-awesome-icon`),l=(0,n.resolveComponent)(`reclamant-recherche-block`);return(0,n.openBlock)(),(0,n.createElementBlock)(`div`,lt,[r.premiere?((0,n.openBlock)(),(0,n.createBlock)(s,{key:0})):(0,n.createCommentVNode)(``,!0),(0,n.renderSlot)(e.$slots,`reclamant`,{reclamant:i.draft.reclamantSelectionne,select:i.draft.selectReclamant},()=>[(0,n.createElementVNode)(`div`,ut,[(0,n.createVNode)(c,{icon:`user`,class:`text-primary me-2`}),t[0]||=(0,n.createTextVNode)(` Pour qui cette sollicitation est-elle créée\xA0? `,-1)]),(0,n.createVNode)(l)])])}var ft=D(ct,[[`render`,dt]]),q=Symbol(`cresol:options`),pt=e=>(0,n.provide)(q,e),J=()=>(0,n.inject)(q,{});function Y(e,t=!0){if(!e)return null;let n=e.toString().normalize(`NFD`).replace(/[̀-ͯ]/g,``);return t?n.toLowerCase():n}var mt={name:`ReclamantSelecteurBlock`,components:{AmsomAutocomplete:a.AmsomAutocomplete},props:{mode:{type:String,default:null},inline:{type:Boolean,default:!0}},setup(){return{draft:E(),options:J()}},computed:{reclamants(){return this.draft.reclamantsDisponibles},reclamantSelectionne(){return this.draft.reclamantSelectionne},presentation(){return this.mode??this.options.reclamantMode},estFige(){return this.reclamants.length<=1||this.draft.isReadonly(`reclamant`)}},methods:{reclamantId(e){let t=this.reclamants.indexOf(e);return t<0?null:t},select(e){this.draft.selectReclamant(e)},filterReclamants({search:e,items:t}){let n=(Y(e)??``).trim();return n?t.filter(e=>(Y(e?.libelle)??``).includes(n)):t}}},ht={key:0,class:`fs-7 text-muted`},gt={class:`fw-medium`},_t={key:0,class:`btn-group btn-group-sm`,role:`group`},vt=[`onClick`],yt=[`value`],bt=[`value`];function xt(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`amsom-autocomplete`);return o.estFige?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ht,[t[2]||=(0,n.createTextVNode)(` Réclamant : `,-1),(0,n.createElementVNode)(`span`,gt,(0,n.toDisplayString)(o.reclamantSelectionne?.libelle),1)])):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:1,class:(0,n.normalizeClass)(r.inline?`d-flex align-items-center justify-content-between gap-2 border-bottom pb-2`:`d-flex flex-column gap-1`)},[t[3]||=(0,n.createElementVNode)(`span`,{class:`fs-7 fw-semibold text-muted text-uppercase`},`Réclamant`,-1),o.presentation===`switch`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,_t,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.reclamants,(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:t,type:`button`,class:(0,n.normalizeClass)([`btn btn-sm py-0`,e===o.reclamantSelectionne?`btn-primary`:`btn-outline-primary`]),onClick:t=>o.select(e)},(0,n.toDisplayString)(e.libelle),11,vt))),128))])):o.presentation===`autocomplete`?((0,n.openBlock)(),(0,n.createBlock)(s,{key:1,"model-value":o.reclamantSelectionne,items:o.reclamants,"get-id":o.reclamantId,"get-input-libelle":e=>e?.libelle??``,"filtering-function":o.filterReclamants,placeholder:`Rechercher un réclamant…`,"input-size":`sm`,"hide-choices":``,class:(0,n.normalizeClass)(r.inline?``:`w-100`),"onUpdate:modelValue":t[0]||=e=>o.select(e)},null,8,[`model-value`,`items`,`get-id`,`get-input-libelle`,`filtering-function`,`class`])):((0,n.openBlock)(),(0,n.createElementBlock)(`select`,{key:2,class:(0,n.normalizeClass)([`form-select form-select-sm`,r.inline?`w-auto`:``]),value:o.reclamants.indexOf(o.reclamantSelectionne),onChange:t[1]||=e=>o.select(o.reclamants[e.target.value])},[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.reclamants,(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`option`,{key:t,value:t},(0,n.toDisplayString)(e.libelle),9,bt))),128))],42,yt))],2))}var St=D(mt,[[`render`,xt]]),Ct={name:`EtapeCategorieBlock`,components:{AmsomOverlay:t.AmsomOverlay,AmsomAutocomplete:a.AmsomAutocomplete,ReclamantSelecteurBlock:St,ProvenanceSelecteurBlock:K},props:{premiere:{type:Boolean,default:!1}},setup(){return{draft:E(),data:V(),options:J()}},data(){return{iconsReady:!1}},computed:{mainLigne(){return this.draft.lignePrincipale},motifFige(){return this.draft.isReadonly(`motif`)},activeMotifs(){return(this.data.cache.motifs??[]).filter(e=>!e.estDesactive).slice().sort((e,t)=>(e.categorie??``).localeCompare(t.categorie??``)||(e.type??``).localeCompare(t.type??``)||(e.nature??``).localeCompare(t.nature??``)||(e.libelle??``).localeCompare(t.libelle??``))},allowedMotifs(){let e=this.options.nomenclatureFilter;if(typeof e!=`function`)return this.activeMotifs;let t=this.draft.reclamantSelectionne;return this.activeMotifs.filter(n=>e(n,{reclamant:t}))},categoriesList(){return this.distinct(this.allowedMotifs,`idCategorie`,`categorie`,e=>this.data.categorieIcon(e))},typesList(){return this.mainLigne.idCategorie?this.distinct(this.allowedMotifs.filter(e=>e.idCategorie===this.mainLigne.idCategorie),`idType`,`type`,e=>this.data.typeIcon(e)):[]},naturesList(){return this.mainLigne.idType?this.distinct(this.allowedMotifs.filter(e=>e.idType===this.mainLigne.idType),`idNature`,`nature`,e=>this.data.natureIcon(e)):[]},motifsList(){return this.mainLigne.idNature?this.allowedMotifs.filter(e=>e.idNature===this.mainLigne.idNature).map(e=>({id:e.id,libelle:e.libelle,icon:e.icon})):[]},selectedMotif(){return this.mainLigne.idMotif?this.activeMotifs.find(e=>e.id===this.mainLigne.idMotif)??null:null},motifsAssocies(){let e=this.selectedMotif?.association;return e?Object.entries(e).map(([e,t])=>({libelle:e,idMotif:t})):[]},selectionChain(){let e=[];return this.mainLigne.idCategorie&&e.push({level:`categorie`,libelle:this.data.categorieLibelle(this.mainLigne.idCategorie),icon:this.data.categorieIcon(this.mainLigne.idCategorie)}),this.mainLigne.idType&&e.push({level:`type`,libelle:this.data.typeLibelle(this.mainLigne.idType),icon:this.data.typeIcon(this.mainLigne.idType)}),this.mainLigne.idNature&&e.push({level:`nature`,libelle:this.data.natureLibelle(this.mainLigne.idNature),icon:this.data.natureIcon(this.mainLigne.idNature)}),this.mainLigne.idMotif&&e.push({level:`motif`,libelle:this.data.motifLibelle(this.mainLigne.idMotif),icon:this.data.motifIcon(this.mainLigne.idMotif)}),e},currentLevel(){return this.mainLigne.idCategorie?this.mainLigne.idType?this.mainLigne.idNature?this.mainLigne.idMotif?null:{title:`Motif`,options:this.motifsList,select:e=>this.draft.setMotif(e)}:{title:`Nature`,options:this.naturesList,select:e=>this.draft.setNature(e)}:{title:`Type`,options:this.typesList,select:e=>this.draft.setType(e)}:{title:`Catégorie`,options:this.categoriesList,select:e=>this.draft.setCategorie(e)}},motifRecherche:{get(){return this.selectedMotif},set(e){let t=e&&typeof e==`object`?e:e?this.activeMotifs.find(t=>t.id===e):null;t?this.draft.selectMotifChain(t):this.draft.setCategorie(null)}}},async created(){await this.data.loadNomenclature(),await this.registerIcons(),this.iconsReady=!0},methods:{goBackTo(e){e===`categorie`?this.draft.setCategorie(null):e===`type`?this.draft.setType(null):e===`nature`?this.draft.setNature(null):e===`motif`&&this.draft.setMotif(null)},isActive(e){return this.draft.lignesAssociees.some(t=>t.idMotif===e)},toggleMotifAssocie(e){let t=this.activeMotifs.find(t=>t.id===e.idMotif);this.draft.toggleLigneAssociee(e.idMotif,{libelle:e.libelle,idCategorie:t?.idCategorie??null,idType:t?.idType??null,idNature:t?.idNature??null})},registerIcons(){return H([...this.data.cache.categories??[],...this.data.cache.types??[],...this.data.cache.natures??[],...this.activeMotifs].map(e=>e.icon))},filterMotifs({search:e,items:t}){let n=(Y(e)??``).trim();if(!n)return t;let r=n.split(/\s+/);return t.filter(e=>{let t=Y(`${e.libelle} ${e.categorie} ${e.type} ${e.nature}`)??``;return r.every(e=>t.includes(e))})},getMotifId(e){return e?e.id:null},getMotifInputLibelle(e){return e?e.libelle:``},distinct(e,t,n,r){let i=new Map;for(let a of e)a[t]!=null&&!i.has(a[t])&&i.set(a[t],{id:a[t],libelle:a[n]??a[t],icon:r?r(a[t]):null});return[...i.values()].sort((e,t)=>(e.libelle??``).localeCompare(t.libelle??``))},motifLibelleFromId(e){return this.activeMotifs.find(t=>t.id===e)?.libelle??e}}},wt={key:0,class:`d-flex flex-column gap-3`},Tt={key:2},Et={class:`d-flex flex-wrap align-items-center gap-2`},Dt={class:`badge rounded-pill bg-primary d-inline-flex align-items-center gap-2`},Ot={key:3},kt={class:`d-flex align-items-center gap-2`},At={class:`min-w-0`},jt={class:`fw-medium text-truncate`},Mt={class:`text-muted d-block text-truncate`},Nt={key:4,class:`d-flex align-items-center gap-2 text-muted fs-7`},Pt={key:5,class:`d-flex flex-wrap align-items-center gap-2`},Ft=[`onClick`],It={key:6},Lt={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-2`},Rt={class:`row justify-content-around g-3`},zt=[`title`,`onClick`],Bt={class:`fs-7 mt-1 lh-sm`},Vt={key:0,class:`col-12 text-muted fs-7`},Ht=[`id`,`checked`,`disabled`,`onChange`],Ut=[`for`];function Wt(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`provenance-selecteur-block`),c=(0,n.resolveComponent)(`reclamant-selecteur-block`),l=(0,n.resolveComponent)(`font-awesome-icon`),u=(0,n.resolveComponent)(`amsom-autocomplete`),d=(0,n.resolveComponent)(`amsom-overlay`);return(0,n.openBlock)(),(0,n.createBlock)(d,{loading:i.data.isLoading&&!i.data.cache.motifs||!a.iconsReady},{default:(0,n.withCtx)(()=>[a.iconsReady?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,wt,[r.premiere?((0,n.openBlock)(),(0,n.createBlock)(s,{key:0})):(0,n.createCommentVNode)(``,!0),i.options.reclamantMode===`step`?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createBlock)(c,{key:1})),o.motifFige&&o.selectionChain.length?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Tt,[t[1]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Motif`,-1),(0,n.createElementVNode)(`div`,Et,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.selectionChain,(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:e.level},[t>0?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,icon:`fa-solid fa-chevron-right`,class:`text-muted fs-7`})):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,Dt,[e.icon?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,icon:e.icon,"fixed-width":``},null,8,[`icon`])):(0,n.createCommentVNode)(``,!0),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(e.libelle),1)])],64))),128))])])):(0,n.createCommentVNode)(``,!0),o.motifFige?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Ot,[t[2]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Rechercher un motif `,-1),(0,n.createVNode)(u,{modelValue:o.motifRecherche,"onUpdate:modelValue":t[0]||=e=>o.motifRecherche=e,items:o.allowedMotifs,"get-id":o.getMotifId,"get-input-libelle":o.getMotifInputLibelle,"get-input-libelle-from-id":o.motifLibelleFromId,"filtering-function":o.filterMotifs,placeholder:`Rechercher (motif, catégorie, type, nature)…`,"input-size":`sm`,"hide-choices":``},{options:(0,n.withCtx)(e=>[(0,n.createElementVNode)(`div`,kt,[e?.icon?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,icon:e.icon,class:`text-primary`,"fixed-width":``},null,8,[`icon`])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,At,[(0,n.createElementVNode)(`div`,jt,(0,n.toDisplayString)(e?.libelle),1),(0,n.createElementVNode)(`small`,Mt,(0,n.toDisplayString)(e?.categorie)+` › `+(0,n.toDisplayString)(e?.type)+` › `+(0,n.toDisplayString)(e?.nature),1)])])]),_:1},8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`get-input-libelle-from-id`,`filtering-function`])])),o.motifFige?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Nt,[...t[3]||=[(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`},null,-1),(0,n.createElementVNode)(`span`,null,`ou sélection guidée`,-1),(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`},null,-1)]])),!o.motifFige&&o.selectionChain.length?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Pt,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.selectionChain,(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:e.level},[t>0?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,icon:`fa-solid fa-chevron-right`,class:`text-muted fs-7`})):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`button`,{type:`button`,class:`btn btn-sm btn-primary rounded-pill d-inline-flex align-items-center gap-2`,onClick:t=>o.goBackTo(e.level)},[e.icon?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,icon:e.icon,"fixed-width":``},null,8,[`icon`])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.libelle),1),(0,n.createVNode)(l,{icon:`fa-solid fa-xmark`,class:`fs-7 opacity-75`})],8,Ft)],64))),128))])):(0,n.createCommentVNode)(``,!0),!o.motifFige&&o.currentLevel?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,It,[(0,n.createElementVNode)(`label`,Lt,(0,n.toDisplayString)(o.currentLevel.title),1),(0,n.createElementVNode)(`div`,Rt,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.currentLevel.options,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:e.id,class:`col-3 text-center`},[(0,n.createElementVNode)(`button`,{type:`button`,class:`btn btn-lg btn-outline-primary btn-circle d-flex align-items-center justify-content-center mx-auto`,title:e.libelle,onClick:t=>o.currentLevel.select(e.id)},[e.icon?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,icon:e.icon,size:`lg`},null,8,[`icon`])):(0,n.createCommentVNode)(``,!0)],8,zt),(0,n.createElementVNode)(`div`,Bt,(0,n.toDisplayString)(e.libelle),1)]))),128)),o.currentLevel.options.length?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Vt,` Aucun choix disponible `))])])):(0,n.createCommentVNode)(``,!0),o.motifsAssocies.length?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:7},[t[4]||=(0,n.createElementVNode)(`div`,{class:`d-flex align-items-center gap-2 text-muted fs-7`},[(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`}),(0,n.createElementVNode)(`span`,null,`Autres motifs liés`),(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`})],-1),((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.motifsAssocies,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:e.idMotif,class:`form-check form-switch`},[(0,n.createElementVNode)(`input`,{id:`assoc-${e.idMotif}`,class:`form-check-input`,type:`checkbox`,checked:o.isActive(e.idMotif),disabled:o.motifFige,onChange:t=>o.toggleMotifAssocie(e)},null,40,Ht),(0,n.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`assoc-${e.idMotif}`},(0,n.toDisplayString)(e.libelle)+` ? `,9,Ut)]))),128))],64)):(0,n.createCommentVNode)(``,!0)])):(0,n.createCommentVNode)(``,!0)]),_:1},8,[`loading`])}var Gt=D(Ct,[[`render`,Wt]]),Kt={B:`briefcase`,M:`store`,W:`dungeon`,E:`user-graduate`,K:`building-shield`,F:`person-shelter`,S:`square-parking`,V:`hands-holding`};function qt(e,t=!1,n=`circle-question`){return e===`L`?t?`building`:`house`:Kt[e]??n}function Jt(e){return e?e.idCategorieModule===`L`?e.estCollectif?`Appartement`:`Maison`:e.categorieModule??``:``}var Yt=0,Xt={name:`CiblePickerBlock`,components:{AmsomAutocomplete:a.AmsomAutocomplete},props:{patrimoine:{type:Object,default:null},cibleMode:{type:String,default:`contrat`},reclamantModules:{type:Array,default:()=>[]},reclamantType:{type:String,default:null},contratReclamant:{type:Boolean,default:!0},contratCible:{type:Object,default:null},afficheCaseContratReclamant:{type:Boolean,default:!1},modulePrecis:{type:Boolean,default:!0},locataireActuelOption:{type:Object,default:null}},emits:[`change-mode`,`select-commune`,`select-adresse`,`select-etage`,`select-module`,`select-contrat`,`toggle-contrat-reclamant`,`toggle-reprendre-locataire-actuel`,`set-module-precis`],setup(){return{data:V()}},data(){return{uid:++Yt,rechercheContrat:``,contratsTrouves:[],rechercheEnCours:!1,rechercheFaite:!1}},computed:{availableModes(){return this.reclamantType===`D`?[{key:`demande`,label:`La demande`,icon:`hourglass`,aide:`Cible la demande elle-même (sans localisation).`}]:[{key:`contrat`,label:`Un contrat`,icon:`file-signature`,aide:`Cible un contrat et l’un de ses modules.`},{key:`patrimoine`,label:`Du patrimoine`,icon:`building`}]},currentMode(){return this.availableModes.find(e=>e.key===this.cibleMode)},portees(){return[{modulePrecis:!1,icon:`building`,titre:`Les parties communes`,aide:`Les espaces partagés de l’étage choisi`},{modulePrecis:!0,icon:`house`,titre:`Un module précis`,aide:`Un module voisin dans la résidence`}]},afficheModule(){return this.cibleMode===`contrat`||this.modulePrecis},contratModules(){return this.contratReclamant?this.reclamantModules:this.contratCible?this.data.modulesOfContrat(this.contratCible)??[]:[]},areModulesLocked(){return this.cibleMode===`contrat`?this.contratModules.length<=1:!this.patrimoine?.idEntree},adresses(){let e=this.patrimoine?.idCommune;return e==null?[]:this.data.adressesOfCommune(e)??[]},programmeModules(){let e=this.patrimoine?.codeProgramme;return e==null?[]:this.data.modulesOfProgramme(e)??[]},adresseModules(){let e=this.patrimoine?.idEntree;return e==null?[]:this.programmeModules.filter(t=>t.idEntree===e)},autresModules(){let e=this.patrimoine?.idEntree,t=Object.fromEntries(this.data.allAdresses().map(e=>[e.idEntree,e]));return this.programmeModules.map(n=>{let r=t[n.idEntree]?.entree??`Adresse ${n.idEntree}`;return{...n,_autreLibelle:n.idEntree===e&&n.etage!=null?`${r} — Étage ${n.etage}`:r}})},modules(){if(this.cibleMode===`contrat`)return this.contratModules.slice().sort((e,t)=>e.estModulePrincipal&&!t.estModulePrincipal?-1:!e.estModulePrincipal&&t.estModulePrincipal?1:t.dateDebut-e.dateDebut);let e=this.patrimoine?.etage,t=e==null?this.adresseModules:this.adresseModules.filter(t=>String(t.etage)===String(e)),n=new Set(t.map(e=>e.idModule));return[...t,...this.autresModules.filter(e=>!n.has(e.idModule))]},etages(){return[...new Set(this.adresseModules.map(e=>e.etage).filter(e=>e!=null))].sort((e,t)=>String(e).localeCompare(String(t),`fr`,{numeric:!0})).map(e=>({id:e,libelle:`Étage ${e}`}))},selectedContrat:{get(){let e=this.contratCible;return e?this.contratsTrouves.find(t=>String(t.idContrat)===String(e.idContrat)&&t.typeContrat===e.typeContrat)??{...e,libelle:e.libelle}:null},set(e){this.$emit(`select-contrat`,e??null)}},selectedCommune:{get(){let e=this.patrimoine?.idCommune;return e==null?null:(this.data.cache.communes||[]).find(t=>t.idCommune===e)??null},set(e){this.$emit(`select-commune`,e??null)}},selectedAdresse:{get(){let e=this.patrimoine?.idEntree;return e==null?null:this.adresses.find(t=>t.idEntree===e)??null},set(e){this.$emit(`select-adresse`,e??null)}},selectedEtage:{get(){let e=this.patrimoine?.etage;return e==null?null:this.etages.find(t=>t.id===e)??null},set(e){this.$emit(`select-etage`,e?.id??null)}},selectedModule:{get(){let e=this.patrimoine?.idModule;return e==null?null:this.modules.find(t=>t.idModule===e)??null},set(e){this.$emit(`select-module`,e??null)}}},watch:{modules:{immediate:!0,handler(e){this.cibleMode===`contrat`&&e.length===1&&this.patrimoine?.idModule==null&&this.$emit(`select-module`,e[0])}},contratReclamant(){this.contratsTrouves=[],this.rechercheFaite=!1}},beforeUnmount(){clearTimeout(this.rechercheTimeout),this.controller?.abort()},methods:{rechercherPlusTard(e){clearTimeout(this.rechercheTimeout),this.rechercheTimeout=setTimeout(()=>this.rechercherContrat(e),400)},rechercherContrat(e){let t=(e??``).trim();t.length<2?(this.contratsTrouves=[],this.rechercheEnCours=!1):(this.controller?.abort(),this.controller=new AbortController,this.rechercheEnCours=!0,this.data.searchContrats(t,{signal:this.controller.signal}).then(e=>{this.contratsTrouves=e??[],this.rechercheEnCours=!1}).catch(()=>{this.rechercheEnCours=!1}))},contratInputLibelle(e){return e?[e.libelle,`${e.typeContrat}/${e.idContrat}`].filter(Boolean).join(` — `):``},contratAdresse(e){return[e?.adresse,e?.commune].filter(Boolean).join(`, `)},filterOn(e){return({search:t,items:n})=>{let r=(Y(t)??``).trim();return r?n.filter(t=>(Y(t?.[e])??``).includes(r)):n}},filterModules({search:e,items:t}){let n=(Y(e)??``).trim();return n?t.filter(e=>(Y(this.moduleInputLibelle(e))??``).includes(n)||(Y(e?._autreLibelle)??``).includes(n)):t},getCategorieModuleIcon:qt,categorieLibelle:Jt,moduleLibelle(e){return e?e.libelleModule??e.adresse??`Module ${e.idModule}`:``},moduleInputLibelle(e){let t=this.categorieLibelle(e);return t?`${t} — ${this.moduleLibelle(e)}`:this.moduleLibelle(e)},isExit(e){return!!e?.dateFin&&e.dateFin<Math.floor(Date.now()/1e3)}}},Zt={class:`d-flex flex-column gap-3`},Qt={class:`btn-group w-100`,role:`group`},$t=[`onClick`],en={class:`text-muted d-block mt-1`},tn={key:0,class:`form-check`},nn=[`id`,`checked`],rn=[`for`],an={key:1},on={class:`min-w-0`},sn={class:`fw-medium text-truncate text-capitalize`},cn={class:`d-flex flex-wrap align-items-center gap-1`},ln={class:`text-muted`},un={key:0,class:`badge bg-info`},dn={key:1,class:`badge bg-warning`},fn={key:0,class:`text-muted d-block text-truncate`},pn={key:1},mn={class:`row g-2`},hn=[`aria-pressed`,`onClick`],gn={class:`min-w-0`},_n={class:`d-block fw-semibold fs-6`},vn={class:`d-block text-muted`},yn={key:2,class:`row g-3`},bn={class:`min-w-0`},xn={class:`fw-medium text-truncate`},Sn={class:`text-muted d-block text-truncate`},Cn=[`value`],wn=[`value`],Tn=[`value`],En={key:0,class:`col-12 col-md-6`},Dn={class:`d-flex flex-wrap align-items-center gap-1`},On=[`title`],kn={class:`text-muted`},An={key:1,class:`d-block text-truncate`},jn={key:2,class:`text-muted d-block`},Mn={key:0,class:`mt-2 d-flex flex-column gap-2`},Nn={class:`form-check mb-0 ms-3`},Pn=[`id`,`checked`],Fn=[`for`];function In(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`font-awesome-icon`),c=(0,n.resolveComponent)(`amsom-autocomplete`);return(0,n.openBlock)(),(0,n.createElementBlock)(`div`,Zt,[(0,n.createElementVNode)(`div`,null,[t[7]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` La sollicitation concerne… `,-1),(0,n.createElementVNode)(`div`,Qt,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.availableModes,t=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:t.key,type:`button`,class:(0,n.normalizeClass)([`btn btn-sm`,r.cibleMode===t.key?`btn-primary`:`btn-outline-primary`]),onClick:n=>e.$emit(`change-mode`,t.key)},[(0,n.createVNode)(s,{icon:t.icon,class:`me-1`},null,8,[`icon`]),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(t.label),1)],10,$t))),128))]),(0,n.createElementVNode)(`small`,en,(0,n.toDisplayString)(o.currentMode?.aide),1)]),r.cibleMode===`contrat`?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:0},[r.afficheCaseContratReclamant?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,tn,[(0,n.createElementVNode)(`input`,{id:`contrat-reclamant-${a.uid}`,class:`form-check-input`,type:`checkbox`,checked:r.contratReclamant,onChange:t[0]||=t=>e.$emit(`toggle-contrat-reclamant`,t.target.checked)},null,40,nn),(0,n.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`contrat-reclamant-${a.uid}`},` Contrat du réclamant `,8,rn)])):(0,n.createCommentVNode)(``,!0),r.contratReclamant?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,an,[t[8]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Contrat ciblé `,-1),(0,n.createVNode)(c,{modelValue:o.selectedContrat,"onUpdate:modelValue":t[1]||=e=>o.selectedContrat=e,items:a.contratsTrouves,"filtering-function":({items:e})=>e,loading:a.rechercheEnCours,"get-id":e=>e?`${e.typeContrat}|${e.idContrat}`:null,"get-input-libelle":o.contratInputLibelle,placeholder:`N° de contrat, locataire, module ou adresse…`,"input-size":`sm`,"hide-choices":``,"debounce-delay":0,onSearch:o.rechercherPlusTard},{options:(0,n.withCtx)(e=>[(0,n.createElementVNode)(`div`,on,[(0,n.createElementVNode)(`div`,sn,(0,n.toDisplayString)(e?.libelle??`Contrat ${e?.idContrat}`),1),(0,n.createElementVNode)(`div`,cn,[(0,n.createElementVNode)(`small`,ln,`N° `+(0,n.toDisplayString)(e?.typeContrat)+`/`+(0,n.toDisplayString)(e?.idContrat),1),e?.nbModules>1?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,un,(0,n.toDisplayString)(e.nbModules)+` modules`,1)):(0,n.createCommentVNode)(``,!0),e?.estSorti?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,dn,`Sorti`)):(0,n.createCommentVNode)(``,!0)]),o.contratAdresse(e)?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,fn,(0,n.toDisplayString)(o.contratAdresse(e)),1)):(0,n.createCommentVNode)(``,!0)])]),_:1},8,[`modelValue`,`items`,`filtering-function`,`loading`,`get-id`,`get-input-libelle`,`onSearch`])]))],64)):(0,n.createCommentVNode)(``,!0),r.cibleMode===`patrimoine`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,pn,[t[9]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Le problème concerne… `,-1),(0,n.createElementVNode)(`div`,mn,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.portees,t=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:t.titre,class:`col-12 col-md-6`},[(0,n.createElementVNode)(`button`,{type:`button`,class:(0,n.normalizeClass)([`btn w-100 h-100 text-start d-flex align-items-center gap-3 p-3 rounded border text-primary`,t.modulePrecis===r.modulePrecis?`border-primary bg-light`:`bg-white`]),"aria-pressed":t.modulePrecis===r.modulePrecis,onClick:n=>e.$emit(`set-module-precis`,t.modulePrecis)},[(0,n.createVNode)(s,{icon:t.icon,class:`fs-4`,"fixed-width":``},null,8,[`icon`]),(0,n.createElementVNode)(`span`,gn,[(0,n.createElementVNode)(`span`,_n,(0,n.toDisplayString)(t.titre),1),(0,n.createElementVNode)(`small`,vn,(0,n.toDisplayString)(t.aide),1)])],10,hn)]))),128))])])):(0,n.createCommentVNode)(``,!0),r.cibleMode===`contrat`||r.cibleMode===`patrimoine`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,yn,[(0,n.createElementVNode)(`div`,{class:(0,n.normalizeClass)([`col-12 d-flex flex-column gap-3`,{"col-md-6":o.afficheModule}])},[r.cibleMode===`patrimoine`?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:0},[(0,n.createElementVNode)(`div`,null,[t[10]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Commune `,-1),(0,n.createVNode)(c,{modelValue:o.selectedCommune,"onUpdate:modelValue":t[2]||=e=>o.selectedCommune=e,items:i.data.cache.communes||[],"get-id":e=>e?.idCommune,"get-input-libelle":e=>e?.commune??``,"filtering-function":o.filterOn(`commune`),placeholder:`Rechercher une commune…`,"input-size":`sm`,"hide-choices":``},null,8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`filtering-function`])]),(0,n.createElementVNode)(`div`,null,[t[11]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Adresse `,-1),(0,n.createVNode)(c,{modelValue:o.selectedAdresse,"onUpdate:modelValue":t[3]||=e=>o.selectedAdresse=e,items:o.adresses,"get-id":e=>e?.idEntree,"get-input-libelle":e=>e?.entree??``,"filtering-function":o.filterOn(`entree`),disabled:!r.patrimoine.idCommune,placeholder:`Rechercher une adresse…`,"input-size":`sm`,"hide-choices":``},{options:(0,n.withCtx)(e=>[(0,n.createElementVNode)(`div`,bn,[(0,n.createElementVNode)(`div`,xn,(0,n.toDisplayString)(e?.entree),1),(0,n.createElementVNode)(`small`,Sn,(0,n.toDisplayString)(e?.commune)+` — Programme `+(0,n.toDisplayString)(e?.codeProgramme),1)])]),_:1},8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`filtering-function`,`disabled`])]),(0,n.createElementVNode)(`div`,null,[t[12]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Étage`,-1),(0,n.createVNode)(c,{modelValue:o.selectedEtage,"onUpdate:modelValue":t[4]||=e=>o.selectedEtage=e,items:o.etages,"get-id":e=>e?.id,"get-input-libelle":e=>e?.libelle??``,disabled:!r.patrimoine.idEntree,placeholder:`Tous les étages…`,"input-size":`sm`,"hide-choices":``},null,8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`disabled`])])],64)):((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:1},[(0,n.createElementVNode)(`div`,null,[t[13]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Commune `,-1),(0,n.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:r.patrimoine.commune??`—`},null,8,Cn)]),(0,n.createElementVNode)(`div`,null,[t[14]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Adresse `,-1),(0,n.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:r.patrimoine.entree??`—`},null,8,wn)]),(0,n.createElementVNode)(`div`,null,[t[15]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Étage`,-1),(0,n.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:r.patrimoine.etage??`—`},null,8,Tn)])],64))],2),o.afficheModule?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,En,[t[16]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Module`,-1),(0,n.createVNode)(c,{modelValue:o.selectedModule,"onUpdate:modelValue":t[5]||=e=>o.selectedModule=e,items:o.modules,"get-id":e=>e?.idModule,"get-input-libelle":e=>o.moduleInputLibelle(e),"filtering-function":o.filterModules,disabled:o.areModulesLocked,placeholder:`Rechercher un module…`,"input-size":`sm`,"hide-choices":``},{options:(0,n.withCtx)(e=>[(0,n.createElementVNode)(`div`,{class:(0,n.normalizeClass)([`min-w-0 w-100 rounded position-relative`,e?._autreLibelle?`bg-yellow-subtle p-2`:``])},[e?._autreLibelle?((0,n.openBlock)(),(0,n.createBlock)(s,{key:0,icon:`building`,class:`position-absolute top-0 end-0 m-1 text-muted`,title:`Autre adresse ou étage du même programme`})):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,{class:(0,n.normalizeClass)([`fw-medium text-truncate`,[e?._autreLibelle?`text-muted`:``,o.isExit(e)?`text-decoration-line-through`:``]])},(0,n.toDisplayString)(o.moduleLibelle(e)),3),(0,n.createElementVNode)(`div`,Dn,[o.categorieLibelle(e)?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,{key:0,class:`badge bg-info`,title:e?.categorieModule},[(0,n.createVNode)(s,{icon:o.getCategorieModuleIcon(e?.idCategorieModule,e?.estCollectif)},null,8,[`icon`])],8,On)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`small`,kn,`N° `+(0,n.toDisplayString)(e?.idModule),1)]),e?._autreLibelle?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,An,(0,n.toDisplayString)(e._autreLibelle),1)):e?.etage==null?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`small`,jn,` Étage `+(0,n.toDisplayString)(e.etage),1))],2)]),_:1},8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`filtering-function`,`disabled`]),r.locataireActuelOption?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Mn,[(0,n.createElementVNode)(`div`,{class:(0,n.normalizeClass)([`alert d-flex align-items-start gap-2 py-2 px-3 mt-2 mb-0 fs-7`,r.locataireActuelOption.reprendre?`alert-warning`:`alert-secondary border`])},[(0,n.createVNode)(s,{icon:`circle-info`,class:`mt-1`}),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(r.locataireActuelOption.hint),1)],2),(0,n.createElementVNode)(`div`,Nn,[(0,n.createElementVNode)(`input`,{id:`locataire-actuel-${a.uid}`,class:`form-check-input`,type:`checkbox`,checked:r.locataireActuelOption.reprendre,onChange:t[6]||=t=>e.$emit(`toggle-reprendre-locataire-actuel`,t.target.checked)},null,40,Pn),(0,n.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`locataire-actuel-${a.uid}`},` Rattacher au locataire actuel du module `,8,Fn)])])):(0,n.createCommentVNode)(``,!0)])):(0,n.createCommentVNode)(``,!0)])):(0,n.createCommentVNode)(``,!0)])}var Ln=D(Xt,[[`render`,In]]),Rn={name:`EtapeCibleBlock`,components:{AmsomOverlay:t.AmsomOverlay,CiblePickerBlock:Ln},setup(){return{draft:E(),data:V(),options:J()}},computed:{lignePrincipale(){return this.draft.lignePrincipale},lignesAssociees(){return this.draft.lignesAssociees},reclamantModules(){return this.options.modulesReclamant??[]},mainModule(){return this.draft.moduleReclamantPrincipal},cibleFigee(){return this.draft.isReadonly(`cible`)},reclamantType(){return this.draft.draft.reclamant.type},motifLibelle(){let e=this.lignePrincipale.idMotif;return e==null?null:this.data.motifLibelle(e)}},async created(){if(this.reclamantType===`D`||this.cibleFigee)return;await this.data.loadCommunes(),!this.draft.reclamantEstContrat&&this.lignePrincipale.cibleMode===`contrat`&&this.draft.setCibleMode(0,`patrimoine`);let e=this.lignePrincipale.patrimoine;await this.data.loadAdresses(e?.idCommune??null),this.lignePrincipale.cibleMode!==`contrat`&&await this.data.loadModulesOfProgramme(e?.codeProgramme??null)},methods:{pickerProps(e){return{patrimoine:e.patrimoine,cibleMode:e.cibleMode,reclamantModules:this.reclamantModules,reclamantType:this.reclamantType,contratReclamant:e.contratReclamant,contratCible:e.contratCible,modulePrecis:e.modulePrecis,afficheCaseContratReclamant:this.draft.reclamantEstContrat,locataireActuelOption:this.locataireActuelOption(e)}},onChangeMode(e,t=0){this.draft.setCibleMode(t,e),this.applyMode(e,t)},onSelectCommune(e,t=0){this.draft.setPatrimoineCommune(t,e??null),e?.idCommune!=null&&this.data.loadAdresses(e.idCommune)},onSelectAdresse(e,t=0){this.draft.setPatrimoineEntree(t,e??null),e?.codeProgramme!=null&&this.data.loadModulesOfProgramme(e.codeProgramme)},onSelectEtage(e,t=0){this.draft.setPatrimoineEtage(t,e??null)},onSelectModule(e,t=0){let n=this.draft.draft.lignes[t];e&&n?.cibleMode===`contrat`?this.draft.prefillFromModule(t,e):this.draft.setPatrimoineModule(t,e??null)},onToggleReprendre(e,t=0){this.draft.setReprendreLocataireActuel(t,e)},onToggleContratReclamant(e,t=0){this.draft.toggleContratReclamant(t,e),e&&this.draft.prefillFromModule(t,this.mainModule)},onSelectContrat(e,t=0){this.draft.setContratCible(t,e),e&&this.data.loadModulesOfContrat({idContrat:e.idContrat,typeContrat:e.typeContrat})},locataireActuelOption(e){if(e?.cibleMode!==`contrat`)return null;let t=e?.patrimoine;if(!t||t.idModule==null)return null;let n=e.contratReclamant&&this.draft.reclamantEstContrat,r=n?{typeContrat:this.draft.draft.reclamant.type,idContrat:this.draft.draft.reclamant.id}:e.contratCible;if(!r?.idContrat||String(t.idContratActuel)===String(r.idContrat)&&String(t.typeContratActuel)===String(r.typeContrat))return null;let i=!!e.reprendreLocataireActuel,a=n?`Le réclamant n’occupe plus ce module : `:`Le contrat ciblé n’occupe plus ce module : `;if(!i)a+=`la cible restera le contrat ciblé, ancien occupant de ce module.`;else if(t.idContratActuel==null)a+=`ce module est vacant, la sollicitation ne sera rattachée à aucun contrat.`;else{let e=t.occupantActuel??`contrat sans libellé`,n=(t.typeContratActuel?`${t.typeContratActuel}/`:``)+t.idContratActuel;a+=`la cible sera le locataire actuel du module : ${e} ${n}.`}return{reprendre:i,hint:a}},async applyMode(e,t=0){e===`contrat`?this.draft.prefillFromModule(t,this.mainModule):this.mainModule&&(this.draft.prefillFromModule(t,this.mainModule),this.mainModule.idCommune!=null&&await this.data.loadAdresses(this.mainModule.idCommune),this.mainModule.codeProgramme!=null&&await this.data.loadModulesOfProgramme(this.mainModule.codeProgramme))}}},zn={class:`d-flex flex-column gap-3`},Bn={key:0,class:`alert alert-light border py-2 px-3 mb-0 d-flex align-items-center gap-2`},Vn={class:`fs-7`},Hn={key:1,class:`d-flex flex-column gap-1`},Un={key:0,class:`text-muted me-1`},Wn={class:`d-flex align-items-center gap-2`},Gn={class:`fw-medium fs-7`},Kn={class:`form-check form-switch mb-0`},qn=[`id`,`checked`,`onChange`],Jn=[`for`],Yn={key:0,class:`mt-2`};function Xn(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`font-awesome-icon`),c=(0,n.resolveComponent)(`cible-picker-block`),l=(0,n.resolveComponent)(`amsom-overlay`);return(0,n.openBlock)(),(0,n.createBlock)(l,{loading:i.data.isLoading},{default:(0,n.withCtx)(()=>[(0,n.createElementVNode)(`div`,zn,[o.motifLibelle?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Bn,[(0,n.createVNode)(s,{icon:`tag`,class:`text-primary`}),(0,n.createElementVNode)(`span`,Vn,[t[9]||=(0,n.createElementVNode)(`span`,{class:`text-muted text-uppercase fw-semibold me-1`},`Motif`,-1),(0,n.createTextVNode)((0,n.toDisplayString)(o.motifLibelle),1)])])):(0,n.createCommentVNode)(``,!0),o.cibleFigee?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Hn,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(i.draft.draft.lignes,(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`span`,{key:t,class:`fs-7`},[(0,n.createVNode)(s,{icon:`location-dot`,class:`text-primary me-2`}),o.lignesAssociees.length?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,Un,(0,n.toDisplayString)(t===0?o.motifLibelle:e.libelle)+` : `,1)):(0,n.createCommentVNode)(``,!0),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(i.draft.cibleResume(e)),1)]))),128))])):((0,n.openBlock)(),(0,n.createBlock)(c,(0,n.mergeProps)({key:2},o.pickerProps(o.lignePrincipale),{onChangeMode:t[0]||=e=>o.onChangeMode(e),onSelectCommune:t[1]||=e=>o.onSelectCommune(e),onSelectAdresse:t[2]||=e=>o.onSelectAdresse(e),onSelectEtage:t[3]||=e=>o.onSelectEtage(e),onSelectModule:t[4]||=e=>o.onSelectModule(e),onSelectContrat:t[5]||=e=>o.onSelectContrat(e),onToggleContratReclamant:t[6]||=e=>o.onToggleContratReclamant(e),onToggleReprendreLocataireActuel:t[7]||=e=>o.onToggleReprendre(e),onSetModulePrecis:t[8]||=e=>i.draft.setModulePrecis(0,e)}),null,16)),!o.cibleFigee&&o.lignesAssociees.length&&o.reclamantType!==`D`?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:3},[t[10]||=(0,n.createElementVNode)(`div`,{class:`d-flex align-items-center gap-2 text-muted fs-7`},[(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`}),(0,n.createElementVNode)(`span`,null,`Cible des autres motifs`),(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`})],-1),((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.lignesAssociees,(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:e.idMotif,class:`border rounded p-2`},[(0,n.createElementVNode)(`div`,Wn,[(0,n.createElementVNode)(`span`,Gn,(0,n.toDisplayString)(e.libelle),1),(0,n.createElementVNode)(`div`,Kn,[(0,n.createElementVNode)(`input`,{id:`memecible-${e.idMotif}`,class:`form-check-input`,type:`checkbox`,checked:!e.patrimoine,onChange:e=>i.draft.toggleCibleOverride(t+1)},null,40,qn),(0,n.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`memecible-${e.idMotif}`},` Même cible que la ligne principale `,8,Jn)])]),e.patrimoine?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Yn,[(0,n.createVNode)(c,(0,n.mergeProps)({ref_for:!0},o.pickerProps(e),{onChangeMode:e=>o.onChangeMode(e,t+1),onSelectCommune:e=>o.onSelectCommune(e,t+1),onSelectAdresse:e=>o.onSelectAdresse(e,t+1),onSelectEtage:e=>o.onSelectEtage(e,t+1),onSelectModule:e=>o.onSelectModule(e,t+1),onSelectContrat:e=>o.onSelectContrat(e,t+1),onToggleContratReclamant:e=>o.onToggleContratReclamant(e,t+1),onToggleReprendreLocataireActuel:e=>o.onToggleReprendre(e,t+1),onSetModulePrecis:e=>i.draft.setModulePrecis(t+1,e)}),null,16,[`onChangeMode`,`onSelectCommune`,`onSelectAdresse`,`onSelectEtage`,`onSelectModule`,`onSelectContrat`,`onToggleContratReclamant`,`onToggleReprendreLocataireActuel`,`onSetModulePrecis`])])):(0,n.createCommentVNode)(``,!0)]))),128))],64)):(0,n.createCommentVNode)(``,!0)])]),_:1},8,[`loading`])}var Zn=D(Rn,[[`render`,Xn]]),Qn={name:`LigneDocumentBlock`,components:{AmsomUploadFile:u.AmsomUploadFile},props:{index:{type:Number,required:!0},fichier:{type:[Object,Array],default:null},readonly:{type:Boolean,default:!1}},emits:[`update`]};function $n(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`amsom-upload-file`);return(0,n.openBlock)(),(0,n.createElementBlock)(`div`,null,[t[1]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Document`,-1),(0,n.createVNode)(s,{"model-value":r.fichier,renameable:``,"output-format":`object`,name:`cresol-creation-ged-${r.index}`,"merge-pdfs":``,"read-only":r.readonly,"onUpdate:modelValue":t[0]||=t=>e.$emit(`update`,t)},null,8,[`model-value`,`name`,`read-only`])])}var er=D(Qn,[[`render`,$n]]);function tr(e){return e==null?``:new Date(e*1e3).toISOString().slice(0,10)}function nr(e){return e?Math.floor(new Date(e).getTime()/1e3):null}var rr=4e3,ir={name:`LigneDetailBlock`,components:{AmsomAutocomplete:a.AmsomAutocomplete,AmsomTextarea:l.AmsomTextarea,LigneDocumentBlock:er},props:{index:{type:Number,required:!0}},setup(){return{draft:E(),data:V()}},computed:{descriptionMaxLength:()=>rr,isPrincipale(){return this.index===0},ligne(){return this.draft.draft.lignes[this.index]},lignePrincipale(){return this.draft.lignePrincipale},collaborateurs(){return(this.data.cache.collaborateurs??[]).filter(e=>e.actif!==!1)},dateFaits(){return this.isPrincipale||this.ligne.dateFaitsOverride?this.ligne.dateFaits:this.lignePrincipale.dateFaits}},methods:{timestampToDateInput:tr,dateInputToTimestamp:nr,responsableLibelle(e){let t=e&&typeof e!=`object`?this.collaborateurs.find(t=>String(t.id)===String(e)):e;return t?`${t.prenom} ${t.nom}`:``},filterCollaborateurs({search:e,items:t}){let n=(Y(e)??``).trim();return n?t.filter(e=>(Y(`${e.prenom} ${e.nom} ${e.service}`)??``).includes(n)):t}}},ar={class:`d-flex flex-column gap-2`},or={class:`d-flex align-items-center gap-2 mb-1`},sr={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-0`},cr={key:0,class:`ms-1 text-danger`},lr={key:0,class:`form-check form-switch mb-0`},ur=[`id`,`checked`,`disabled`],dr=[`for`],fr={key:1,class:`text-muted d-block`,style:{"white-space":`pre-line`}},pr={class:`row g-3`},mr={class:`col-6`},hr={class:`d-flex align-items-center gap-2 mb-1`},gr={key:0,class:`form-check form-switch mb-0`},_r=[`id`,`checked`,`disabled`],vr=[`for`],yr=[`value`],br={key:1,class:`text-muted d-block`},xr={key:0,class:`text-muted d-block`},Sr={class:`min-w-0`},Cr={class:`fw-medium text-truncate`},wr={key:0,class:`text-muted d-block`},Tr={key:2,class:`text-muted`},Er={class:`col-12 col-md-6`};function Dr(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`amsom-textarea`),c=(0,n.resolveComponent)(`amsom-autocomplete`),l=(0,n.resolveComponent)(`ligne-document-block`);return(0,n.openBlock)(),(0,n.createElementBlock)(`div`,ar,[(0,n.createElementVNode)(`div`,null,[(0,n.createElementVNode)(`div`,or,[(0,n.createElementVNode)(`label`,sr,[t[6]||=(0,n.createTextVNode)(` Description`,-1),o.isPrincipale?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,cr,`*`)):(0,n.createCommentVNode)(``,!0)]),o.isPrincipale?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,lr,[(0,n.createElementVNode)(`input`,{id:`memedetail-${o.ligne.idMotif}`,class:`form-check-input`,type:`checkbox`,checked:o.ligne.description==null,disabled:i.draft.isReadonly(`description`),onChange:t[0]||=e=>i.draft.toggleDescriptionOverride(r.index)},null,40,ur),(0,n.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`memedetail-${o.ligne.idMotif}`},` Même description `,8,dr)]))]),!i.draft.isReadonly(`description`)&&(o.isPrincipale||o.ligne.description!=null)?((0,n.openBlock)(),(0,n.createBlock)(s,{key:0,"model-value":o.ligne.description,"input-size":`sm`,rows:o.isPrincipale?4:3,maxlength:o.descriptionMaxLength,placeholder:o.isPrincipale?`Décrivez la sollicitation…`:`Décrivez ce motif…`,"onUpdate:modelValue":t[1]||=e=>i.draft.setDescription(r.index,e)},null,8,[`model-value`,`rows`,`maxlength`,`placeholder`])):((0,n.openBlock)(),(0,n.createElementBlock)(`small`,fr,(0,n.toDisplayString)((o.ligne.description??o.lignePrincipale.description)||`—`),1))]),(0,n.createElementVNode)(`div`,pr,[(0,n.createElementVNode)(`div`,mr,[(0,n.createElementVNode)(`div`,null,[(0,n.createElementVNode)(`div`,hr,[t[7]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-0`},` Date des faits `,-1),o.isPrincipale?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,gr,[(0,n.createElementVNode)(`input`,{id:`memedate-${o.ligne.idMotif}`,class:`form-check-input`,type:`checkbox`,checked:!o.ligne.dateFaitsOverride,disabled:i.draft.isReadonly(`dateFaits`),onChange:t[2]||=e=>i.draft.toggleDateFaitsOverride(r.index)},null,40,_r),(0,n.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`memedate-${o.ligne.idMotif}`},` Même date `,8,vr)]))]),!i.draft.isReadonly(`dateFaits`)&&(o.isPrincipale||o.ligne.dateFaitsOverride)?((0,n.openBlock)(),(0,n.createElementBlock)(`input`,{key:0,value:o.timestampToDateInput(o.ligne.dateFaits),type:`date`,class:`form-control form-control-sm`,onInput:t[3]||=e=>i.draft.setDateFaits(r.index,o.dateInputToTimestamp(e.target.value))},null,40,yr)):((0,n.openBlock)(),(0,n.createElementBlock)(`small`,br,(0,n.toDisplayString)(o.timestampToDateInput(o.dateFaits)||`—`),1))]),(0,n.createElementVNode)(`div`,null,[t[8]||=(0,n.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Responsable `,-1),i.draft.isReadonly(`responsable`)?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,xr,(0,n.toDisplayString)(o.responsableLibelle(o.ligne.responsable)||`Déterminé automatiquement`),1)):((0,n.openBlock)(),(0,n.createBlock)(c,{key:1,"model-value":o.ligne.responsable,items:o.collaborateurs,"get-id":e=>e?.id,"get-input-libelle":o.responsableLibelle,"filtering-function":o.filterCollaborateurs,placeholder:`Rechercher un responsable…`,"input-size":`sm`,"hide-choices":``,"onUpdate:modelValue":t[4]||=e=>i.draft.setResponsable(r.index,e??null)},{options:(0,n.withCtx)(e=>[(0,n.createElementVNode)(`div`,Sr,[(0,n.createElementVNode)(`div`,Cr,(0,n.toDisplayString)(e?.prenom)+` `+(0,n.toDisplayString)(e?.nom),1),e?.service?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,wr,(0,n.toDisplayString)(e.service),1)):(0,n.createCommentVNode)(``,!0)])]),_:1},8,[`model-value`,`items`,`get-id`,`get-input-libelle`,`filtering-function`])),o.isPrincipale&&!o.ligne.responsable&&!i.draft.isReadonly(`responsable`)?((0,n.openBlock)(),(0,n.createElementBlock)(`small`,Tr,` Aucun paramétrage trouvé : le responsable sera déterminé automatiquement. `)):(0,n.createCommentVNode)(``,!0)])]),(0,n.createElementVNode)(`div`,Er,[(0,n.createVNode)(l,{index:r.index,fichier:o.ligne.fichier,readonly:i.draft.isReadonly(`fichier`),onUpdate:t[5]||=e=>i.draft.setFichier(r.index,e)},null,8,[`index`,`fichier`,`readonly`])])])])}var Or=D(ir,[[`render`,Dr]]),kr={name:`EtapeDetailsBlock`,components:{AmsomOverlay:t.AmsomOverlay,LigneDetailBlock:Or},setup(){return{draft:E(),data:V()}},computed:{lignePrincipale(){return this.draft.lignePrincipale},lignesAssociees(){return this.draft.lignesAssociees},collaborateurs(){return(this.data.cache.collaborateurs??[]).filter(e=>e.actif!==!1)},motifLibelle(){let e=this.lignePrincipale.idMotif;return e==null?null:this.data.motifLibelle(e)}},async created(){await this.data.loadCollaborateurs(),await this.prefillResponsables()},methods:{codeOfPatrimoine(e){return{codeProgramme:e?.codeProgramme,codeTranche:e?.codeTranche,codeBatiment:e?.codeBatiment,codeEscalier:e?.codeEscalier}},async suggestResponsable(e,t=null){await this.data.loadResponsables({motif:e.idMotif,categorie:e.idCategorie,type:e.idType,nature:e.idNature});let n=this.codeOfPatrimoine(t??this.lignePrincipale.patrimoine),r=this.data.getResponsableSuggere({idMotif:e.idMotif,...n});return r?this.collaborateurs.find(e=>String(e.id)===String(r.idResponsable))??null:null},async prefillResponsables(){if(!this.draft.isReadonly(`responsable`))for(let[e,t]of this.draft.draft.lignes.entries()){if(t.responsable!=null||t.idMotif==null)continue;let n=await this.suggestResponsable(t,t.patrimoine??null);n&&this.draft.setResponsable(e,n)}}}},Ar={class:`d-flex flex-column gap-3`},jr={class:`alert alert-light border py-2 px-3 mb-0 d-flex flex-column gap-1`},Mr={key:0,class:`fs-7`},Nr={class:`fs-7`},Pr={class:`bg-light rounded px-2 py-1 d-flex flex-column gap-1`},Fr={class:`fs-7`},Ir={class:`fs-7`};function Lr(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`font-awesome-icon`),c=(0,n.resolveComponent)(`ligne-detail-block`),l=(0,n.resolveComponent)(`amsom-overlay`);return(0,n.openBlock)(),(0,n.createBlock)(l,{loading:i.data.isLoading&&!i.data.cache.collaborateurs},{default:(0,n.withCtx)(()=>[(0,n.createElementVNode)(`div`,Ar,[(0,n.createElementVNode)(`div`,jr,[o.motifLibelle?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,Mr,[(0,n.createVNode)(s,{icon:`tag`,class:`text-primary me-2`}),t[0]||=(0,n.createElementVNode)(`span`,{class:`text-muted text-uppercase fw-semibold me-1`},`Motif`,-1),(0,n.createTextVNode)((0,n.toDisplayString)(o.motifLibelle),1)])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,Nr,[(0,n.createVNode)(s,{icon:`location-dot`,class:`text-primary me-2`}),t[1]||=(0,n.createElementVNode)(`span`,{class:`text-muted text-uppercase fw-semibold me-1`},`Cible`,-1),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(i.draft.cibleResume(o.lignePrincipale)),1)])]),(0,n.createVNode)(c,{index:0}),o.lignesAssociees.length?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:0},[t[4]||=(0,n.createElementVNode)(`div`,{class:`d-flex align-items-center gap-2 text-muted fs-7`},[(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`}),(0,n.createElementVNode)(`span`,null,`Détail des autres motifs`),(0,n.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`})],-1),((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(o.lignesAssociees,(e,r)=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:e.idMotif,class:`border rounded p-2 d-flex flex-column gap-2`},[(0,n.createElementVNode)(`div`,Pr,[(0,n.createElementVNode)(`span`,Fr,[(0,n.createVNode)(s,{icon:`tag`,class:`text-primary me-2`}),t[2]||=(0,n.createElementVNode)(`span`,{class:`text-muted text-uppercase fw-semibold me-1`},`Motif`,-1),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(e.libelle),1)]),(0,n.createElementVNode)(`span`,Ir,[(0,n.createVNode)(s,{icon:`location-dot`,class:`text-primary me-2`}),t[3]||=(0,n.createElementVNode)(`span`,{class:`text-muted text-uppercase fw-semibold me-1`},`Cible`,-1),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(i.draft.cibleResume(e)),1)])]),(0,n.createVNode)(c,{index:r+1},null,8,[`index`])]))),128))],64)):(0,n.createCommentVNode)(``,!0)])]),_:1},8,[`loading`])}var Rr=D(kr,[[`render`,Lr]]),zr={name:`StepperBlock`,components:{AmsomHorizontalStepper:i.default,AmsomOverlay:t.AmsomOverlay,EtapeReclamantBlock:ft,EtapeCategorieBlock:Gt,EtapeCibleBlock:Zn,EtapeDetailsBlock:Rr},props:{step:{type:Number,default:1},creating:{type:Boolean,default:!1}},emits:[`update:step`,`stepChange`,`submit`],setup(){return{draft:E(),data:V(),options:J()}},computed:{steps(){return[...this.options.reclamantMode===`step`?[{key:`reclamant`,label:`Réclamant`,icon:`user`}]:[],{key:`categorie`,label:`Catégorisation`,icon:`tag`},{key:`cible`,label:`Cible`,icon:`location-dot`},{key:`details`,label:`Détails`,icon:`info`}]},currentKey(){return this.steps[this.step-1]?.key??null},lignePrincipale(){return this.draft.lignePrincipale},aideMotif(){let e=this.lignePrincipale.idMotif;return e?this.data.cache.motifs?.find(t=>t.id===e)?.aide??null:null},canGoNext(){return this.gatePassed(this.currentKey)},canCreer(){return!!this.lignePrincipale.idMotif&&!!this.draft.draft.provenance&&this.draft.ciblesValid&&this.draft.detailsValid&&this.draft.reclamantSelectionne!=null},stepperSteps(){return this.steps.map((e,t)=>{let n=t+1;return{numero:n,subtitle:e.label,subtitleColor:n===this.step?`primary`:`muted`,icon:n<this.step?`check`:e.icon,iconColor:`white`,bubbleBgColor:n>this.step?`gray`:`primary`,clickable:n<this.step}})}},watch:{step(e,t){this.$emit(`stepChange`,{step:e,key:this.currentKey,previous:{step:t,key:this.steps[t-1]?.key??null}})}},methods:{gatePassed(e){return e===`reclamant`?this.draft.reclamantSelectionne!=null&&!!this.draft.draft.provenance:e===`categorie`?!!this.lignePrincipale.idMotif&&!!this.draft.draft.provenance:e!==`cible`||this.draft.ciblesValid},onStepClick(e){e<this.step&&this.$emit(`update:step`,e)},goPrevious(){this.step>1&&this.$emit(`update:step`,this.step-1)},goNext(){this.step>=this.steps.length||!this.canGoNext||(this.currentKey===`categorie`&&this.preloadResponsables(),this.$emit(`update:step`,this.step+1))},preloadResponsables(){this.draft.draft.lignes.forEach(e=>this.data.loadResponsables({motif:e.idMotif,categorie:e.idCategorie,type:e.idType,nature:e.idNature}))}}},Br={class:`d-flex flex-column gap-3`},Vr={key:0,class:`w-100 fs-6 fw-medium my-3 alert alert-info`,style:{"white-space":`pre-line`}},Hr={style:{"min-height":`260px`}},Ur={class:`d-flex justify-content-between`},Wr={key:1},Gr=[`disabled`],Kr=[`disabled`];function qr(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`amsom-horizontal-stepper`),c=(0,n.resolveComponent)(`font-awesome-icon`),l=(0,n.resolveComponent)(`etape-reclamant-block`),u=(0,n.resolveComponent)(`etape-categorie-block`),d=(0,n.resolveComponent)(`etape-cible-block`),f=(0,n.resolveComponent)(`etape-details-block`),p=(0,n.resolveComponent)(`amsom-overlay`);return(0,n.openBlock)(),(0,n.createBlock)(p,{loading:r.creating},{default:(0,n.withCtx)(()=>[(0,n.createElementVNode)(`div`,Br,[(0,n.createVNode)(s,{steps:o.stepperSteps,size:`md`,onStepClick:o.onStepClick},null,8,[`steps`,`onStepClick`]),o.aideMotif?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Vr,[(0,n.createVNode)(c,{icon:`circle-info`,class:`text-info-emphasis me-2`}),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(o.aideMotif),1)])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,Hr,[o.currentKey===`reclamant`?((0,n.openBlock)(),(0,n.createBlock)(l,{key:0,premiere:r.step===1},(0,n.createSlots)({_:2},[e.$slots.reclamant?{name:`reclamant`,fn:(0,n.withCtx)(t=>[(0,n.renderSlot)(e.$slots,`reclamant`,(0,n.normalizeProps)((0,n.guardReactiveProps)(t)))]),key:`0`}:void 0]),1032,[`premiere`])):o.currentKey===`categorie`?((0,n.openBlock)(),(0,n.createBlock)(u,{key:1,premiere:r.step===1},null,8,[`premiere`])):o.currentKey===`cible`?((0,n.openBlock)(),(0,n.createBlock)(d,{key:2})):o.currentKey===`details`?((0,n.openBlock)(),(0,n.createBlock)(f,{key:3})):(0,n.createCommentVNode)(``,!0)]),(0,n.createElementVNode)(`div`,Ur,[r.step>1?((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:0,class:`btn btn-sm btn-outline-secondary`,onClick:t[0]||=(...e)=>o.goPrevious&&o.goPrevious(...e)},[(0,n.createVNode)(c,{icon:`chevron-left`,class:`me-1`}),t[3]||=(0,n.createTextVNode)(` Précédent `,-1)])):((0,n.openBlock)(),(0,n.createElementBlock)(`span`,Wr)),r.step<o.steps.length?((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:2,class:`btn btn-sm btn-primary`,disabled:!o.canGoNext,onClick:t[1]||=(...e)=>o.goNext&&o.goNext(...e)},[t[4]||=(0,n.createTextVNode)(` Suivant `,-1),(0,n.createVNode)(c,{icon:`chevron-right`,class:`ms-1`})],8,Gr)):((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:3,class:`btn btn-sm btn-success`,disabled:!o.canCreer||r.creating,onClick:t[2]||=t=>e.$emit(`submit`)},[(0,n.createVNode)(c,{icon:`check`,class:`me-1`}),t[5]||=(0,n.createTextVNode)(` Créer la sollicitation `,-1)],8,Kr))])])]),_:3},8,[`loading`])}var Jr=D(zr,[[`render`,qr]]),Yr=(e,{signal:t,baseUrl:n}={})=>M(`/v2/cresol/creer_sollicitation`,e,{signal:t,baseUrl:n}),Xr=({idSollicitation:e,pj:t},{signal:n,baseUrl:r}={})=>M(`/v2/cresol/upload_sollicitation_ged`,{idSollicitation:e,pj:t},{signal:n,baseUrl:r}),X={modelValue:{type:Object,default:null},reclamants:{type:Array,default:()=>[]},reclamantMode:{type:String,default:`select`,validator:e=>[`select`,`switch`,`autocomplete`,`step`].includes(e)},readonly:{type:[Boolean,Array],default:!1,validator:e=>typeof e==`boolean`||e.every(e=>C.includes(e))},modules:{type:Array,default:null},idModule:{type:[String,Number],default:null},nomenclatureFilter:{type:Function,default:null},aside:{type:Boolean,default:!0},nbSimilaires:{type:Number,default:0},baseUrl:{type:String,default:null}},Zr=Object.keys(X),Z=[`update:modelValue`,`reclamantChange`,`motifChange`,`stepChange`,`beforeCreate`,`created`,`createError`,`error`],Qr={name:`CreerSollicitationForm`,components:{AsideBlock:ge,StepperBlock:Jr},props:{...X},emits:[...Z],setup(e,{emit:t}){let r=e=>t(`error`,e),i={baseUrl:(0,n.toRef)(e,`baseUrl`)},a=ze(Re({onError:r,...i})),o=(0,n.ref)(null),s=(0,n.computed)(()=>o.value??e.modules??[]),c=le(ce({reclamants:(0,n.computed)(()=>e.reclamantMode===`step`?[]:e.reclamants),modules:s,idModulePrefere:(0,n.toRef)(e,`idModule`),readonly:(0,n.toRef)(e,`readonly`)}));return pt((0,n.reactive)({nomenclatureFilter:(0,n.toRef)(e,`nomenclatureFilter`),reclamantMode:(0,n.toRef)(e,`reclamantMode`),modulesReclamant:s,...i})),{data:a,draft:c,modulesCharges:o,onError:r}},data(){return{currentStep:1,creating:!1}},computed:{requestOptions(){return{baseUrl:this.baseUrl}},motifChoisi(){let[e,...t]=this.draft.draft.lignes;return{idCategorie:e.idCategorie,idType:e.idType,idNature:e.idNature,idMotif:e.idMotif,motifsAssocies:t.map(e=>e.idMotif)}}},watch:{"draft.draft":{deep:!0,handler(e){this.$emit(`update:modelValue`,e)}}},async created(){this.draft.reset(this.modelValue),this.draft.syncReclamant();let e=this.draft.reclamantSelectionne;this.$watch(`draft.reclamantSelectionne`,async t=>{this.$emit(`reclamantChange`,t),await this.chargerModulesReclamant(t,e)&&this.draft.syncReclamant()}),this.$watch(()=>JSON.stringify(this.motifChoisi),()=>this.$emit(`motifChange`,this.motifChoisi)),this.data.loadNomenclature(),await this.chargerModulesReclamant(e,e)&&this.draft.prefillCiblePrincipale()},methods:{async chargerModulesReclamant(e,t){if(this.modules&&e===t)return this.modulesCharges=null,!0;if(!this.draft.reclamantEstContrat)return this.modulesCharges=[],!0;let n=await this.data.loadModulesOfContrat({idContrat:e.id,typeContrat:e.type});return e===this.draft.reclamantSelectionne&&(this.modulesCharges=n??[],!0)},async creer(){if(!this.creating){this.creating=!0;try{let e=this.draft.creationPayload();if(!await this.autoriserCreation(e))return;let t;try{t=await Yr(e,this.requestOptions)??[]}catch(t){if(F(t))return;let n=P(t);this.$emit(`createError`,{error:t,message:n,payload:e}),this.onError(n);return}let n=await this.sendFiles(t);this.$emit(`created`,t,{payload:e,fichiers:n})}finally{this.creating=!1}}},async autoriserCreation(e){let t=!1,n=[];if(this.$emit(`beforeCreate`,{payload:e,cancel:()=>{t=!0},waitUntil:e=>{n.push(e)}}),t)return!1;try{let e=await Promise.all(n);return!t&&!e.includes(!1)}catch{return!1}},sendFiles(e){let t=[...e],n=this.draft.draft.lignes.filter(e=>e.fichier?.[0]).map(e=>{let n=e.fichier[0],r=e.libelle||e.idMotif,i=t.findIndex(t=>String(t.idMotif)===String(e.idMotif)),a=i===-1?null:t.splice(i,1)[0],o={idMotif:e.idMotif,nom:n.name,idSollicitation:a?.id??null},s=e=>{let t=`Document non envoyé (${r}) : ${e}`;return this.onError(t),{...o,ok:!1,message:t}};return a?.id?Xr({idSollicitation:a.id,pj:{name:n.name,type:n.type||`application/pdf`,file:n.file}},this.requestOptions).then(()=>({...o,ok:!0,message:null})).catch(e=>s(P(e))):Promise.resolve(s(`sollicitation introuvable dans la réponse`))});return Promise.all(n)}}},$r={class:`row g-3`},ei={key:0,class:`col-12 col-lg-4`};function ti(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`aside-block`),c=(0,n.resolveComponent)(`stepper-block`);return(0,n.openBlock)(),(0,n.createElementBlock)(`div`,$r,[e.aside?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ei,[(0,n.renderSlot)(e.$slots,`aside`,{},()=>[(0,n.createVNode)(s,{"nb-similaires":e.nbSimilaires},(0,n.createSlots)({_:2},[e.$slots[`aside-similaires`]?{name:`similaires`,fn:(0,n.withCtx)(t=>[(0,n.renderSlot)(e.$slots,`aside-similaires`,(0,n.normalizeProps)((0,n.guardReactiveProps)(t)))]),key:`0`}:void 0,e.$slots[`aside-evenements`]?{name:`evenements`,fn:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`aside-evenements`)]),key:`1`}:void 0]),1032,[`nb-similaires`])])])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,{class:(0,n.normalizeClass)([`col-12`,e.aside?`col-lg-8`:``])},[(0,n.createVNode)(c,{step:a.currentStep,"onUpdate:step":t[0]||=e=>a.currentStep=e,creating:a.creating,onStepChange:t[1]||=t=>e.$emit(`stepChange`,t),onSubmit:o.creer},(0,n.createSlots)({_:2},[e.$slots.reclamant?{name:`reclamant`,fn:(0,n.withCtx)(t=>[(0,n.renderSlot)(e.$slots,`reclamant`,(0,n.normalizeProps)((0,n.guardReactiveProps)(t)))]),key:`0`}:void 0]),1032,[`step`,`creating`,`onSubmit`])],2)])}var Q=D(Qr,[[`render`,ti]]),ni={name:`CreerSollicitationModal`,components:{AmsomModal:t.AmsomModal,CreerSollicitationForm:Q},props:{...X,titre:{type:String,default:`Nouvelle sollicitation`},closeOnCreated:{type:Boolean,default:!0}},emits:[...Z,`close`],computed:{formProps(){return Object.fromEntries(Zr.map(e=>[e,this[e]]))},formListeners(){return Object.fromEntries(Z.filter(e=>e!==`created`).map(e=>[e,(...t)=>this.$emit(e,...t)]))}},methods:{onCreated(...e){this.$emit(`created`,...e),this.closeOnCreated&&this.$emit(`close`)}}},ri={class:`fw-medium fs-5`};function ii(e,t,r,i,a,o){let s=(0,n.resolveComponent)(`creer-sollicitation-form`),c=(0,n.resolveComponent)(`amsom-modal`);return(0,n.openBlock)(),(0,n.createBlock)(c,{"close-option":``,size:`xl`,onClose:t[0]||=t=>e.$emit(`close`)},{default:(0,n.withCtx)(()=>[(0,n.createElementVNode)(`span`,ri,(0,n.toDisplayString)(r.titre),1),(0,n.createVNode)(s,(0,n.mergeProps)({class:`pt-3`},o.formProps,(0,n.toHandlers)(o.formListeners),{onCreated:o.onCreated}),(0,n.createSlots)({_:2},[(0,n.renderList)(e.$slots,(t,r)=>({name:r,fn:(0,n.withCtx)(t=>[(0,n.renderSlot)(e.$slots,r,(0,n.normalizeProps)((0,n.guardReactiveProps)(t??{})))])}))]),1040,[`onCreated`])]),_:3})}var $=D(ni,[[`render`,ii]]),ai={CreerSollicitationModal:$,CreerSollicitationForm:Q};e.CreerSollicitationForm=Q,e.CreerSollicitationModal=$,e.DEFAULT_PROVENANCE_CONTACT=ee,e.PROVENANCES_CONTACT=y,e.READONLY_FIELDS=C,e.configureCresol=_e,e.default=ai,e.getDefaultDraft=w,e.getDefaultLigne=S,e.getDefaultPatrimoine=x,e.resetCresolCache=Le});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amsom-habitat/cresol",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Création de sollicitation (assistant 3 étapes) réutilisable par les outils AMSOM Habitat",
5
5
  "type": "module",
6
6
  "scripts": {