@amsom-habitat/cresol 0.3.0 → 0.3.1

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("@fortawesome/fontawesome-svg-core"),require("@fortawesome/free-solid-svg-icons"),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("@amsom-habitat/amsom-textarea"),require("@amsom-habitat/file-manager")):typeof define==`function`&&define.amd?define([`exports`,`@fortawesome/fontawesome-svg-core`,`@fortawesome/free-solid-svg-icons`,`@amsom-habitat/ui`,`vue`,`@amsom-habitat/nav-tabs`,`@amsom-habitat/horizontal-stepper`,`@amsom-habitat/amsom-autocomplete`,`@amsom-habitat/axios-overlay`,`@amsom-habitat/user-manager`,`@amsom-habitat/amsom-textarea`,`@amsom-habitat/file-manager`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Cresol={},e._fortawesome_fontawesome_svg_core,e._fortawesome_free_solid_svg_icons,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._amsom_habitat_amsom_textarea,e._amsom_habitat_file_manager))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var f=Object.create,p=Object.defineProperty,m=Object.getOwnPropertyDescriptor,h=Object.getOwnPropertyNames,g=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty,v=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=h(t),a=0,o=i.length,s;a<o;a++)s=i[a],!_.call(e,s)&&s!==n&&p(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=m(t,s))||r.enumerable});return e},y=(e,t,n)=>(n=e==null?{}:f(g(e)),v(t||!e||!e.__esModule||!_.call(e,`default`)?p(n,`default`,{value:e,enumerable:!0}):n,e));o=y(o),c=y(c,1),l=y(l,1),t.library.add(n.faBriefcase,n.faBuilding,n.faBuildingShield,n.faCheck,n.faChevronLeft,n.faChevronRight,n.faCircleExclamation,n.faCircleInfo,n.faCircleQuestion,n.faDungeon,n.faFileSignature,n.faHandsHolding,n.faHourglass,n.faHouse,n.faInfo,n.faLayerGroup,n.faLocationDot,n.faMagnifyingGlass,n.faPersonShelter,n.faSquareParking,n.faStore,n.faTag,n.faUser,n.faUserGraduate,n.faXmark);var b={T:`phone`,M:`envelope`,G:`user-shield`,V:`building`,IP:`exclamation-triangle`,C:`envelope-open`},ee=e=>b[e]??`comment-dots`,x=Object.keys(b),te=`T`,S={locataire:{libelle:`Locataire`,icon:`house-user`,couleur:`primary`},demandeur:{libelle:`Demandeur`,icon:`hourglass-half`,couleur:`info`},tiers:{libelle:`Tiers`,icon:`user-tie`,couleur:`warning`},autre:{libelle:`Autre`,icon:`user`,couleur:`secondary`},fournisseur:{libelle:`Fournisseur`,icon:`truck`,couleur:`success`},personnel:{libelle:`Personnel`,icon:`id-badge`,couleur:`dark`},inconnu:{libelle:`Inconnu`,icon:`circle-question`,couleur:`danger`}},ne=[`L`,`P`],C={...Object.fromEntries(ne.map(e=>[e,`locataire`])),D:`demandeur`,T:`tiers`,U:`autre`,F:`fournisseur`,E:`personnel`},w=Object.keys(C),T=e=>[...new Set(e.map(e=>C[e]))],E=e=>e?S[e.categorie]?e.categorie:C[e.type]??`inconnu`:null,D=e=>S[E(e)]??null,re=Symbol(`cresol:draft`),O=()=>({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}),k=()=>({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}),A=[`reclamant`,`provenance`,`motif`,`cible`,`description`,`dateFaits`,`responsable`,`fichier`],j=(e=`T`)=>({reclamant:{type:null,id:null},provenance:e,lignes:[{...k(),cibleMode:`contrat`,patrimoine:O(),description:``}]}),ie=e=>e?.id??e??null,ae=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`},oe=e=>!!e&&(e.idModule!=null||e.idEntree!=null),se=(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:oe(e.patrimoine),ce=(e,t)=>e.description==null?!t:e.description.trim().length>0,le=(e={})=>{let t={...k(),...e};return e.patrimoine&&(t.patrimoine={...O(),...e.patrimoine}),t},ue=e=>{let t=j();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],...le(e)}:le(e)):t.lignes}};function de({reclamants:e,modules:t,idModulePrefere:n=(0,i.ref)(null),readonly:r=(0,i.ref)(!1)}={}){let a=(0,i.reactive)(j()),o=(0,i.computed)(()=>{let e=(0,i.unref)(r);return e===!0?A:Array.isArray(e)?e:[]}),s=e=>o.value.includes(e),c=(0,i.computed)(()=>a.lignes[0]),l=(0,i.computed)(()=>a.lignes.slice(1)),u=(0,i.computed)(()=>(0,i.unref)(e)??[]),d=(0,i.ref)(null),f=(e,t)=>e.type===t.type&&String(e.id)===String(t.id),p=(0,i.computed)(()=>{let e=d.value;return!e||u.value.some(t=>f(t,e))?u.value:[...u.value,e]}),m=(0,i.computed)(()=>p.value.find(e=>f(e,a.reclamant))??p.value[0]??null),h=(0,i.ref)(!1),g=(0,i.ref)(0),_=(0,i.computed)(()=>{let e=(0,i.unref)(t)??[],r=(0,i.unref)(n);return(r==null?null:e.find(e=>String(e.idModule)===String(r)))??e.find(e=>e.estModulePrincipal)??e[0]??null}),v=(0,i.computed)(()=>!!m.value&&ne.includes(m.value.type)),y={draft:a,lignePrincipale:c,lignesAssociees:l,reclamantsFournis:u,reclamantsDisponibles:p,reclamantSelectionne:m,moduleReclamantPrincipal:_,reclamantEstContrat:v,ciblesValid:(0,i.computed)(()=>a.lignes.every(e=>se(e,v.value))),detailsValid:(0,i.computed)(()=>a.lignes.every((e,t)=>ce(e,t===0))),isReadonly:s,ciblesAssocieesReinitialisees:g,ligneCibleValid(e){let t=a.lignes[e];return!!t&&se(t,v.value)},reset(e=null){let t=e?.lignes?.[0];h.value=!!t&&[`cibleMode`,`patrimoine`,`contratCible`].some(e=>t[e]!=null),g.value=0;let n=ue(e);Object.assign(a,n),a.lignes=n.lignes},setProvenance(e){a.provenance=e},libererCibleFournie(){h.value=!1},syncReclamant(){let e=m.value;y.setReclamant({type:e?.type??null,id:e?.id??null})},selectReclamant(e){e&&(f(e,a.reclamant)||(h.value=!1),u.value.some(t=>f(t,e))||(d.value=e),y.setReclamant(e))},setReclamant({type:e,id:t}){let n=!f({type:e,id:t},a.reclamant);if(a.reclamant={type:e??null,id:t??null},s(`cible`)||h.value)return;let r=a.lignes[0];if(n){let e=a.lignes.filter((e,t)=>t>0&&e.cibleOverride);a.lignes.forEach((e,t)=>{t>0&&e.cibleOverride&&y.toggleCibleOverride(t)}),e.length&&(g.value=e.length)}e===`D`?(r.cibleMode=`demande`,r.patrimoine=null):(r.cibleMode=v.value?`contrat`:`patrimoine`,r.contratReclamant=v.value,r.contratCible=null,r.reprendreLocataireActuel=!1,r.patrimoine=O(),y.prefillCiblePrincipale())},prefillCiblePrincipale(){if(s(`cible`)||h.value)return;let e=_.value;e&&y.prefillFromModule(0,e)},_resetAfterNomenclature(){g.value=0,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,y._resetAfterNomenclature()},setType(e){let t=a.lignes[0];t.idType=e,t.idNature=null,t.idMotif=null,y._resetAfterNomenclature()},setNature(e){let t=a.lignes[0];t.idNature=e,t.idMotif=null,y._resetAfterNomenclature()},setMotif(e){a.lignes[0].idMotif=e,y._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,y._resetAfterNomenclature()},toggleLigneAssociee(e,t={}){let n=a.lignes.findIndex((t,n)=>n>0&&t.idMotif===e);n===-1?a.lignes.push({...k(),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`&&v.value,n.contratCible=null,t===`demande`?n.patrimoine=null:n.patrimoine??=O())},setModulePrecis(e,t){let n=a.lignes[e];n&&(n.modulePrecis=!!t,n.modulePrecis||y.setPatrimoineModule(e,null))},toggleContratReclamant(e,t){let n=a.lignes[e];n&&(n.contratReclamant=t??!n.contratReclamant,n.contratCible=null,n.patrimoine&&y.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,y.setPatrimoineModule(e,null))},setPatrimoineCommune(e,t){let n=y._patrimoine(e);n&&(n.idCommune=t?.idCommune??null,n.commune=t?.commune??null,y.setPatrimoineEntree(e,null))},setPatrimoineEntree(e,t){let n=y._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,y.setPatrimoineModule(e,null))},setPatrimoineEtage(e,t){let n=y._patrimoine(e);n&&(n.etage=t,y.setPatrimoineModule(e,null))},setPatrimoineModule(e,t){let n=y._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=y._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;g.value=0;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:ie(e.responsable)};if(r.cibleMode===`demande`)return{...c,codeTypeCible:`D`,idCible:a.reclamant.id,deduireCible:!1};let l=y._patrimoinePayload(r.patrimoine);if(r.cibleMode===`contrat`&&!r.reprendreLocataireActuel){let e=r.contratReclamant&&v.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=ae(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&&v.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)=>y._lignePayload(e,t))},creationPayload(){let e=m.value;return{typeReclamant:e?.type??null,reclamant:e?.id??null,lignes:y.lignesPayload(),provenance:a.provenance}}};return(0,i.reactive)(y)}function fe(e){return(0,i.provide)(re,e),e}function M(){let e=(0,i.inject)(re,null);if(!e)throw Error(`useSollicitationDraft() hors de <creer-sollicitation-form>`);return e}var N=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},pe={name:`AsideBlock`,components:{AmsomNavTabsHorizontal:a.AmsomNavTabsHorizontal},props:{nbSimilaires:{type:Number,default:0}},setup(){return{draft:M()}},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)}}}},me={key:0,class:`badge bg-danger ms-1`},he={style:{"min-height":`320px`}},ge={key:0},_e={key:1};function ve(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`),c=(0,i.resolveComponent)(`amsom-nav-tabs-horizontal`);return o.tabs.length?((0,i.openBlock)(),(0,i.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,i.withCtx)(({item:e})=>[(0,i.createVNode)(s,{icon:e.icon},null,8,[`icon`]),(0,i.createElementVNode)(`span`,null,(0,i.toDisplayString)(e.label),1),e.id===`similarite`&&n.nbSimilaires>0?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,me,(0,i.toDisplayString)(n.nbSimilaires),1)):(0,i.createCommentVNode)(``,!0)]),content:(0,i.withCtx)(()=>[(0,i.createElementVNode)(`div`,he,[e.$slots.similaires?(0,i.withDirectives)(((0,i.openBlock)(),(0,i.createElementBlock)(`div`,ge,[(0,i.renderSlot)(e.$slots,`similaires`,(0,i.normalizeProps)((0,i.guardReactiveProps)(o.scope)))],512)),[[i.vShow,a.activeTab===`similarite`]]):(0,i.createCommentVNode)(``,!0),e.$slots.evenements?(0,i.withDirectives)(((0,i.openBlock)(),(0,i.createElementBlock)(`div`,_e,[(0,i.renderSlot)(e.$slots,`evenements`)],512)),[[i.vShow,a.activeTab===`evenements`]]):(0,i.createCommentVNode)(``,!0)])]),_:3},8,[`modelValue`,`items`])):(0,i.createCommentVNode)(``,!0)}var ye=N(pe,[[`render`,ve]]),be={name:`SectionComponent`,props:{titre:{type:String,required:!0},aide:{type:String,default:null}}},xe={class:`d-flex flex-column gap-2`},Se={class:`d-flex flex-wrap align-items-center justify-content-between gap-2`},Ce={class:`fs-6 fw-semibold`},we={key:0,class:`text-muted d-flex align-items-center gap-1`};function Te(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`);return(0,i.openBlock)(),(0,i.createElementBlock)(`section`,xe,[(0,i.createElementVNode)(`div`,null,[(0,i.createElementVNode)(`div`,Se,[(0,i.createElementVNode)(`span`,Ce,(0,i.toDisplayString)(n.titre),1),(0,i.renderSlot)(e.$slots,`actions`)]),n.aide?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,we,[(0,i.createVNode)(s,{icon:`circle-info`}),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(n.aide),1)])):(0,i.createCommentVNode)(``,!0)]),(0,i.renderSlot)(e.$slots,`default`)])}var P=N(be,[[`render`,Te]]),Ee=e=>`fa`+e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);async function F(e){let n=await import(`@fortawesome/free-solid-svg-icons`);[...new Set(e.filter(Boolean))].forEach(e=>{let r=n[Ee(e)];r&&t.library.add(r)})}function I(e,t=!0){if(!e)return null;let n=e.toString().normalize(`NFD`).replace(/[̀-ͯ]/g,``);return t?n.toLowerCase():n}var De={name:`IconSelectComponent`,components:{AmsomAutocomplete:s.AmsomAutocomplete},props:{modelValue:{type:[String,Number],default:null},items:{type:Array,default:()=>[]},label:{type:String,required:!0},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},placeholder:{type:String,default:`Choisir…`}},emits:[`update:modelValue`],data(){return{iconsReady:!1}},computed:{selected(){return this.items.find(e=>e.id===this.modelValue)??null}},watch:{items:{immediate:!0,async handler(e){await F(e.map(e=>e.icon)),this.iconsReady=!0}}},methods:{filtrer({search:e,items:t}){let n=(I(e)??``).trim();return n?t.filter(e=>(I(e?.libelle)??``).includes(n)):t}}},Oe={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},ke={key:0,class:`ms-1 text-danger`},Ae={class:`d-inline-flex align-items-center gap-2`};function je(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`),c=(0,i.resolveComponent)(`amsom-autocomplete`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,null,[(0,i.createElementVNode)(`label`,Oe,[(0,i.createTextVNode)((0,i.toDisplayString)(n.label),1),n.required?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,ke,`*`)):(0,i.createCommentVNode)(``,!0)]),a.iconsReady?((0,i.openBlock)(),(0,i.createBlock)(c,{key:0,"model-value":o.selected,items:n.items,"get-id":e=>e?.id??null,"get-input-libelle":e=>e?.libelle??``,"filtering-function":o.filtrer,disabled:n.disabled,placeholder:n.placeholder,required:``,"input-size":`sm`,"onUpdate:modelValue":t[0]||=t=>e.$emit(`update:modelValue`,t?.id??null)},{options:(0,i.withCtx)(e=>[(0,i.createElementVNode)(`span`,Ae,[e?.icon?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,icon:e.icon,"fixed-width":``},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(e?.libelle),1)])]),_:1},8,[`model-value`,`items`,`get-id`,`get-input-libelle`,`filtering-function`,`disabled`,`placeholder`])):(0,i.createCommentVNode)(``,!0)])}var Me=N(De,[[`render`,je]]),Ne={baseUrl:``,getToken:()=>l.default.getToken(),setToken:e=>l.default.setToken(e),logout:()=>l.default.logout(),goToLoginPage:()=>l.default.goToLoginPage()};function Pe(e={}){Object.assign(Ne,e)}var L=()=>Ne;function Fe(e,t={}){let n=L(),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,c.default)(e,t)}var Ie=(e,t)=>{let n=t||L().baseUrl;if(!n)throw Error(`Cresol : baseUrl non renseignée (configureCresol ou prop baseUrl)`);return`${n}${e}`},Le=(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}`:``},Re=({method:e,path:t,params:n,data:r,signal:i,baseUrl:a},o={})=>Fe({url:Ie(`${t}${Le(n)}`,a),method:e,...r===void 0?{}:{data:r},...i?{signal:i}:{}},o),R=(e,{params:t,signal:n,overlay:r,baseUrl:i}={})=>Re({method:`GET`,path:e,params:t,signal:n,baseUrl:i},r).then(e=>e.data),ze=(e,t,{params:n,signal:r,overlay:i,baseUrl:a}={})=>Re({method:`POST`,path:e,params:n,data:t,signal:r,baseUrl:a},i).then(e=>e.data),Be={mustBeAuthenticated:!1},z=(e,{signal:t,baseUrl:n}={})=>R(e,{signal:t,baseUrl:n,overlay:Be}),Ve=e=>z(`/v2/sollicitation/motifs`,e),He=e=>z(`/v2/sollicitation/categories`,e),Ue=e=>z(`/v2/sollicitation/types`,e),We=e=>z(`/v2/sollicitation/natures`,e),Ge=e=>z(`/v2/sollicitation/etats`,e),Ke=({signal:e,baseUrl:t}={})=>R(`/v2/sollicitation/provenances`,{params:{estDesactive:!1},signal:e,baseUrl:t,overlay:Be}),qe=({signal:e,baseUrl:t}={})=>R(`/collaborateurs`,{params:{actif:!0},signal:e,baseUrl:t}),Je=async({signal:e,baseUrl:t}={})=>(await R(`/v2/patrimoine/communes`,{signal:e,baseUrl:t})??[]).map(e=>({idCommune:e.id,commune:e.libelle})),Ye=(e,{signal:t,baseUrl:n}={})=>R(`/v2/patrimoine/entrees`,{params:{idCommune:e},signal:t,baseUrl:n}),Xe=(e,{signal:t,baseUrl:n}={})=>R(`/v2/patrimoine/modules`,{params:{codeProgramme:e},signal:t,baseUrl:n}),Ze=({idContrat:e,typeContrat:t},{signal:n,baseUrl:r}={})=>R(`/v2/patrimoine/contrat_modules`,{params:{idContrat:e,typeContrat:t},signal:n,baseUrl:r}),Qe=({motif:e,categorie:t,type:n,nature:r},{signal:i,baseUrl:a}={})=>R(`/v2/sollicitation/responsables`,{params:{motif:e,categorie:t,type:n,nature:r},signal:i,baseUrl:a}),$e=(e,{signal:t,baseUrl:n}={})=>R(`/v2/patrimoine/contrat_module_rechercher`,{params:{recherche:e},signal:t,baseUrl:n}),et=({categorie:e,recherche:t},{signal:n,baseUrl:r}={})=>R(`/v2/cresol/reclamant_rechercher`,{params:{categorie:e,recherche:t},signal:n,baseUrl:r});function B(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 tt=e=>e?.name===`AbortError`||e?.name===`CanceledError`,nt=Symbol(`cresol:data`),rt=()=>({motifs:null,categories:null,types:null,natures:null,etats:null,provenances:null,collaborateurs:null,communes:null,adressesByCommune:{},modulesByProgramme:{},modulesByContrat:{},responsablesByMotif:{}}),V=new Map,it=e=>(V.has(e)||V.set(e,(0,i.reactive)(rt())),V.get(e)),H=new Map;function at(){V.clear(),H.clear()}var U=(e,t,n)=>e?.find(e=>e[t]===n)?.libelle??n,W=(e,t,n)=>e?.find(e=>e[t]===n)?.icon??null;function ot({onError:e,baseUrl:t}={}){let n=(0,i.ref)(0),r=()=>({baseUrl:(0,i.unref)(t)||null}),a=()=>(0,i.unref)(t)||L().baseUrl||``,o=()=>it(a()),s=(t,r)=>{let i=`${a()}|${t}`;if(H.has(i))return H.get(i);n.value+=1;let o=Promise.resolve().then(r).catch(t=>(tt(t)||e?.(B(t)),null)).finally(()=>{--n.value,H.delete(i)});return H.set(i,o),o},c=(e,t)=>o()[e]?.length?Promise.resolve(o()[e]):s(`referentiel:${e}`,async()=>(o()[e]=await t(r()),o()[e])),l={get cache(){return o()},loading:n,isLoading:(0,i.computed)(()=>n.value>0),loadNomenclature(){return Promise.all([c(`motifs`,Ve),c(`categories`,He),c(`types`,Ue),c(`natures`,We),c(`etats`,Ge)])},loadCollaborateurs:()=>c(`collaborateurs`,qe),loadProvenances:()=>c(`provenances`,Ke),loadCommunes(){return o().communes?.length?Promise.resolve(o().communes):s(`communes`,async()=>(o().communes=await Je(r()),o().communes))},loadAdresses(e){return e==null?Promise.resolve([]):o().adressesByCommune[e]?Promise.resolve(o().adressesByCommune[e]):s(`adresses:${e}`,async()=>{let t=await Ye(e,r());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 Xe(e,r());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 i=await Ze({idContrat:e,typeContrat:t},r());return o().modulesByContrat[n]=i??[],i})},async searchContrats(e,{signal:t}={}){let n=(e??``).trim();if(!n)return[];let i=await $e(n,{...r(),signal:t}),a=new Map;for(let e of i??[]){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,dateSortie:e.dateSortieContrat??null,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 i=(t??``).trim();if(!i)return[];let a=await et({categorie:e,recherche:i},{...r(),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,idModule:t.idModule,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.dateSortie),n=t.every(e=>e!=null)?Math.max(...t):null,r=e.individus.map(e=>[e.nom,e.prenom].filter(Boolean).join(` `)).filter(Boolean).join(`, `),i={locataire:`${e.libelleReclamant||r} — Contrat ${e.type}/${e.id}`,demandeur:`${r} — ${e.libelleReclamant}`}[e.categorie];return{...e,dateSortie:n,libelle:i??e.libelleReclamant}})},loadResponsables({motif:e,categorie:t,type:n,nature:i}){return e==null?Promise.resolve([]):o().responsablesByMotif[e]?Promise.resolve(o().responsablesByMotif[e]):s(`responsables:${e}`,async()=>{let a=await Qe({motif:e,categorie:t,type:n,nature:i},r());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=>U(o().motifs,`id`,e),categorieLibelle:e=>U(o().categories,`id`,e),typeLibelle:e=>U(o().types,`id`,e),natureLibelle:e=>U(o().natures,`id`,e),etatLibelle:e=>U(o().etats,`code`,e),motifIcon:e=>W(o().motifs,`id`,e),categorieIcon:e=>W(o().categories,`id`,e),typeIcon:e=>W(o().types,`id`,e),natureIcon:e=>W(o().natures,`id`,e)};return(0,i.reactive)(l)}function st(e){return(0,i.provide)(nt,e),e}function G(){let e=(0,i.inject)(nt,null);if(!e)throw Error(`useCresolData() hors de <creer-sollicitation-form>`);return e}var ct=Symbol(`cresol:options`),lt=e=>(0,i.provide)(ct,e),K=()=>(0,i.inject)(ct,{}),ut={name:`ProvenanceSelecteurBlock`,components:{IconSelectComponent:Me},setup(){return{draft:M(),data:G(),options:K()}},computed:{provenances(){return this.options.provenances},loaded(){return this.data.cache.provenances!=null},selected(){return this.draft.draft.provenance},libelleFige(){return this.data.cache.provenances?.find(e=>e.id===this.selected)?.libelle??this.selected??`—`},provenanceChoisie(){return this.provenances.find(e=>e.id===this.selected)??null}}},dt={key:0},ft=[`value`],pt={key:1},mt={key:0,class:`fs-7 text-danger mt-1`};function ht(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`icon-select-component`);return r.draft.isReadonly(`provenance`)?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,dt,[t[1]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Provenance`,-1),(0,i.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:o.libelleFige},null,8,ft)])):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,pt,[(0,i.createVNode)(s,{"model-value":o.provenanceChoisie?.id??null,items:o.provenances,label:`Provenance`,required:``,"onUpdate:modelValue":t[0]||=e=>r.draft.setProvenance(e)},null,8,[`model-value`,`items`]),o.loaded&&!o.provenanceChoisie?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,mt,` Sélectionnez par quel canal la sollicitation vous est parvenue. `)):(0,i.createCommentVNode)(``,!0)]))}var gt=N(ut,[[`render`,ht]]);function _t(e){return e==null?``:new Date(e*1e3).toISOString().slice(0,10)}function vt(e){return e?Math.floor(new Date(e).getTime()/1e3):null}function q(e){return e==null?``:new Date(e*1e3).toLocaleDateString(`fr-FR`)}var yt=(0,i.ref)(!1);F(Object.values(S).map(e=>e.icon)).then(()=>{yt.value=!0});var bt={name:`ReclamantTypeBadgeComponent`,props:{reclamant:{type:Object,default:null},iconOnly:{type:Boolean,default:!1}},setup(){return{iconsReady:yt}},computed:{type(){return D(this.reclamant)}}},xt=[`title`],St={key:1};function Ct(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`);return o.type?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,{key:0,class:(0,i.normalizeClass)([`badge d-inline-flex align-items-center gap-1 border flex-shrink-0`,`bg-${o.type.couleur}-subtle text-${o.type.couleur}-emphasis border-${o.type.couleur}-subtle`]),title:o.type.libelle},[r.iconsReady?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,icon:o.type.icon,"fixed-width":``},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0),n.iconOnly?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`span`,St,(0,i.toDisplayString)(o.type.libelle),1))],10,xt)):(0,i.createCommentVNode)(``,!0)}var wt=N(bt,[[`render`,Ct]]),J=[{key:`locataire`,label:`Locataire`,icon:S.locataire.icon,recherche:`Rechercher un locataire`,aucun:`Aucun locataire trouvé.`,placeholder:`Nom, prénom, n° de contrat ou de module, adresse, téléphone ou mail…`},{key:`demandeur`,label:`Demandeur`,icon:S.demandeur.icon,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:S.tiers.icon,recherche:`Rechercher un tiers`,aucun:`Aucun tiers trouvé.`,placeholder:`Raison sociale, adresse, téléphone ou mail…`},{key:`autre`,label:`Autre`,icon:S.autre.icon,recherche:`Rechercher un individu « Autre »`,aucun:`Aucun individu « Autre » trouvé.`,placeholder:`Nom, prénom, adresse, téléphone ou mail…`},{key:`fournisseur`,label:`Fournisseur`,icon:S.fournisseur.icon,recherche:`Rechercher un fournisseur`,aucun:`Aucun fournisseur trouvé.`,placeholder:`Raison sociale, adresse, téléphone ou mail…`},{key:`personnel`,label:`Personnel`,icon:S.personnel.icon,recherche:`Rechercher un collaborateur`,aucun:`Aucun collaborateur trouvé.`,placeholder:`Nom, prénom, 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, de module ou de demande, adresse, téléphone ou mail…`}],Tt={signataire:`Signataire`,occupant:`Occupant`,demandeur:`Demandeur`},Et={name:`ReclamantRechercheBlock`,components:{AmsomAutocomplete:s.AmsomAutocomplete,AmsomOverlay:r.AmsomOverlay,IconSelectComponent:Me,ReclamantTypeBadgeComponent:wt},setup(){return{draft:M(),data:G(),options:K()}},data(){return{iconsReady:!1,categorie:null,trouves:[],rechercheEnCours:!1,rechercheFaite:!1}},computed:{typesAutorises(){return this.options.typesReclamant??w},autorisees(){return T(this.typesAutorises)},categories(){return J.filter(e=>e.key===`tout`?this.autorisees.length>1:this.autorisees.includes(e.key))},categoriesItems(){return this.categories.map(e=>({id:e.key,libelle:e.label,icon:e.icon}))},categorieCourante(){return J.find(e=>e.key===this.categorie)},selectionne(){return this.draft.reclamantSelectionne},selectedTrouve:{get(){return this.categorie===`tout`||this.categorieOf(this.selectionne)===this.categorie?this.selectionne:null},set(e){this.select(e)}}},watch:{selectionne(e){this.categorie!==`tout`&&(this.categorie=this.categorieOf(e)??this.categorie)}},async created(){this.categorie=this.categorieOf(this.selectionne)??this.categories[0]?.key??null,await F(J.map(e=>e.icon)),this.iconsReady=!0},beforeUnmount(){clearTimeout(this.rechercheTimeout),this.controller?.abort()},methods:{select(e){e&&this.draft.selectReclamant(e)},setCategorie(e){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===`tout`?this.autorisees.join(`,`):this.categorie,t,{signal:this.controller.signal}).then(e=>{this.trouves=(e??[]).filter(e=>this.typesAutorises.includes(e.type)),this.rechercheFaite=!0,this.rechercheEnCours=!1}).catch(()=>{this.rechercheEnCours=!1}))},cleReclamant(e){return e?`${e.type}|${e.id}`:null},categorieOf(e){let t=E(e);return this.autorisees.includes(t)?t:null},sortiLibelle(e){return e?.dateSortie==null?`sorti`:`sorti le ${q(e.dateSortie)}`},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=this.categorieOf(e);return t===`locataire`?e.libelleReclamant||this.nomsOf(e):t===`demandeur`?this.nomsOf(e):e.libelleReclamant},referenceOf(e){if(!e?.individus)return``;let t=this.categorieOf(e);return t===`locataire`?[`Contrat ${e.type}/${e.id}`,e.idModule&&`Module ${e.idModule}`].filter(Boolean).join(` — `):t===`demandeur`?e.libelleReclamant:t===`autre`?`Individu « Autre »`:D(e).libelle},detailOf(e){let t=e?.individus??[];if(![`locataire`,`demandeur`].includes(E(e))){let e=t[0];return e?[e.telephone,e.mail].filter(Boolean).join(` — `):``}return t.map(t=>{let n=[t.nom,t.prenom].filter(Boolean).join(` `),r=e.estActif&&t.dateSortie!=null&&t.dateSortie*1e3<Date.now()?`sorti le ${q(t.dateSortie)}`:null,i=[Tt[t.role]?.toLowerCase(),r].filter(Boolean).join(`, `);return i?`${n} (${i})`:n}).join(`, `)}}},Dt={class:`row g-3`},Ot={key:0,class:`col-12 col-md-6`},kt={class:`col-12`},At={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},jt={class:`min-w-0`},Mt={key:0,class:`badge bg-warning-subtle text-warning-emphasis ms-1`},Nt={class:`text-muted d-block text-truncate`},Pt={key:0},Ft={key:0,class:`text-muted d-block text-truncate`},It={key:0,class:`text-muted`};function Lt(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`icon-select-component`),c=(0,i.resolveComponent)(`reclamant-type-badge-component`),l=(0,i.resolveComponent)(`amsom-autocomplete`),u=(0,i.resolveComponent)(`amsom-overlay`);return a.iconsReady?((0,i.openBlock)(),(0,i.createBlock)(u,{key:0,loading:r.options.repriseReclamant},{default:(0,i.withCtx)(()=>[(0,i.createElementVNode)(`div`,Dt,[e.$slots[`avant-categorie`]?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Ot,[(0,i.renderSlot)(e.$slots,`avant-categorie`)])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`col-12`,{"col-md-6":e.$slots[`avant-categorie`]}])},[(0,i.createVNode)(s,{"model-value":a.categorie,items:o.categoriesItems,label:`Le réclamant est…`,"onUpdate:modelValue":t[0]||=e=>o.setCategorie(e)},null,8,[`model-value`,`items`])],2),(0,i.createElementVNode)(`div`,kt,[(0,i.createElementVNode)(`label`,At,[(0,i.createTextVNode)((0,i.toDisplayString)(o.categorieCourante.recherche),1),t[2]||=(0,i.createElementVNode)(`span`,{class:`ms-1 text-danger`},`*`,-1)]),((0,i.openBlock)(),(0,i.createBlock)(l,{key:a.categorie,modelValue:o.selectedTrouve,"onUpdate:modelValue":t[1]||=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,i.withCtx)(e=>[(0,i.createElementVNode)(`div`,jt,[(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`fw-medium text-truncate`,e?.estActif?``:`text-muted`])},[(0,i.createVNode)(c,{reclamant:e,"icon-only":``,class:`me-1`},null,8,[`reclamant`]),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(o.titreOf(e))+` `,1),e?.estActif?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`span`,Mt,(0,i.toDisplayString)(o.categorieOf(e)===`demandeur`?`inactive`:o.sortiLibelle(e)),1))],2),(0,i.createElementVNode)(`small`,Nt,[(0,i.createTextVNode)((0,i.toDisplayString)(o.referenceOf(e))+` `,1),e?.adresse?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,Pt,` — `+(0,i.toDisplayString)(e.adresse),1)):(0,i.createCommentVNode)(``,!0)]),o.detailOf(e)?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,Ft,(0,i.toDisplayString)(o.detailOf(e)),1)):(0,i.createCommentVNode)(``,!0)])]),_:1},8,[`modelValue`,`items`,`filtering-function`,`loading`,`get-id`,`get-input-libelle`,`placeholder`,`onSearch`])),a.rechercheFaite&&!a.rechercheEnCours&&!a.trouves.length?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,It,(0,i.toDisplayString)(o.categorieCourante.aucun),1)):(0,i.createCommentVNode)(``,!0)])])]),_:3},8,[`loading`])):(0,i.createCommentVNode)(``,!0)}var Rt=N(Et,[[`render`,Lt]]),zt={name:`ReclamantSelecteurBlock`,components:{AmsomAutocomplete:s.AmsomAutocomplete,ReclamantTypeBadgeComponent:wt},props:{mode:{type:String,default:null}},setup(){return{draft:M(),options:K()}},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=(I(e)??``).trim();return n?t.filter(e=>(I(e?.libelle)??``).includes(n)):t}}},Bt={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},Vt={key:0,class:`ms-1 text-danger`},Ht=[`value`],Ut={key:1,class:`btn-group btn-group-sm w-100`,role:`group`},Wt=[`onClick`],Gt=[`value`],Kt=[`value`];function qt(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`reclamant-type-badge-component`),c=(0,i.resolveComponent)(`amsom-autocomplete`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,null,[(0,i.createElementVNode)(`label`,Bt,[t[2]||=(0,i.createTextVNode)(` Réclamant`,-1),o.estFige?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`span`,Vt,`*`))]),o.estFige?((0,i.openBlock)(),(0,i.createElementBlock)(`input`,{key:0,class:`form-control form-control-sm`,disabled:``,value:o.reclamantSelectionne?.libelle??`—`},null,8,Ht)):o.presentation===`switch`?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Ut,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.reclamants,(e,t)=>((0,i.openBlock)(),(0,i.createElementBlock)(`button`,{key:t,type:`button`,class:(0,i.normalizeClass)([`btn d-inline-flex align-items-center justify-content-center`,e===o.reclamantSelectionne?`btn-primary`:`btn-outline-primary`]),onClick:t=>o.select(e)},(0,i.toDisplayString)(e.libelle),11,Wt))),128))])):o.presentation===`autocomplete`?((0,i.openBlock)(),(0,i.createBlock)(c,{key:2,"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`,required:``,"onUpdate:modelValue":t[0]||=e=>o.select(e)},{options:(0,i.withCtx)(e=>[(0,i.createVNode)(s,{reclamant:e,"icon-only":``,class:`me-1`},null,8,[`reclamant`]),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(e?.libelle),1)]),_:1},8,[`model-value`,`items`,`get-id`,`get-input-libelle`,`filtering-function`])):((0,i.openBlock)(),(0,i.createElementBlock)(`select`,{key:3,class:`form-select form-select-sm`,value:o.reclamants.indexOf(o.reclamantSelectionne),onChange:t[1]||=e=>o.select(o.reclamants[e.target.value])},[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.reclamants,(e,t)=>((0,i.openBlock)(),(0,i.createElementBlock)(`option`,{key:t,value:t},(0,i.toDisplayString)(e.libelle),9,Kt))),128))],40,Gt))])}var Jt=N(zt,[[`render`,qt]]),Yt={B:`briefcase`,M:`store`,W:`dungeon`,E:`user-graduate`,K:`building-shield`,F:`person-shelter`,S:`square-parking`,V:`hands-holding`};function Xt(e,t=!1,n=`circle-question`){return e===`L`?t?`building`:`house`:Yt[e]??n}function Zt(e){return e?e.idCategorieModule===`L`?e.estCollectif?`Appartement`:`Maison`:e.categorieModule??``:``}var Qt=0,$t={name:`CiblePickerBlock`,components:{AmsomAutocomplete:s.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:G()}},data(){return{uid:++Qt,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:{formatDate:q,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=(I(t)??``).trim();return r?n.filter(t=>(I(t?.[e])??``).includes(r)):n}},filterModules({search:e,items:t}){let n=(I(e)??``).trim();return n?t.filter(e=>String(e?.idModule??``).includes(n)||(I(this.moduleInputLibelle(e))??``).includes(n)||(I(e?._autreLibelle)??``).includes(n)):t},getCategorieModuleIcon:Xt,categorieLibelle:Zt,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)}}},en={class:`d-flex flex-column gap-3`},tn={class:`btn-group w-100`,role:`group`},nn=[`onClick`],rn={class:`text-muted d-block mt-1`},an={key:0,class:`form-check`},on=[`id`,`checked`],sn=[`for`],cn={key:1},ln={class:`min-w-0`},un={class:`fw-medium text-truncate text-capitalize`},dn={class:`d-flex flex-wrap align-items-center gap-1`},fn={class:`text-muted`},pn={key:0,class:`badge bg-info`},mn={key:1,class:`badge bg-warning`},hn={key:0,class:`text-muted d-block text-truncate`},gn={key:1},_n={class:`row g-2`},vn=[`aria-pressed`,`onClick`],yn={class:`min-w-0`},bn={class:`d-block fw-semibold fs-6`},xn={class:`d-block text-muted`},Sn={key:2,class:`row g-3`},Cn={class:`min-w-0`},wn={class:`fw-medium text-truncate`},Tn={class:`text-muted d-block text-truncate`},En=[`value`],Dn=[`value`],On=[`value`],kn={key:0,class:`col-12 col-md-6`},An={class:`d-flex flex-wrap align-items-center gap-1`},jn=[`title`],Mn={class:`text-muted`},Nn={key:1,class:`d-block text-truncate`},Pn={key:2,class:`text-muted d-block`},Fn={key:0,class:`mt-2 d-flex flex-column gap-2`},In={class:`form-check mb-0 ms-3`},Ln=[`id`,`checked`],Rn=[`for`];function zn(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`),c=(0,i.resolveComponent)(`amsom-autocomplete`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,en,[(0,i.createElementVNode)(`div`,null,[t[7]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` La sollicitation concerne… `,-1),(0,i.createElementVNode)(`div`,tn,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.availableModes,t=>((0,i.openBlock)(),(0,i.createElementBlock)(`button`,{key:t.key,type:`button`,class:(0,i.normalizeClass)([`btn btn-sm`,n.cibleMode===t.key?`btn-primary`:`btn-outline-primary`]),onClick:n=>e.$emit(`change-mode`,t.key)},[(0,i.createVNode)(s,{icon:t.icon,class:`me-1`},null,8,[`icon`]),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(t.label),1)],10,nn))),128))]),(0,i.createElementVNode)(`small`,rn,(0,i.toDisplayString)(o.currentMode?.aide),1)]),n.cibleMode===`contrat`?((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:0},[n.afficheCaseContratReclamant?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,an,[(0,i.createElementVNode)(`input`,{id:`contrat-reclamant-${a.uid}`,class:`form-check-input`,type:`checkbox`,checked:n.contratReclamant,onChange:t[0]||=t=>e.$emit(`toggle-contrat-reclamant`,t.target.checked)},null,40,on),(0,i.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`contrat-reclamant-${a.uid}`},` Contrat du réclamant `,8,sn)])):(0,i.createCommentVNode)(``,!0),n.contratReclamant?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,cn,[t[8]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Contrat ciblé `,-1),(0,i.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,i.withCtx)(e=>[(0,i.createElementVNode)(`div`,ln,[(0,i.createElementVNode)(`div`,un,(0,i.toDisplayString)(e?.libelle??`Contrat ${e?.idContrat}`),1),(0,i.createElementVNode)(`div`,dn,[(0,i.createElementVNode)(`small`,fn,`N° `+(0,i.toDisplayString)(e?.typeContrat)+`/`+(0,i.toDisplayString)(e?.idContrat),1),e?.nbModules>1?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,pn,(0,i.toDisplayString)(e.nbModules)+` modules`,1)):(0,i.createCommentVNode)(``,!0),e?.estSorti?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,mn,(0,i.toDisplayString)(e.dateSortie?`Sorti le ${o.formatDate(e.dateSortie)}`:`Sorti`),1)):(0,i.createCommentVNode)(``,!0)]),o.contratAdresse(e)?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,hn,(0,i.toDisplayString)(o.contratAdresse(e)),1)):(0,i.createCommentVNode)(``,!0)])]),_:1},8,[`modelValue`,`items`,`filtering-function`,`loading`,`get-id`,`get-input-libelle`,`onSearch`])]))],64)):(0,i.createCommentVNode)(``,!0),n.cibleMode===`patrimoine`?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,gn,[t[9]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Le problème concerne… `,-1),(0,i.createElementVNode)(`div`,_n,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.portees,t=>((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:t.titre,class:`col-12 col-md-6`},[(0,i.createElementVNode)(`button`,{type:`button`,class:(0,i.normalizeClass)([`btn w-100 h-100 text-start d-flex align-items-center gap-3 p-3 rounded border text-primary`,t.modulePrecis===n.modulePrecis?`border-primary bg-light`:`bg-white`]),"aria-pressed":t.modulePrecis===n.modulePrecis,onClick:n=>e.$emit(`set-module-precis`,t.modulePrecis)},[(0,i.createVNode)(s,{icon:t.icon,class:`fs-4`,"fixed-width":``},null,8,[`icon`]),(0,i.createElementVNode)(`span`,yn,[(0,i.createElementVNode)(`span`,bn,(0,i.toDisplayString)(t.titre),1),(0,i.createElementVNode)(`small`,xn,(0,i.toDisplayString)(t.aide),1)])],10,vn)]))),128))])])):(0,i.createCommentVNode)(``,!0),n.cibleMode===`contrat`||n.cibleMode===`patrimoine`?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Sn,[(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`col-12 d-flex flex-column gap-3`,{"col-md-6":o.afficheModule}])},[n.cibleMode===`patrimoine`?((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:0},[(0,i.createElementVNode)(`div`,null,[t[10]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Commune `,-1),(0,i.createVNode)(c,{modelValue:o.selectedCommune,"onUpdate:modelValue":t[2]||=e=>o.selectedCommune=e,items:r.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,i.createElementVNode)(`div`,null,[t[11]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Adresse `,-1),(0,i.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:!n.patrimoine.idCommune,placeholder:`Rechercher une adresse…`,"input-size":`sm`,"hide-choices":``},{options:(0,i.withCtx)(e=>[(0,i.createElementVNode)(`div`,Cn,[(0,i.createElementVNode)(`div`,wn,(0,i.toDisplayString)(e?.entree),1),(0,i.createElementVNode)(`small`,Tn,(0,i.toDisplayString)(e?.commune)+` — Programme `+(0,i.toDisplayString)(e?.codeProgramme),1)])]),_:1},8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`filtering-function`,`disabled`])]),(0,i.createElementVNode)(`div`,null,[t[12]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Étage`,-1),(0,i.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:!n.patrimoine.idEntree,placeholder:`Tous les étages…`,"input-size":`sm`,"hide-choices":``},null,8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`disabled`])])],64)):((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:1},[(0,i.createElementVNode)(`div`,null,[t[13]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Commune `,-1),(0,i.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:n.patrimoine.commune??`—`},null,8,En)]),(0,i.createElementVNode)(`div`,null,[t[14]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Adresse `,-1),(0,i.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:n.patrimoine.entree??`—`},null,8,Dn)]),(0,i.createElementVNode)(`div`,null,[t[15]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Étage`,-1),(0,i.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:n.patrimoine.etage??`—`},null,8,On)])],64))],2),o.afficheModule?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,kn,[t[16]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Module`,-1),(0,i.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,i.withCtx)(e=>[(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`min-w-0 w-100 rounded position-relative`,e?._autreLibelle?`bg-yellow-subtle p-2`:``])},[e?._autreLibelle?((0,i.openBlock)(),(0,i.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,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`fw-medium text-truncate`,[e?._autreLibelle?`text-muted`:``,o.isExit(e)?`text-decoration-line-through`:``]])},(0,i.toDisplayString)(o.moduleLibelle(e)),3),(0,i.createElementVNode)(`div`,An,[o.categorieLibelle(e)?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,{key:0,class:`badge bg-info`,title:e?.categorieModule},[(0,i.createVNode)(s,{icon:o.getCategorieModuleIcon(e?.idCategorieModule,e?.estCollectif)},null,8,[`icon`])],8,jn)):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`small`,Mn,`N° `+(0,i.toDisplayString)(e?.idModule),1)]),e?._autreLibelle?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,Nn,(0,i.toDisplayString)(e._autreLibelle),1)):e?.etage==null?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`small`,Pn,` Étage `+(0,i.toDisplayString)(e.etage),1))],2)]),_:1},8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`filtering-function`,`disabled`]),n.locataireActuelOption?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Fn,[(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`alert d-flex align-items-start gap-2 py-2 px-3 mt-2 mb-0 fs-7`,n.locataireActuelOption.reprendre?`alert-warning`:`alert-secondary border`])},[(0,i.createVNode)(s,{icon:`circle-info`,class:`mt-1`}),(0,i.createElementVNode)(`span`,null,(0,i.toDisplayString)(n.locataireActuelOption.hint),1)],2),(0,i.createElementVNode)(`div`,In,[(0,i.createElementVNode)(`input`,{id:`locataire-actuel-${a.uid}`,class:`form-check-input`,type:`checkbox`,checked:n.locataireActuelOption.reprendre,onChange:t[6]||=t=>e.$emit(`toggle-reprendre-locataire-actuel`,t.target.checked)},null,40,Ln),(0,i.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`locataire-actuel-${a.uid}`},` Rattacher au locataire actuel du module `,8,Rn)])])):(0,i.createCommentVNode)(``,!0)])):(0,i.createCommentVNode)(``,!0)])):(0,i.createCommentVNode)(``,!0)])}var Bn=N($t,[[`render`,zn]]),Vn=0,Hn={name:`LigneCibleBlock`,components:{AmsomOverlay:r.AmsomOverlay,CiblePickerBlock:Bn},props:{index:{type:Number,required:!0}},setup(){return{draft:M(),data:G(),options:K()}},data(){return{uid:++Vn}},computed:{isPrincipale(){return this.index===0},ligne(){return this.draft.draft.lignes[this.index]},cibleFigee(){return this.draft.isReadonly(`cible`)},reclamantModules(){return this.options.modulesReclamant??[]},mainModule(){return this.draft.moduleReclamantPrincipal},localisation(){let e=this.ligne?.patrimoine;return{actif:!this.cibleFigee&&!!e&&this.ligne.cibleMode!==`demande`,idCommune:e?.idCommune??null,codeProgramme:this.ligne?.cibleMode===`patrimoine`?e?.codeProgramme??null:null}},locataireActuelOption(){let e=this.ligne;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}}},watch:{localisation:{immediate:!0,deep:!0,handler({actif:e,idCommune:t,codeProgramme:n}){e&&(this.data.loadCommunes(),this.data.loadAdresses(t),this.data.loadModulesOfProgramme(n))}}},created(){this.isPrincipale&&!this.cibleFigee&&!this.draft.reclamantEstContrat&&this.ligne.cibleMode===`contrat`&&this.draft.setCibleMode(0,`patrimoine`)},methods:{onChangeMode(e){this.draft.setCibleMode(this.index,e),e!==`demande`&&this.draft.prefillFromModule(this.index,this.mainModule)},onSelectModule(e){e&&this.ligne.cibleMode===`contrat`?this.draft.prefillFromModule(this.index,e):this.draft.setPatrimoineModule(this.index,e??null)},onToggleContratReclamant(e){this.draft.toggleContratReclamant(this.index,e),e&&this.draft.prefillFromModule(this.index,this.mainModule)},onSelectContrat(e){this.draft.setContratCible(this.index,e),e&&this.data.loadModulesOfContrat({idContrat:e.idContrat,typeContrat:e.typeContrat})}}},Un={key:0,class:`d-flex flex-wrap align-items-center gap-2`},Wn={class:`fw-medium fs-7`},Gn={key:0,class:`form-check form-switch mb-0`},Kn=[`id`,`checked`],qn=[`for`];function Jn(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`),c=(0,i.resolveComponent)(`cible-picker-block`),l=(0,i.resolveComponent)(`amsom-overlay`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,{class:(0,i.normalizeClass)({"border rounded p-2":!o.isPrincipale})},[o.isPrincipale?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Un,[(0,i.createElementVNode)(`span`,Wn,(0,i.toDisplayString)(o.ligne.libelle),1),o.cibleFigee?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Gn,[(0,i.createElementVNode)(`input`,{id:`memecible-${a.uid}`,class:`form-check-input`,type:`checkbox`,checked:!o.ligne.cibleOverride,onChange:t[0]||=e=>r.draft.toggleCibleOverride(n.index)},null,40,Kn),(0,i.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`memecible-${a.uid}`},` Même cible que la ligne principale `,8,qn)]))])),o.cibleFigee?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:1,class:(0,i.normalizeClass)([`fs-7`,{"mt-1":!o.isPrincipale}])},[(0,i.createVNode)(s,{icon:`location-dot`,class:`text-primary me-2`}),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(r.draft.cibleResume(o.ligne)),1)],2)):o.isPrincipale||o.ligne.cibleOverride?((0,i.openBlock)(),(0,i.createBlock)(l,{key:2,loading:r.data.isLoading&&!r.data.cache.communes?.length},{default:(0,i.withCtx)(()=>[(0,i.createVNode)(c,{class:(0,i.normalizeClass)({"mt-2":!o.isPrincipale}),patrimoine:o.ligne.patrimoine,"cible-mode":o.ligne.cibleMode,"reclamant-modules":o.reclamantModules,"reclamant-type":r.draft.draft.reclamant.type,"contrat-reclamant":o.ligne.contratReclamant,"contrat-cible":o.ligne.contratCible,"module-precis":o.ligne.modulePrecis,"affiche-case-contrat-reclamant":r.draft.reclamantEstContrat,"locataire-actuel-option":o.locataireActuelOption,onChangeMode:o.onChangeMode,onSelectCommune:t[1]||=e=>r.draft.setPatrimoineCommune(n.index,e??null),onSelectAdresse:t[2]||=e=>r.draft.setPatrimoineEntree(n.index,e??null),onSelectEtage:t[3]||=e=>r.draft.setPatrimoineEtage(n.index,e??null),onSelectModule:o.onSelectModule,onSelectContrat:o.onSelectContrat,onToggleContratReclamant:o.onToggleContratReclamant,onToggleReprendreLocataireActuel:t[4]||=e=>r.draft.setReprendreLocataireActuel(n.index,e),onSetModulePrecis:t[5]||=e=>r.draft.setModulePrecis(n.index,e)},null,8,[`class`,`patrimoine`,`cible-mode`,`reclamant-modules`,`reclamant-type`,`contrat-reclamant`,`contrat-cible`,`module-precis`,`affiche-case-contrat-reclamant`,`locataire-actuel-option`,`onChangeMode`,`onSelectModule`,`onSelectContrat`,`onToggleContratReclamant`])]),_:1},8,[`loading`])):(0,i.createCommentVNode)(``,!0)],2)}var Yn=N(Hn,[[`render`,Jn]]),Xn={name:`EtapeReclamantCibleBlock`,components:{SectionComponent:P,ProvenanceSelecteurBlock:gt,ReclamantRechercheBlock:Rt,ReclamantSelecteurBlock:Jt,LigneCibleBlock:Yn},setup(){return{draft:M(),options:K()}}},Zn={class:`d-flex flex-column gap-4`},Qn={key:2,class:`row g-3`},$n={class:`col-12 col-md-6`},er={class:`col-12 col-md-6`};function tr(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`provenance-selecteur-block`),c=(0,i.resolveComponent)(`reclamant-recherche-block`),l=(0,i.resolveComponent)(`reclamant-selecteur-block`),u=(0,i.resolveComponent)(`section-component`),d=(0,i.resolveComponent)(`ligne-cible-block`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,Zn,[(0,i.createVNode)(u,{titre:`Réclamant`,aide:`La personne à l’origine de la sollicitation : locataire, tiers, fournisseur…`},{default:(0,i.withCtx)(()=>[e.$slots.reclamant?((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:0},[(0,i.createVNode)(s),(0,i.renderSlot)(e.$slots,`reclamant`,{reclamant:r.draft.reclamantSelectionne,select:r.draft.selectReclamant})],64)):r.options.rechercheReclamant?((0,i.openBlock)(),(0,i.createBlock)(c,{key:1},{"avant-categorie":(0,i.withCtx)(()=>[(0,i.createVNode)(s)]),_:1})):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Qn,[(0,i.createElementVNode)(`div`,$n,[(0,i.createVNode)(s)]),(0,i.createElementVNode)(`div`,er,[(0,i.createVNode)(l)])]))]),_:3}),r.draft.reclamantSelectionne?((0,i.openBlock)(),(0,i.createBlock)(u,{key:0,titre:`Cible`,aide:r.draft.draft.reclamant.type===`D`?`Une demande de logement se cible elle-même`:`Ce sur quoi porte la sollicitation : un contrat ou un élément du patrimoine`},{default:(0,i.withCtx)(()=>[(0,i.createVNode)(d,{index:0})]),_:1},8,[`aide`])):(0,i.createCommentVNode)(``,!0)])}var nr=N(Xn,[[`render`,tr]]),rr={name:`SeparateurComponent`,props:{texte:{type:String,required:!0}}},ir={class:`d-flex align-items-center gap-2 text-muted fs-7`};function ar(e,t,n,r,a,o){return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,ir,[t[0]||=(0,i.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`},null,-1),(0,i.createElementVNode)(`span`,null,(0,i.toDisplayString)(n.texte),1),t[1]||=(0,i.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`},null,-1)])}var or=N(rr,[[`render`,ar]]),sr={reclamant:{icon:`user`,label:`Réclamant`},cible:{icon:`location-dot`,label:`Cible`},motif:{icon:`tag`,label:`Motif`}},cr={name:`RecapBlock`,props:{index:{type:Number,default:0},champs:{type:Array,default:()=>[`reclamant`,`cible`,`motif`],validator:e=>e.every(e=>sr[e])}},setup(){return{draft:M(),data:G()}},computed:{ligne(){return this.draft.draft.lignes[this.index]},valeurs(){return{reclamant:this.reclamant,cible:this.ligne?this.draft.cibleResume(this.ligne):null,motif:this.motif}},reclamant(){let e=this.draft.reclamantSelectionne?.libelle;if(!e)return null;let t=this.data.cache.provenances?.find(e=>e.id===this.draft.draft.provenance)?.libelle;return t?`${e} · via ${t}`:e},motif(){let e=this.ligne;return e?.idMotif?this.index>0?e.libelle??this.data.motifLibelle(e.idMotif):[this.data.categorieLibelle(e.idCategorie),this.data.typeLibelle(e.idType),this.data.natureLibelle(e.idNature),this.data.motifLibelle(e.idMotif)].filter(Boolean).join(` › `):null},items(){return this.champs.map(e=>({champ:e,...sr[e],valeur:this.valeurs[e]})).filter(e=>e.valeur)}}},lr={class:`alert alert-light border py-2 px-3 mb-0 d-flex flex-column gap-1`},ur={class:`text-muted text-uppercase fw-semibold text-nowrap`},dr={class:`min-w-0`};function fr(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,lr,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.items,e=>((0,i.openBlock)(),(0,i.createElementBlock)(`span`,{key:e.champ,class:`fs-7 d-flex align-items-start gap-2`},[(0,i.createVNode)(s,{icon:e.icon,class:`text-primary mt-1`,"fixed-width":``},null,8,[`icon`]),(0,i.createElementVNode)(`span`,ur,(0,i.toDisplayString)(e.label),1),(0,i.createElementVNode)(`span`,dr,(0,i.toDisplayString)(e.valeur),1)]))),128))])}var pr=N(cr,[[`render`,fr]]),mr={name:`MotifChaineComponent`,props:{chaine:{type:Array,default:()=>[]},readonly:{type:Boolean,default:!1}},emits:[`retirer`]},hr={class:`d-flex flex-wrap align-items-center gap-2`},gr=[`onClick`],_r={key:2,class:`badge rounded-pill bg-primary d-inline-flex align-items-center gap-2`};function vr(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,hr,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(n.chaine,(t,r)=>((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:t.key},[r>0?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,icon:`chevron-right`,class:`text-muted fs-7`})):(0,i.createCommentVNode)(``,!0),n.readonly?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,_r,[t.icon?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,icon:t.icon,"fixed-width":``},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(t.libelle),1)])):((0,i.openBlock)(),(0,i.createElementBlock)(`button`,{key:1,type:`button`,class:`btn btn-sm btn-primary rounded-pill d-inline-flex align-items-center gap-2`,onClick:n=>e.$emit(`retirer`,t.key)},[t.icon?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,icon:t.icon,"fixed-width":``},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`span`,null,(0,i.toDisplayString)(t.libelle),1),(0,i.createVNode)(s,{icon:`xmark`,class:`fs-7 opacity-75`})],8,gr))],64))),128))])}var yr=N(mr,[[`render`,vr]]),Y=[{key:`categorie`,titre:`Catégorie`,idKey:`idCategorie`,libelleKey:`categorie`},{key:`type`,titre:`Type`,idKey:`idType`,libelleKey:`type`},{key:`nature`,titre:`Nature`,idKey:`idNature`,libelleKey:`nature`},{key:`motif`,titre:`Motif`,idKey:`idMotif`,libelleKey:`libelle`}],X=e=>e.filter(e=>e.selectedId!=null).map(e=>{let t=e.options.find(t=>t.id===e.selectedId);return{key:e.key,libelle:t?.libelle??e.selectedId,icon:t?.icon??null}}),br={name:`MotifBubbleBlock`,components:{MotifChaineComponent:yr},props:{niveaux:{type:Array,required:!0}},emits:[`choisir`,`retirer`],computed:{chaine(){return X(this.niveaux)},courant(){return this.niveaux.find(e=>e.selectedId==null)??null}}},xr={class:`d-flex flex-column gap-3`},Sr={key:1},Cr={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-2`},wr={class:`row justify-content-around g-3`},Tr=[`title`,`onClick`],Er={class:`fs-7 mt-1 lh-sm`},Dr={key:0,class:`col-12 text-muted fs-7`};function Or(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`motif-chaine-component`),c=(0,i.resolveComponent)(`font-awesome-icon`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,xr,[o.chaine.length?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,chaine:o.chaine,onRetirer:t[0]||=t=>e.$emit(`retirer`,t)},null,8,[`chaine`])):(0,i.createCommentVNode)(``,!0),o.courant?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Sr,[(0,i.createElementVNode)(`label`,Cr,(0,i.toDisplayString)(o.courant.titre),1),(0,i.createElementVNode)(`div`,wr,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.courant.options,t=>((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:t.id,class:`col-3 text-center`},[(0,i.createElementVNode)(`button`,{type:`button`,class:`btn btn-lg btn-outline-primary btn-circle d-flex align-items-center justify-content-center mx-auto`,title:t.libelle,onClick:n=>e.$emit(`choisir`,{key:o.courant.key,id:t.id})},[t.icon?((0,i.openBlock)(),(0,i.createBlock)(c,{key:0,icon:t.icon,size:`lg`},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0)],8,Tr),(0,i.createElementVNode)(`div`,Er,(0,i.toDisplayString)(t.libelle),1)]))),128)),o.courant.options.length?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Dr,` Aucun choix disponible `))])])):(0,i.createCommentVNode)(``,!0)])}var kr=N(br,[[`render`,Or]]),Ar={categorie:`une catégorie`,type:`un type`,nature:`une nature`},jr={name:`MotifColonnesBlock`,props:{niveaux:{type:Array,required:!0}},emits:[`choisir`],methods:{article(e){return Ar[e.key]??e.titre.toLowerCase()}}},Mr={class:`row g-0 border rounded overflow-hidden`},Nr={class:`d-flex align-items-center justify-content-between bg-light border-bottom px-2 py-1`},Pr={class:`fs-7 fw-semibold text-muted text-uppercase`},Fr={key:0,class:`badge bg-secondary`},Ir={class:`list-group list-group-flush overflow-auto`,style:{"max-height":`260px`}},Lr=[`aria-pressed`,`onClick`],Rr={class:`flex-grow-1 lh-sm text-start`},zr={key:0,class:`text-muted fst-italic p-2`};function Br(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,Mr,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(n.niveaux,(t,r)=>((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:t.key,class:(0,i.normalizeClass)([`col-6 col-md-3 d-flex flex-column`,{"border-start":r>0}])},[(0,i.createElementVNode)(`div`,Nr,[(0,i.createElementVNode)(`span`,Pr,(0,i.toDisplayString)(t.titre),1),t.options.length?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,Fr,(0,i.toDisplayString)(t.options.length),1)):(0,i.createCommentVNode)(``,!0)]),(0,i.createElementVNode)(`div`,Ir,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(t.options,a=>((0,i.openBlock)(),(0,i.createElementBlock)(`button`,{key:a.id,type:`button`,class:(0,i.normalizeClass)([`list-group-item list-group-item-action d-flex align-items-center gap-2 fs-7 px-2 py-1`,{active:a.id===t.selectedId}]),"aria-pressed":a.id===t.selectedId,onClick:n=>e.$emit(`choisir`,{key:t.key,id:a.id})},[a.icon?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,icon:a.icon,"fixed-width":``},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`span`,Rr,(0,i.toDisplayString)(a.libelle),1),r<n.niveaux.length-1?((0,i.openBlock)(),(0,i.createBlock)(s,{key:1,icon:`chevron-right`,class:`opacity-50`})):a.id===t.selectedId?((0,i.openBlock)(),(0,i.createBlock)(s,{key:2,icon:`check`})):(0,i.createCommentVNode)(``,!0)],10,Lr))),128))]),t.options.length?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`small`,zr,(0,i.toDisplayString)(r>0?`← Choisir ${o.article(n.niveaux[r-1])}`:`Aucun choix disponible`),1))],2))),128))])}var Vr=N(jr,[[`render`,Br]]),Hr={name:`EtapeMotifBlock`,components:{AmsomOverlay:r.AmsomOverlay,AmsomAutocomplete:s.AmsomAutocomplete,SectionComponent:P,SeparateurComponent:or,RecapBlock:pr,MotifChaineComponent:yr,MotifBubbleBlock:kr,MotifColonnesBlock:Vr,LigneCibleBlock:Yn},setup(){return{draft:M(),data:G(),options:K()}},data(){return{iconsReady:!1}},computed:{mainLigne(){return this.draft.lignePrincipale},lignesAssociees(){return this.draft.lignesAssociees},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(){return this.activeMotifs.filter(e=>this.options.estMotifPropose(e))},motifBloque(){return this.options.motifNonProposeMode===`block`&&!this.options.motifPrincipalPropose},niveaux(){let e={categorie:this.data.categorieIcon,type:this.data.typeIcon,nature:this.data.natureIcon},t=this.allowedMotifs;return Y.map((n,r)=>{let i=Y[r-1],a=!i||this.mainLigne[i.idKey]!=null?t:[],o=n.key===`motif`?a.map(e=>({id:e.id,libelle:e.libelle,icon:e.icon})):this.distinct(a,n.idKey,n.libelleKey,e[n.key]),s=this.mainLigne[n.idKey];return s!=null&&(t=t.filter(e=>e[n.idKey]===s)),{key:n.key,titre:n.titre,options:o,selectedId:s}})},chaine(){let e=this.mainLigne,t={categorie:this.data.categorieLibelle,type:this.data.typeLibelle,nature:this.data.natureLibelle,motif:this.data.motifLibelle},n={categorie:this.data.categorieIcon,type:this.data.typeIcon,nature:this.data.natureIcon,motif:this.data.motifIcon};return X(Y.map(r=>{let i=e[r.idKey];return{key:r.key,selectedId:i,options:i==null?[]:[{id:i,libelle:t[r.key](i),icon:n[r.key](i)}]}}))},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})):[]},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:{setNiveau(e,t){({categorie:this.draft.setCategorie,type:this.draft.setType,nature:this.draft.setNature,motif:this.draft.setMotif})[e](t)},choisir({key:e,id:t}){if(this.setNiveau(e,t),this.options.motifSelectionMode!==`columns`)return;let n=Y.findIndex(t=>t.key===e)+1;for(;n<Y.length;){let e=this.niveaux[n];if(e.selectedId!=null||e.options.length!==1)break;this.setNiveau(e.key,e.options[0].id),n+=1}},retirer(e){this.setNiveau(e,null)},isActive(e){return this.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 F([...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=(I(e)??``).trim();if(!n)return t;let r=n.split(/\s+/);return t.filter(e=>{let t=I(`${e.libelle} ${e.categorie} ${e.type} ${e.nature}`)??``;return r.every(e=>t.includes(e))})},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}}},Ur={key:0,class:`d-flex flex-column gap-4`},Wr={key:0,class:`alert alert-info d-flex align-items-start gap-2 py-2 px-3 mb-0 fs-7`},Gr={key:1,class:`alert alert-warning d-flex align-items-start gap-2 py-2 px-3 mb-0 fs-7`},Kr={class:`d-flex align-items-center gap-2`},qr={class:`min-w-0`},Jr={class:`fw-medium text-truncate`},Yr={class:`text-muted d-block text-truncate`},Xr=[`id`,`checked`,`disabled`,`onChange`],Zr=[`for`],Qr={key:0,class:`alert alert-warning d-flex align-items-start gap-2 py-2 px-3 mb-0 fs-7`};function $r(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`recap-block`),c=(0,i.resolveComponent)(`font-awesome-icon`),l=(0,i.resolveComponent)(`motif-chaine-component`),u=(0,i.resolveComponent)(`amsom-autocomplete`),d=(0,i.resolveComponent)(`separateur-component`),f=(0,i.resolveComponent)(`motif-colonnes-block`),p=(0,i.resolveComponent)(`motif-bubble-block`),m=(0,i.resolveComponent)(`section-component`),h=(0,i.resolveComponent)(`ligne-cible-block`),g=(0,i.resolveComponent)(`amsom-overlay`);return(0,i.openBlock)(),(0,i.createBlock)(g,{loading:r.data.isLoading&&!r.data.cache.motifs||!a.iconsReady},{default:(0,i.withCtx)(()=>[a.iconsReady?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Ur,[(0,i.createVNode)(s,{champs:[`reclamant`,`cible`]}),(0,i.createVNode)(m,{titre:`Motif`},{default:(0,i.withCtx)(()=>[r.options.motifRetire?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Wr,[(0,i.createVNode)(c,{icon:`circle-info`,class:`mt-1`}),(0,i.createElementVNode)(`span`,null,[(0,i.createTextVNode)(` Le motif « `+(0,i.toDisplayString)(r.options.motifRetire.libelle)+` » a été retiré `,1),r.options.motifRetire.associes.length?((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:0},[(0,i.createTextVNode)(` avec ses motifs associés (`+(0,i.toDisplayString)(r.options.motifRetire.associes.join(`, `))+`) `,1)],64)):(0,i.createCommentVNode)(``,!0),t[1]||=(0,i.createTextVNode)(` : il n’est pas proposé pour ce réclamant. `,-1)])])):(0,i.createCommentVNode)(``,!0),o.motifBloque?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Gr,[(0,i.createVNode)(c,{icon:`circle-exclamation`,class:`mt-1`}),(0,i.createElementVNode)(`span`,null,` Le motif « `+(0,i.toDisplayString)(r.data.motifLibelle(o.mainLigne.idMotif))+` » n’est pas proposé pour ce réclamant : choisissez-en un autre pour continuer. `,1)])):(0,i.createCommentVNode)(``,!0),o.motifFige?((0,i.openBlock)(),(0,i.createBlock)(l,{key:2,chaine:o.chaine,readonly:``},null,8,[`chaine`])):((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:3},[(0,i.createElementVNode)(`div`,null,[t[2]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},[(0,i.createTextVNode)(` Rechercher un motif`),(0,i.createElementVNode)(`span`,{class:`ms-1 text-danger`},`*`)],-1),(0,i.createVNode)(u,{modelValue:o.motifRecherche,"onUpdate:modelValue":t[0]||=e=>o.motifRecherche=e,items:o.allowedMotifs,"get-id":e=>e?.id??null,"get-input-libelle":e=>e?.libelle??``,"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,i.withCtx)(e=>[(0,i.createElementVNode)(`div`,Kr,[e?.icon?((0,i.openBlock)(),(0,i.createBlock)(c,{key:0,icon:e.icon,class:`text-primary`,"fixed-width":``},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`div`,qr,[(0,i.createElementVNode)(`div`,Jr,(0,i.toDisplayString)(e?.libelle),1),(0,i.createElementVNode)(`small`,Yr,(0,i.toDisplayString)(e?.categorie)+` › `+(0,i.toDisplayString)(e?.type)+` › `+(0,i.toDisplayString)(e?.nature),1)])])]),_:1},8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`get-input-libelle-from-id`,`filtering-function`])]),(0,i.createVNode)(d,{texte:`ou sélection guidée`}),r.options.motifSelectionMode===`columns`?((0,i.openBlock)(),(0,i.createBlock)(f,{key:0,niveaux:o.niveaux,onChoisir:o.choisir},null,8,[`niveaux`,`onChoisir`])):((0,i.openBlock)(),(0,i.createBlock)(p,{key:1,niveaux:o.niveaux,onChoisir:o.choisir,onRetirer:o.retirer},null,8,[`niveaux`,`onChoisir`,`onRetirer`]))],64))]),_:1}),o.motifsAssocies.length?((0,i.openBlock)(),(0,i.createBlock)(m,{key:0,titre:`Motifs complémentaires`},{default:(0,i.withCtx)(()=>[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.motifsAssocies,e=>((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:e.idMotif,class:`form-check form-switch`},[(0,i.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,Xr),(0,i.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`assoc-${e.idMotif}`},(0,i.toDisplayString)(e.libelle)+` ? `,9,Zr)]))),128)),r.draft.ciblesAssocieesReinitialisees&&r.draft.draft.reclamant.type!==`D`?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Qr,[(0,i.createVNode)(c,{icon:`circle-exclamation`,class:`mt-1`}),(0,i.createElementVNode)(`span`,null,` Le réclamant a changé : `+(0,i.toDisplayString)(r.draft.ciblesAssocieesReinitialisees>1?`${r.draft.ciblesAssocieesReinitialisees} motifs associés reprennent`:`un motif associé reprend`)+` la cible de la ligne principale. Vérifiez-la ci-dessous si elle doit être différente. `,1)])):(0,i.createCommentVNode)(``,!0),o.lignesAssociees.length&&r.draft.draft.reclamant.type!==`D`?((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:1},[(0,i.createVNode)(d,{texte:`Cible des autres motifs`}),((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.lignesAssociees,(e,t)=>((0,i.openBlock)(),(0,i.createBlock)(h,{key:e.idMotif,index:t+1},null,8,[`index`]))),128))],64)):(0,i.createCommentVNode)(``,!0)]),_:1})):(0,i.createCommentVNode)(``,!0)])):(0,i.createCommentVNode)(``,!0)]),_:1},8,[`loading`])}var ei=N(Hr,[[`render`,$r]]),ti={name:`LigneDocumentBlock`,components:{AmsomUploadFile:d.AmsomUploadFile},props:{index:{type:Number,required:!0},fichier:{type:[Object,Array],default:null},readonly:{type:Boolean,default:!1}},emits:[`update`]};function ni(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`amsom-upload-file`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,null,[t[1]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Document`,-1),(0,i.createVNode)(s,{"model-value":n.fichier,renameable:``,"output-format":`object`,name:`cresol-creation-ged-${n.index}`,"merge-pdfs":``,"read-only":n.readonly,"onUpdate:modelValue":t[0]||=t=>e.$emit(`update`,t)},null,8,[`model-value`,`name`,`read-only`])])}var ri=N(ti,[[`render`,ni]]),ii=4e3,ai={name:`LigneDetailBlock`,components:{AmsomAutocomplete:s.AmsomAutocomplete,AmsomTextarea:u.AmsomTextarea,LigneDocumentBlock:ri},props:{index:{type:Number,required:!0}},setup(){return{draft:M(),data:G()}},computed:{descriptionMaxLength:()=>ii,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}},mounted(){this.isPrincipale&&this.$refs.description?.$el.querySelector(`textarea`)?.focus()},methods:{timestampToDateInput:_t,dateInputToTimestamp:vt,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=(I(e)??``).trim();return n?t.filter(e=>(I(`${e.prenom} ${e.nom} ${e.service}`)??``).includes(n)):t}}},oi={class:`d-flex flex-column gap-2`},si={class:`d-flex align-items-center gap-2 mb-1`},ci={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-0`},li={key:0,class:`ms-1 text-danger`},ui={key:0,class:`form-check form-switch mb-0`},di=[`id`,`checked`,`disabled`],fi=[`for`],pi=[`rows`,`value`],mi={class:`row g-3`},hi={class:`col-6`},gi={class:`d-flex align-items-center gap-2 mb-1`},_i={key:0,class:`form-check form-switch mb-0`},vi=[`id`,`checked`,`disabled`],yi=[`for`],bi=[`value`],xi=[`value`],Si=[`value`],Ci={class:`min-w-0`},wi={class:`fw-medium text-truncate`},Ti={key:0,class:`text-muted d-block`},Ei={key:2,class:`text-muted`},Di={class:`col-12 col-md-6`};function Oi(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`amsom-textarea`),c=(0,i.resolveComponent)(`amsom-autocomplete`),l=(0,i.resolveComponent)(`ligne-document-block`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,oi,[(0,i.createElementVNode)(`div`,null,[(0,i.createElementVNode)(`div`,si,[(0,i.createElementVNode)(`label`,ci,[t[6]||=(0,i.createTextVNode)(` Description`,-1),o.isPrincipale?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,li,`*`)):(0,i.createCommentVNode)(``,!0)]),o.isPrincipale?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,ui,[(0,i.createElementVNode)(`input`,{id:`memedetail-${o.ligne.idMotif}`,class:`form-check-input`,type:`checkbox`,checked:o.ligne.description==null,disabled:r.draft.isReadonly(`description`),onChange:t[0]||=e=>r.draft.toggleDescriptionOverride(n.index)},null,40,di),(0,i.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`memedetail-${o.ligne.idMotif}`},` Même description `,8,fi)]))]),!r.draft.isReadonly(`description`)&&(o.isPrincipale||o.ligne.description!=null)?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,ref:`description`,"model-value":o.ligne.description,"input-size":`sm`,rows:o.isPrincipale?7:5,maxlength:o.descriptionMaxLength,placeholder:o.isPrincipale?`Décrivez la sollicitation…`:`Décrivez ce motif…`,"onUpdate:modelValue":t[1]||=e=>r.draft.setDescription(n.index,e)},null,8,[`model-value`,`rows`,`maxlength`,`placeholder`])):((0,i.openBlock)(),(0,i.createElementBlock)(`textarea`,{key:1,class:`form-control form-control-sm`,disabled:``,rows:o.isPrincipale?7:5,value:(o.ligne.description??o.lignePrincipale.description)||``},null,8,pi))]),(0,i.createElementVNode)(`div`,mi,[(0,i.createElementVNode)(`div`,hi,[(0,i.createElementVNode)(`div`,null,[(0,i.createElementVNode)(`div`,gi,[t[7]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-0`},` Date des faits `,-1),o.isPrincipale?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,_i,[(0,i.createElementVNode)(`input`,{id:`memedate-${o.ligne.idMotif}`,class:`form-check-input`,type:`checkbox`,checked:!o.ligne.dateFaitsOverride,disabled:r.draft.isReadonly(`dateFaits`),onChange:t[2]||=e=>r.draft.toggleDateFaitsOverride(n.index)},null,40,vi),(0,i.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`memedate-${o.ligne.idMotif}`},` Même date `,8,yi)]))]),!r.draft.isReadonly(`dateFaits`)&&(o.isPrincipale||o.ligne.dateFaitsOverride)?((0,i.openBlock)(),(0,i.createElementBlock)(`input`,{key:0,value:o.timestampToDateInput(o.ligne.dateFaits),type:`date`,class:`form-control form-control-sm`,onInput:t[3]||=e=>r.draft.setDateFaits(n.index,o.dateInputToTimestamp(e.target.value))},null,40,bi)):((0,i.openBlock)(),(0,i.createElementBlock)(`input`,{key:1,value:o.timestampToDateInput(o.dateFaits),type:`date`,class:`form-control form-control-sm`,disabled:``},null,8,xi))]),(0,i.createElementVNode)(`div`,null,[t[8]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Responsable `,-1),r.draft.isReadonly(`responsable`)?((0,i.openBlock)(),(0,i.createElementBlock)(`input`,{key:0,class:`form-control form-control-sm`,disabled:``,value:o.responsableLibelle(o.ligne.responsable)||`Déterminé automatiquement`},null,8,Si)):((0,i.openBlock)(),(0,i.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=>r.draft.setResponsable(n.index,e??null)},{options:(0,i.withCtx)(e=>[(0,i.createElementVNode)(`div`,Ci,[(0,i.createElementVNode)(`div`,wi,(0,i.toDisplayString)(e?.prenom)+` `+(0,i.toDisplayString)(e?.nom),1),e?.service?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,Ti,(0,i.toDisplayString)(e.service),1)):(0,i.createCommentVNode)(``,!0)])]),_:1},8,[`model-value`,`items`,`get-id`,`get-input-libelle`,`filtering-function`])),o.isPrincipale&&!o.ligne.responsable&&!r.draft.isReadonly(`responsable`)?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,Ei,` Aucun paramétrage trouvé : le responsable sera déterminé automatiquement. `)):(0,i.createCommentVNode)(``,!0)])]),(0,i.createElementVNode)(`div`,Di,[(0,i.createVNode)(l,{index:n.index,fichier:o.ligne.fichier,readonly:r.draft.isReadonly(`fichier`),onUpdate:t[5]||=e=>r.draft.setFichier(n.index,e)},null,8,[`index`,`fichier`,`readonly`])])])])}var ki=N(ai,[[`render`,Oi]]),Ai={name:`EtapeDetailsBlock`,components:{AmsomOverlay:r.AmsomOverlay,LigneDetailBlock:ki,RecapBlock:pr,SectionComponent:P},setup(){return{draft:M(),data:G()}},computed:{lignePrincipale(){return this.draft.lignePrincipale},lignesAssociees(){return this.draft.lignesAssociees},collaborateurs(){return(this.data.cache.collaborateurs??[]).filter(e=>e.actif!==!1)}},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)}}}},ji={class:`d-flex flex-column gap-4`},Mi={class:`text-muted d-flex align-items-start gap-2`};function Ni(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`recap-block`),c=(0,i.resolveComponent)(`font-awesome-icon`),l=(0,i.resolveComponent)(`ligne-detail-block`),u=(0,i.resolveComponent)(`section-component`),d=(0,i.resolveComponent)(`amsom-overlay`);return(0,i.openBlock)(),(0,i.createBlock)(d,{loading:r.data.isLoading&&!r.data.cache.collaborateurs},{default:(0,i.withCtx)(()=>[(0,i.createElementVNode)(`div`,ji,[(0,i.createVNode)(s),(0,i.createElementVNode)(`small`,Mi,[(0,i.createVNode)(c,{icon:`circle-info`,class:`mt-1`}),t[0]||=(0,i.createTextVNode)(` Rappel RGPD : ne saisissez que les informations nécessaires au traitement de la sollicitation, aucune donnée sensible (santé, opinions, situation judiciaire…) ni appréciation personnelle sur le réclamant. `,-1)]),(0,i.createVNode)(u,{titre:o.lignesAssociees.length?`Motif principal`:`Détails`},{default:(0,i.withCtx)(()=>[(0,i.createVNode)(l,{index:0})]),_:1},8,[`titre`]),o.lignesAssociees.length?((0,i.openBlock)(),(0,i.createBlock)(u,{key:0,titre:`Détail des autres motifs`},{default:(0,i.withCtx)(()=>[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.lignesAssociees,(e,t)=>((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:e.idMotif,class:`border rounded p-2 d-flex flex-column gap-2`},[(0,i.createVNode)(s,{index:t+1,champs:[`motif`,`cible`]},null,8,[`index`]),(0,i.createVNode)(l,{index:t+1},null,8,[`index`])]))),128))]),_:1})):(0,i.createCommentVNode)(``,!0)])]),_:1},8,[`loading`])}var Pi=N(Ai,[[`render`,Ni]]),Fi=[{key:`reclamantCible`,label:`Réclamant et cible`,icon:`user`},{key:`motif`,label:`Motif`,icon:`tag`},{key:`details`,label:`Détails`,icon:`info`}],Ii={name:`StepperBlock`,components:{AmsomHorizontalStepper:o.default,AmsomOverlay:r.AmsomOverlay,EtapeReclamantCibleBlock:nr,EtapeMotifBlock:ei,EtapeDetailsBlock:Pi},props:{step:{type:Number,default:1},creating:{type:Boolean,default:!1}},emits:[`update:step`,`stepChange`,`submit`],setup(){return{draft:M(),data:G(),options:K()}},computed:{steps:()=>Fi,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},provenanceValid(){return this.options.provenances.some(e=>e.id===this.draft.draft.provenance)},motifPropose(){return this.options.motifNonProposeMode!==`block`||this.options.motifPrincipalPropose},canGoNext(){return this.gatePassed(this.currentKey)},canCreer(){return!!this.lignePrincipale.idMotif&&this.motifPropose&&this.provenanceValid&&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===`reclamantCible`?this.draft.reclamantSelectionne!=null&&this.provenanceValid&&this.draft.ligneCibleValid(0):e!==`motif`||!!this.lignePrincipale.idMotif&&this.motifPropose&&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===`motif`&&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}))}}},Li={class:`d-flex flex-column gap-3`},Ri={key:0,class:`w-100 fs-6 fw-medium my-3 alert alert-info`,style:{"white-space":`pre-line`}},zi={style:{"min-height":`260px`}},Bi={class:`d-flex justify-content-between`},Vi={key:1},Hi=[`disabled`],Ui=[`disabled`];function Wi(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`amsom-horizontal-stepper`),c=(0,i.resolveComponent)(`font-awesome-icon`),l=(0,i.resolveComponent)(`etape-reclamant-cible-block`),u=(0,i.resolveComponent)(`etape-motif-block`),d=(0,i.resolveComponent)(`etape-details-block`),f=(0,i.resolveComponent)(`amsom-overlay`);return(0,i.openBlock)(),(0,i.createBlock)(f,{loading:n.creating},{default:(0,i.withCtx)(()=>[(0,i.createElementVNode)(`div`,Li,[(0,i.createVNode)(s,{steps:o.stepperSteps,size:`md`,onStepClick:o.onStepClick},null,8,[`steps`,`onStepClick`]),o.aideMotif?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Ri,[(0,i.createVNode)(c,{icon:`circle-info`,class:`text-info-emphasis me-2`}),(0,i.createElementVNode)(`span`,null,(0,i.toDisplayString)(o.aideMotif),1)])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`div`,zi,[o.currentKey===`reclamantCible`?((0,i.openBlock)(),(0,i.createBlock)(l,{key:0},(0,i.createSlots)({_:2},[e.$slots.reclamant?{name:`reclamant`,fn:(0,i.withCtx)(t=>[(0,i.renderSlot)(e.$slots,`reclamant`,(0,i.normalizeProps)((0,i.guardReactiveProps)(t)))]),key:`0`}:void 0]),1024)):o.currentKey===`motif`?((0,i.openBlock)(),(0,i.createBlock)(u,{key:1})):o.currentKey===`details`?((0,i.openBlock)(),(0,i.createBlock)(d,{key:2})):(0,i.createCommentVNode)(``,!0)]),(0,i.createElementVNode)(`div`,Bi,[n.step>1?((0,i.openBlock)(),(0,i.createElementBlock)(`button`,{key:0,class:`btn btn-sm btn-outline-secondary`,onClick:t[0]||=(...e)=>o.goPrevious&&o.goPrevious(...e)},[(0,i.createVNode)(c,{icon:`chevron-left`,class:`me-1`}),t[3]||=(0,i.createTextVNode)(` Précédent `,-1)])):((0,i.openBlock)(),(0,i.createElementBlock)(`span`,Vi)),n.step<o.steps.length?((0,i.openBlock)(),(0,i.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,i.createTextVNode)(` Suivant `,-1),(0,i.createVNode)(c,{icon:`chevron-right`,class:`ms-1`})],8,Hi)):((0,i.openBlock)(),(0,i.createElementBlock)(`button`,{key:3,class:`btn btn-sm btn-success`,disabled:!o.canCreer||n.creating,onClick:t[2]||=t=>e.$emit(`submit`)},[(0,i.createVNode)(c,{icon:`check`,class:`me-1`}),t[5]||=(0,i.createTextVNode)(` Créer la sollicitation `,-1)],8,Ui))])])]),_:3},8,[`loading`])}var Gi=N(Ii,[[`render`,Wi]]),Ki=(e,{signal:t,baseUrl:n}={})=>ze(`/v2/cresol/creer_sollicitation`,e,{signal:t,baseUrl:n}),qi=({idSollicitation:e,pj:t},{signal:n,baseUrl:r}={})=>ze(`/v2/cresol/upload_sollicitation_ged`,{idSollicitation:e,pj:t},{signal:n,baseUrl:r}),Z={modelValue:{type:Object,default:null},reclamants:{type:Array,default:()=>[]},reclamantMode:{type:String,default:`select`,validator:e=>[`select`,`switch`,`autocomplete`,`recherche`].includes(e)},motifSelectionMode:{type:String,default:`bubble`,validator:e=>[`bubble`,`columns`].includes(e)},motifNonProposeMode:{type:String,default:`clear`,validator:e=>[`clear`,`block`,`ignore`].includes(e)},typesReclamant:{type:Array,default:null,validator:e=>e.every(e=>w.includes(e))},typesReclamantExclus:{type:Array,default:()=>[],validator:e=>e.every(e=>w.includes(e))},provenances:{type:Array,default:()=>[...x]},provenancesExclues:{type:Array,default:()=>[]},readonly:{type:[Boolean,Array],default:!1,validator:e=>typeof e==`boolean`||e.every(e=>A.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}},Ji=Object.keys(Z),Q=[`update:modelValue`,`reclamantChange`,`motifChange`,`stepChange`,`beforeCreate`,`created`,`createError`,`error`],Yi={name:`CreerSollicitationForm`,components:{AsideBlock:ye,StepperBlock:Gi},props:{...Z},emits:[...Q],setup(e,{emit:t}){let n=e=>t(`error`,e),r={baseUrl:(0,i.toRef)(e,`baseUrl`)},a=st(ot({onError:n,...r})),o=(0,i.ref)(null),s=(0,i.ref)(!1),c=(0,i.computed)(()=>o.value??e.modules??[]),l=(0,i.computed)(()=>e.reclamantMode===`recherche`),u=fe(de({reclamants:(0,i.computed)(()=>l.value?[]:e.reclamants),modules:c,idModulePrefere:(0,i.toRef)(e,`idModule`),readonly:(0,i.toRef)(e,`readonly`)})),d=t=>{if(!t||t.estDesactive)return!1;let n=e.nomenclatureFilter;return typeof n!=`function`||n(t,{reclamant:u.reclamantSelectionne})},f=(0,i.computed)(()=>{let e=u.lignePrincipale.idMotif;if(e==null||u.isReadonly(`motif`))return!0;let t=a.cache.motifs?.find(t=>t.id===e);return!a.cache.motifs||d(t)}),p=(0,i.ref)(null);return lt((0,i.reactive)({nomenclatureFilter:(0,i.toRef)(e,`nomenclatureFilter`),estMotifPropose:d,motifPrincipalPropose:f,motifNonProposeMode:(0,i.toRef)(e,`motifNonProposeMode`),motifRetire:p,reclamantMode:(0,i.toRef)(e,`reclamantMode`),rechercheReclamant:l,motifSelectionMode:(0,i.toRef)(e,`motifSelectionMode`),typesReclamant:(0,i.computed)(()=>(e.typesReclamant??w).filter(t=>!e.typesReclamantExclus.includes(t))),provenances:(0,i.computed)(()=>{let t=a.cache.provenances??[];return(e.provenances??t.map(e=>e.id)).filter(t=>!e.provenancesExclues.includes(t)).flatMap(e=>{let n=t.find(t=>t.id===e);return n?[{...n,icon:ee(e)}]:[]})}),modulesReclamant:c,repriseReclamant:s,...r})),{data:a,draft:u,modulesCharges:o,repriseReclamant:s,rechercheReclamant:l,motifPrincipalPropose:f,motifRetire:p,onError:n}},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.data.loadNomenclature(),this.data.loadProvenances(),this.draft.reset(this.modelValue),this.rechercheReclamant&&await this.reprendreReclamantFourni(),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(`motifPrincipalPropose`,this.retirerMotifNonPropose,{immediate:!0}),this.$watch(()=>this.draft.lignePrincipale.idMotif,e=>{e!=null&&(this.motifRetire=null)}),this.$watch(()=>JSON.stringify(this.motifChoisi),()=>this.$emit(`motifChange`,this.motifChoisi)),await this.chargerModulesReclamant(e,e)&&this.draft.prefillCiblePrincipale(),this.draft.libererCibleFournie()},methods:{retirerMotifNonPropose(e){if(e||this.motifNonProposeMode!==`clear`)return;let t=this.draft.lignePrincipale.idMotif,n={libelle:this.data.motifLibelle(t),associes:this.draft.lignesAssociees.map(e=>e.libelle??this.data.motifLibelle(e.idMotif))};this.draft.setCategorie(null),this.motifRetire=n},async reprendreReclamantFourni(){let{type:e,id:t}=this.draft.draft.reclamant;if(!e||t==null)return;let n=n=>n.type===e&&String(n.id)===String(t),[r]=T([e]),i=null;if(r){this.repriseReclamant=!0;try{i=(await this.data.searchReclamants(r,String(t))??[]).find(n)??null}catch{}finally{this.repriseReclamant=!1}}n(this.draft.draft.reclamant)&&this.draft.selectReclamant(i??{type:e,id:t,libelle:`${e}/${t}`})},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 Ki(e,this.requestOptions)??[]}catch(t){if(tt(t))return;let n=B(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?qi({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(B(e))):Promise.resolve(s(`sollicitation introuvable dans la réponse`))});return Promise.all(n)}}},Xi={class:`row g-3`},Zi={key:0,class:`col-12 col-lg-4`};function Qi(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`aside-block`),c=(0,i.resolveComponent)(`stepper-block`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,Xi,[e.aside?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Zi,[(0,i.renderSlot)(e.$slots,`aside`,{},()=>[(0,i.createVNode)(s,{"nb-similaires":e.nbSimilaires},(0,i.createSlots)({_:2},[e.$slots[`aside-similaires`]?{name:`similaires`,fn:(0,i.withCtx)(t=>[(0,i.renderSlot)(e.$slots,`aside-similaires`,(0,i.normalizeProps)((0,i.guardReactiveProps)(t)))]),key:`0`}:void 0,e.$slots[`aside-evenements`]?{name:`evenements`,fn:(0,i.withCtx)(()=>[(0,i.renderSlot)(e.$slots,`aside-evenements`)]),key:`1`}:void 0]),1032,[`nb-similaires`])])])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`col-12`,e.aside?`col-lg-8`:``])},[(0,i.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,i.createSlots)({_:2},[e.$slots.reclamant?{name:`reclamant`,fn:(0,i.withCtx)(t=>[(0,i.renderSlot)(e.$slots,`reclamant`,(0,i.normalizeProps)((0,i.guardReactiveProps)(t)))]),key:`0`}:void 0]),1032,[`step`,`creating`,`onSubmit`])],2)])}var $=N(Yi,[[`render`,Qi]]),$i={name:`CreerSollicitationModal`,components:{AmsomModal:r.AmsomModal,CreerSollicitationForm:$},props:{...Z,titre:{type:String,default:`Nouvelle sollicitation`},closeOnCreated:{type:Boolean,default:!0}},emits:[...Q,`close`],computed:{formProps(){return Object.fromEntries(Ji.map(e=>[e,this[e]]))},formListeners(){return Object.fromEntries(Q.filter(e=>e!==`created`).map(e=>[e,(...t)=>this.$emit(e,...t)]))}},methods:{onCreated(...e){this.$emit(`created`,...e),this.closeOnCreated&&this.$emit(`close`)}}},ea={class:`fw-medium fs-5`};function ta(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`creer-sollicitation-form`),c=(0,i.resolveComponent)(`amsom-modal`);return(0,i.openBlock)(),(0,i.createBlock)(c,{"close-option":``,size:`xl`,onClose:t[0]||=t=>e.$emit(`close`)},{default:(0,i.withCtx)(()=>[(0,i.createElementVNode)(`span`,ea,(0,i.toDisplayString)(n.titre),1),(0,i.createVNode)(s,(0,i.mergeProps)({class:`pt-3`},o.formProps,(0,i.toHandlers)(o.formListeners),{onCreated:o.onCreated}),(0,i.createSlots)({_:2},[(0,i.renderList)(e.$slots,(t,n)=>({name:n,fn:(0,i.withCtx)(t=>[(0,i.renderSlot)(e.$slots,n,(0,i.normalizeProps)((0,i.guardReactiveProps)(t??{})))])}))]),1040,[`onCreated`])]),_:3})}var na=N($i,[[`render`,ta]]),ra={CreerSollicitationModal:na,CreerSollicitationForm:$};e.CreerSollicitationForm=$,e.CreerSollicitationModal=na,e.DEFAULT_PROVENANCE_CONTACT=te,e.PROVENANCES_CONTACT_DEFAUT=x,e.PROVENANCE_CONTACT_ICONS=b,e.READONLY_FIELDS=A,e.configureCresol=Pe,e.default=ra,e.getDefaultDraft=j,e.getDefaultLigne=k,e.getDefaultPatrimoine=O,e.resetCresolCache=at});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@fortawesome/fontawesome-svg-core"),require("@fortawesome/free-solid-svg-icons"),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("@amsom-habitat/amsom-textarea"),require("@amsom-habitat/file-manager")):typeof define==`function`&&define.amd?define([`exports`,`@fortawesome/fontawesome-svg-core`,`@fortawesome/free-solid-svg-icons`,`@amsom-habitat/ui`,`vue`,`@amsom-habitat/nav-tabs`,`@amsom-habitat/horizontal-stepper`,`@amsom-habitat/amsom-autocomplete`,`@amsom-habitat/axios-overlay`,`@amsom-habitat/user-manager`,`@amsom-habitat/amsom-textarea`,`@amsom-habitat/file-manager`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Cresol={},e._fortawesome_fontawesome_svg_core,e._fortawesome_free_solid_svg_icons,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._amsom_habitat_amsom_textarea,e._amsom_habitat_file_manager))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var f=Object.create,p=Object.defineProperty,m=Object.getOwnPropertyDescriptor,h=Object.getOwnPropertyNames,g=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty,v=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=h(t),a=0,o=i.length,s;a<o;a++)s=i[a],!_.call(e,s)&&s!==n&&p(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=m(t,s))||r.enumerable});return e},y=(e,t,n)=>(n=e==null?{}:f(g(e)),v(t||!e||!e.__esModule||!_.call(e,`default`)?p(n,`default`,{value:e,enumerable:!0}):n,e));o=y(o),c=y(c,1),l=y(l,1),t.library.add(n.faBriefcase,n.faBuilding,n.faBuildingShield,n.faCheck,n.faChevronLeft,n.faChevronRight,n.faCircleExclamation,n.faCircleInfo,n.faCircleQuestion,n.faDungeon,n.faFileSignature,n.faHandsHolding,n.faHourglass,n.faHouse,n.faInfo,n.faLayerGroup,n.faLocationDot,n.faMagnifyingGlass,n.faPersonShelter,n.faSquareParking,n.faStore,n.faTag,n.faUser,n.faUserGraduate,n.faXmark);var b={T:`phone`,M:`envelope`,G:`user-shield`,V:`building`,IP:`exclamation-triangle`,C:`envelope-open`},ee=e=>b[e]??`comment-dots`,te=Object.keys(b),ne=`T`,x={locataire:{libelle:`Locataire`,icon:`house-user`,couleur:`primary`},demandeur:{libelle:`Demandeur`,icon:`hourglass-half`,couleur:`info`},tiers:{libelle:`Tiers`,icon:`user-tie`,couleur:`warning`},autre:{libelle:`Autre`,icon:`user`,couleur:`secondary`},fournisseur:{libelle:`Fournisseur`,icon:`truck`,couleur:`success`},personnel:{libelle:`Personnel`,icon:`id-badge`,couleur:`dark`},inconnu:{libelle:`Inconnu`,icon:`circle-question`,couleur:`danger`}},S=[`L`,`P`],C={...Object.fromEntries(S.map(e=>[e,`locataire`])),D:`demandeur`,T:`tiers`,U:`autre`,F:`fournisseur`,E:`personnel`},w=Object.keys(C),T=e=>[...new Set(e.map(e=>C[e]))],E=e=>e?x[e.categorie]?e.categorie:C[e.type]??`inconnu`:null,re=e=>x[E(e)]??null,ie=Symbol(`cresol:draft`),D=()=>({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}),O=()=>({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}),k=[`cibleOverride`,`cibleMode`,`contratReclamant`,`contratCible`,`reprendreLocataireActuel`,`modulePrecis`,`patrimoine`],ae=e=>Object.fromEntries(k.map(t=>{let n=e?.[t]??O()[t];return[t,n&&typeof n==`object`?{...n}:n]})),A=[`reclamant`,`provenance`,`motif`,`cible`,`description`,`dateFaits`,`responsable`,`fichier`],j=(e=`T`)=>({reclamant:{type:null,id:null},provenance:e,lignes:[{...O(),cibleMode:`contrat`,patrimoine:D(),description:``}]}),oe=e=>e?.id??e??null,se=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`},ce=e=>!!e&&(e.idModule!=null||e.idEntree!=null),le=(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:ce(e.patrimoine),ue=(e,t)=>e.description==null?!t:e.description.trim().length>0,de=(e={})=>{let t={...O(),...e};return e.patrimoine&&(t.patrimoine={...D(),...e.patrimoine}),t},fe=e=>{let t=j();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],...de(e)}:de(e)):t.lignes}};function pe({reclamants:e,modules:t,idModulePrefere:n=(0,i.ref)(null),readonly:r=(0,i.ref)(!1)}={}){let a=(0,i.reactive)(j()),o=(0,i.computed)(()=>{let e=(0,i.unref)(r);return e===!0?A:Array.isArray(e)?e:[]}),s=e=>o.value.includes(e),c=(0,i.computed)(()=>a.lignes[0]),l=(0,i.computed)(()=>a.lignes.slice(1)),u=(0,i.computed)(()=>(0,i.unref)(e)??[]),d=(0,i.ref)(null),f=(e,t)=>e.type===t.type&&String(e.id)===String(t.id),p=(0,i.computed)(()=>{let e=d.value;return!e||u.value.some(t=>f(t,e))?u.value:[...u.value,e]}),m=(0,i.computed)(()=>p.value.find(e=>f(e,a.reclamant))??p.value[0]??null),h=(0,i.ref)(!1),g=(0,i.ref)(0),_=(0,i.computed)(()=>{let e=(0,i.unref)(t)??[],r=(0,i.unref)(n);return(r==null?null:e.find(e=>String(e.idModule)===String(r)))??e.find(e=>e.estModulePrincipal)??e[0]??null}),v=(0,i.computed)(()=>!!m.value&&S.includes(m.value.type)),y={draft:a,lignePrincipale:c,lignesAssociees:l,reclamantsFournis:u,reclamantsDisponibles:p,reclamantSelectionne:m,moduleReclamantPrincipal:_,reclamantEstContrat:v,ciblesValid:(0,i.computed)(()=>a.lignes.every(e=>le(e,v.value))),detailsValid:(0,i.computed)(()=>a.lignes.every((e,t)=>ue(e,t===0))),isReadonly:s,ciblesAssocieesReinitialisees:g,ligneCibleValid(e){let t=a.lignes[e];return!!t&&le(t,v.value)},reset(e=null){let t=e?.lignes?.[0];h.value=!!t&&[`cibleMode`,`patrimoine`,`contratCible`].some(e=>t[e]!=null),g.value=0;let n=fe(e);Object.assign(a,n),a.lignes=n.lignes},setProvenance(e){a.provenance=e},libererCibleFournie(){h.value=!1},syncReclamant(){let e=m.value;y.setReclamant({type:e?.type??null,id:e?.id??null})},selectReclamant(e){e&&(f(e,a.reclamant)||(h.value=!1),u.value.some(t=>f(t,e))||(d.value=e),y.setReclamant(e))},setReclamant({type:e,id:t}){let n=!f({type:e,id:t},a.reclamant);if(a.reclamant={type:e??null,id:t??null},s(`cible`)||h.value)return;let r=a.lignes[0];if(n){let e=a.lignes.filter((e,t)=>t>0&&e.cibleOverride);a.lignes.forEach((e,t)=>{t>0&&e.cibleOverride&&y.toggleCibleOverride(t)}),e.length&&(g.value=e.length)}e===`D`?(r.cibleMode=`demande`,r.patrimoine=null):(r.cibleMode=v.value?`contrat`:`patrimoine`,r.contratReclamant=v.value,r.contratCible=null,r.reprendreLocataireActuel=!1,r.patrimoine=D(),y.prefillCiblePrincipale())},prefillCiblePrincipale(){if(s(`cible`)||h.value)return;let e=_.value;e&&y.prefillFromModule(0,e)},_resetAfterNomenclature(){g.value=0,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,y._resetAfterNomenclature()},setType(e){let t=a.lignes[0];t.idType=e,t.idNature=null,t.idMotif=null,y._resetAfterNomenclature()},setNature(e){let t=a.lignes[0];t.idNature=e,t.idMotif=null,y._resetAfterNomenclature()},setMotif(e){a.lignes[0].idMotif=e,y._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,y._resetAfterNomenclature()},toggleLigneAssociee(e,t={}){let n=a.lignes.findIndex((t,n)=>n>0&&t.idMotif===e);n===-1?a.lignes.push({...O(),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`&&v.value,n.contratCible=null,t===`demande`?n.patrimoine=null:n.patrimoine??=D())},setModulePrecis(e,t){let n=a.lignes[e];n&&(n.modulePrecis=!!t,n.modulePrecis||y.setPatrimoineModule(e,null))},toggleContratReclamant(e,t){let n=a.lignes[e];n&&(n.contratReclamant=t??!n.contratReclamant,n.contratCible=null,n.patrimoine&&y.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,y.setPatrimoineModule(e,null))},setPatrimoineCommune(e,t){let n=y._patrimoine(e);n&&(n.idCommune=t?.idCommune??null,n.commune=t?.commune??null,y.setPatrimoineEntree(e,null))},setPatrimoineEntree(e,t){let n=y._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,y.setPatrimoineModule(e,null))},setPatrimoineEtage(e,t){let n=y._patrimoine(e);n&&(n.etage=t,y.setPatrimoineModule(e,null))},setPatrimoineModule(e,t){let n=y._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=y._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;g.value=0;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:oe(e.responsable)};if(r.cibleMode===`demande`)return{...c,codeTypeCible:`D`,idCible:a.reclamant.id,deduireCible:!1};let l=y._patrimoinePayload(r.patrimoine);if(r.cibleMode===`contrat`&&!r.reprendreLocataireActuel){let e=r.contratReclamant&&v.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=se(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&&v.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)=>y._lignePayload(e,t))},creationPayload(){let e=m.value;return{typeReclamant:e?.type??null,reclamant:e?.id??null,lignes:y.lignesPayload(),provenance:a.provenance}}};return(0,i.reactive)(y)}function me(e){return(0,i.provide)(ie,e),e}function M(){let e=(0,i.inject)(ie,null);if(!e)throw Error(`useSollicitationDraft() hors de <creer-sollicitation-form>`);return e}var N=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},he={name:`AsideBlock`,components:{AmsomNavTabsHorizontal:a.AmsomNavTabsHorizontal},props:{nbSimilaires:{type:Number,default:0}},setup(){return{draft:M()}},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)}}}},ge={key:0,class:`badge bg-danger ms-1`},_e={style:{"min-height":`320px`}},ve={key:0},ye={key:1};function be(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`),c=(0,i.resolveComponent)(`amsom-nav-tabs-horizontal`);return o.tabs.length?((0,i.openBlock)(),(0,i.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,i.withCtx)(({item:e})=>[(0,i.createVNode)(s,{icon:e.icon},null,8,[`icon`]),(0,i.createElementVNode)(`span`,null,(0,i.toDisplayString)(e.label),1),e.id===`similarite`&&n.nbSimilaires>0?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,ge,(0,i.toDisplayString)(n.nbSimilaires),1)):(0,i.createCommentVNode)(``,!0)]),content:(0,i.withCtx)(()=>[(0,i.createElementVNode)(`div`,_e,[e.$slots.similaires?(0,i.withDirectives)(((0,i.openBlock)(),(0,i.createElementBlock)(`div`,ve,[(0,i.renderSlot)(e.$slots,`similaires`,(0,i.normalizeProps)((0,i.guardReactiveProps)(o.scope)))],512)),[[i.vShow,a.activeTab===`similarite`]]):(0,i.createCommentVNode)(``,!0),e.$slots.evenements?(0,i.withDirectives)(((0,i.openBlock)(),(0,i.createElementBlock)(`div`,ye,[(0,i.renderSlot)(e.$slots,`evenements`)],512)),[[i.vShow,a.activeTab===`evenements`]]):(0,i.createCommentVNode)(``,!0)])]),_:3},8,[`modelValue`,`items`])):(0,i.createCommentVNode)(``,!0)}var xe=N(he,[[`render`,be]]),Se={name:`SectionComponent`,props:{titre:{type:String,required:!0},aide:{type:String,default:null}}},Ce={class:`d-flex flex-column gap-2`},we={class:`d-flex flex-wrap align-items-center justify-content-between gap-2`},Te={class:`fs-6 fw-semibold`},Ee={key:0,class:`text-muted d-flex align-items-center gap-1`};function De(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`);return(0,i.openBlock)(),(0,i.createElementBlock)(`section`,Ce,[(0,i.createElementVNode)(`div`,null,[(0,i.createElementVNode)(`div`,we,[(0,i.createElementVNode)(`span`,Te,(0,i.toDisplayString)(n.titre),1),(0,i.renderSlot)(e.$slots,`actions`)]),n.aide?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,Ee,[(0,i.createVNode)(s,{icon:`circle-info`}),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(n.aide),1)])):(0,i.createCommentVNode)(``,!0)]),(0,i.renderSlot)(e.$slots,`default`)])}var P=N(Se,[[`render`,De]]),Oe=e=>`fa`+e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);async function F(e){let n=await import(`@fortawesome/free-solid-svg-icons`);[...new Set(e.filter(Boolean))].forEach(e=>{let r=n[Oe(e)];r&&t.library.add(r)})}function I(e,t=!0){if(!e)return null;let n=e.toString().normalize(`NFD`).replace(/[̀-ͯ]/g,``);return t?n.toLowerCase():n}var ke={name:`IconSelectComponent`,components:{AmsomAutocomplete:s.AmsomAutocomplete},props:{modelValue:{type:[String,Number],default:null},items:{type:Array,default:()=>[]},label:{type:String,required:!0},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},placeholder:{type:String,default:`Choisir…`}},emits:[`update:modelValue`],data(){return{iconsReady:!1}},computed:{selected(){return this.items.find(e=>e.id===this.modelValue)??null}},watch:{items:{immediate:!0,async handler(e){await F(e.map(e=>e.icon)),this.iconsReady=!0}}},methods:{filtrer({search:e,items:t}){let n=(I(e)??``).trim();return n?t.filter(e=>(I(e?.libelle)??``).includes(n)):t}}},Ae={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},je={key:0,class:`ms-1 text-danger`},Me={class:`d-inline-flex align-items-center gap-2`};function Ne(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`),c=(0,i.resolveComponent)(`amsom-autocomplete`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,null,[(0,i.createElementVNode)(`label`,Ae,[(0,i.createTextVNode)((0,i.toDisplayString)(n.label),1),n.required?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,je,`*`)):(0,i.createCommentVNode)(``,!0)]),a.iconsReady?((0,i.openBlock)(),(0,i.createBlock)(c,{key:0,"model-value":o.selected,items:n.items,"get-id":e=>e?.id??null,"get-input-libelle":e=>e?.libelle??``,"filtering-function":o.filtrer,disabled:n.disabled,placeholder:n.placeholder,required:``,"input-size":`sm`,"onUpdate:modelValue":t[0]||=t=>e.$emit(`update:modelValue`,t?.id??null)},{options:(0,i.withCtx)(e=>[(0,i.createElementVNode)(`span`,Me,[e?.icon?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,icon:e.icon,"fixed-width":``},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(e?.libelle),1)])]),_:1},8,[`model-value`,`items`,`get-id`,`get-input-libelle`,`filtering-function`,`disabled`,`placeholder`])):(0,i.createCommentVNode)(``,!0)])}var Pe=N(ke,[[`render`,Ne]]),Fe={baseUrl:``,getToken:()=>l.default.getToken(),setToken:e=>l.default.setToken(e),logout:()=>l.default.logout(),goToLoginPage:()=>l.default.goToLoginPage()};function Ie(e={}){Object.assign(Fe,e)}var L=()=>Fe;function Le(e,t={}){let n=L(),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,c.default)(e,t)}var Re=(e,t)=>{let n=t||L().baseUrl;if(!n)throw Error(`Cresol : baseUrl non renseignée (configureCresol ou prop baseUrl)`);return`${n}${e}`},ze=(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}`:``},Be=({method:e,path:t,params:n,data:r,signal:i,baseUrl:a},o={})=>Le({url:Re(`${t}${ze(n)}`,a),method:e,...r===void 0?{}:{data:r},...i?{signal:i}:{}},o),R=(e,{params:t,signal:n,overlay:r,baseUrl:i}={})=>Be({method:`GET`,path:e,params:t,signal:n,baseUrl:i},r).then(e=>e.data),Ve=(e,t,{params:n,signal:r,overlay:i,baseUrl:a}={})=>Be({method:`POST`,path:e,params:n,data:t,signal:r,baseUrl:a},i).then(e=>e.data),He={mustBeAuthenticated:!1},z=(e,{signal:t,baseUrl:n}={})=>R(e,{signal:t,baseUrl:n,overlay:He}),Ue=e=>z(`/v2/sollicitation/motifs`,e),We=e=>z(`/v2/sollicitation/categories`,e),Ge=e=>z(`/v2/sollicitation/types`,e),Ke=e=>z(`/v2/sollicitation/natures`,e),qe=e=>z(`/v2/sollicitation/etats`,e),Je=({signal:e,baseUrl:t}={})=>R(`/v2/sollicitation/provenances`,{params:{estDesactive:!1},signal:e,baseUrl:t,overlay:He}),Ye=({signal:e,baseUrl:t}={})=>R(`/collaborateurs`,{params:{actif:!0},signal:e,baseUrl:t}),Xe=async({signal:e,baseUrl:t}={})=>(await R(`/v2/patrimoine/communes`,{signal:e,baseUrl:t})??[]).map(e=>({idCommune:e.id,commune:e.libelle})),Ze=(e,{signal:t,baseUrl:n}={})=>R(`/v2/patrimoine/entrees`,{params:{idCommune:e},signal:t,baseUrl:n}),Qe=(e,{signal:t,baseUrl:n}={})=>R(`/v2/patrimoine/modules`,{params:{codeProgramme:e},signal:t,baseUrl:n}),$e=({idContrat:e,typeContrat:t},{signal:n,baseUrl:r}={})=>R(`/v2/patrimoine/contrat_modules`,{params:{idContrat:e,typeContrat:t},signal:n,baseUrl:r}),et=({motif:e,categorie:t,type:n,nature:r},{signal:i,baseUrl:a}={})=>R(`/v2/sollicitation/responsables`,{params:{motif:e,categorie:t,type:n,nature:r},signal:i,baseUrl:a}),tt=(e,{signal:t,baseUrl:n}={})=>R(`/v2/patrimoine/contrat_module_rechercher`,{params:{recherche:e},signal:t,baseUrl:n}),nt=({categorie:e,recherche:t},{signal:n,baseUrl:r}={})=>R(`/v2/cresol/reclamant_rechercher`,{params:{categorie:e,recherche:t},signal:n,baseUrl:r});function B(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 rt=e=>e?.name===`AbortError`||e?.name===`CanceledError`,V=Symbol(`cresol:data`),it=()=>({motifs:null,categories:null,types:null,natures:null,etats:null,provenances:null,collaborateurs:null,communes:null,adressesByCommune:{},modulesByProgramme:{},modulesByContrat:{},responsablesByMotif:{}}),H=new Map,at=e=>(H.has(e)||H.set(e,(0,i.reactive)(it())),H.get(e)),U=new Map;function ot(){H.clear(),U.clear()}var W=(e,t,n)=>e?.find(e=>e[t]===n)?.libelle??n,G=(e,t,n)=>e?.find(e=>e[t]===n)?.icon??null;function st({onError:e,baseUrl:t}={}){let n=(0,i.ref)(0),r=()=>({baseUrl:(0,i.unref)(t)||null}),a=()=>(0,i.unref)(t)||L().baseUrl||``,o=()=>at(a()),s=(t,r)=>{let i=`${a()}|${t}`;if(U.has(i))return U.get(i);n.value+=1;let o=Promise.resolve().then(r).catch(t=>(rt(t)||e?.(B(t)),null)).finally(()=>{--n.value,U.delete(i)});return U.set(i,o),o},c=(e,t)=>o()[e]?.length?Promise.resolve(o()[e]):s(`referentiel:${e}`,async()=>(o()[e]=await t(r()),o()[e])),l={get cache(){return o()},loading:n,isLoading:(0,i.computed)(()=>n.value>0),loadNomenclature(){return Promise.all([c(`motifs`,Ue),c(`categories`,We),c(`types`,Ge),c(`natures`,Ke),c(`etats`,qe)])},loadCollaborateurs:()=>c(`collaborateurs`,Ye),loadProvenances:()=>c(`provenances`,Je),loadCommunes(){return o().communes?.length?Promise.resolve(o().communes):s(`communes`,async()=>(o().communes=await Xe(r()),o().communes))},loadAdresses(e){return e==null?Promise.resolve([]):o().adressesByCommune[e]?Promise.resolve(o().adressesByCommune[e]):s(`adresses:${e}`,async()=>{let t=await Ze(e,r());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 Qe(e,r());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 i=await $e({idContrat:e,typeContrat:t},r());return o().modulesByContrat[n]=i??[],i})},async searchContrats(e,{signal:t}={}){let n=(e??``).trim();if(!n)return[];let i=await tt(n,{...r(),signal:t}),a=new Map;for(let e of i??[]){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,dateSortie:e.dateSortieContrat??null,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 i=(t??``).trim();if(!i)return[];let a=await nt({categorie:e,recherche:i},{...r(),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,idModule:t.idModule,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.dateSortie),n=t.every(e=>e!=null)?Math.max(...t):null,r=e.individus.map(e=>[e.nom,e.prenom].filter(Boolean).join(` `)).filter(Boolean).join(`, `),i={locataire:`${e.libelleReclamant||r} — Contrat ${e.type}/${e.id}`,demandeur:`${r} — ${e.libelleReclamant}`}[e.categorie];return{...e,dateSortie:n,libelle:i??e.libelleReclamant}})},loadResponsables({motif:e,categorie:t,type:n,nature:i}){return e==null?Promise.resolve([]):o().responsablesByMotif[e]?Promise.resolve(o().responsablesByMotif[e]):s(`responsables:${e}`,async()=>{let a=await et({motif:e,categorie:t,type:n,nature:i},r());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=>W(o().motifs,`id`,e),categorieLibelle:e=>W(o().categories,`id`,e),typeLibelle:e=>W(o().types,`id`,e),natureLibelle:e=>W(o().natures,`id`,e),etatLibelle:e=>W(o().etats,`code`,e),motifIcon:e=>G(o().motifs,`id`,e),categorieIcon:e=>G(o().categories,`id`,e),typeIcon:e=>G(o().types,`id`,e),natureIcon:e=>G(o().natures,`id`,e)};return(0,i.reactive)(l)}function ct(e){return(0,i.provide)(V,e),e}function K(){let e=(0,i.inject)(V,null);if(!e)throw Error(`useCresolData() hors de <creer-sollicitation-form>`);return e}var lt=Symbol(`cresol:options`),ut=e=>(0,i.provide)(lt,e),q=()=>(0,i.inject)(lt,{}),dt={name:`ProvenanceSelecteurBlock`,components:{IconSelectComponent:Pe},setup(){return{draft:M(),data:K(),options:q()}},computed:{provenances(){return this.options.provenances},loaded(){return this.data.cache.provenances!=null},selected(){return this.draft.draft.provenance},libelleFige(){return this.data.cache.provenances?.find(e=>e.id===this.selected)?.libelle??this.selected??`—`},provenanceChoisie(){return this.provenances.find(e=>e.id===this.selected)??null}}},ft={key:0},pt=[`value`],mt={key:1},ht={key:0,class:`fs-7 text-danger mt-1`};function gt(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`icon-select-component`);return r.draft.isReadonly(`provenance`)?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,ft,[t[1]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Provenance`,-1),(0,i.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:o.libelleFige},null,8,pt)])):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,mt,[(0,i.createVNode)(s,{"model-value":o.provenanceChoisie?.id??null,items:o.provenances,label:`Provenance`,required:``,"onUpdate:modelValue":t[0]||=e=>r.draft.setProvenance(e)},null,8,[`model-value`,`items`]),o.loaded&&!o.provenanceChoisie?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,ht,` Sélectionnez par quel canal la sollicitation vous est parvenue. `)):(0,i.createCommentVNode)(``,!0)]))}var _t=N(dt,[[`render`,gt]]);function vt(e){return e==null?``:new Date(e*1e3).toISOString().slice(0,10)}function yt(e){return e?Math.floor(new Date(e).getTime()/1e3):null}function J(e){return e==null?``:new Date(e*1e3).toLocaleDateString(`fr-FR`)}var bt=(0,i.ref)(!1);F(Object.values(x).map(e=>e.icon)).then(()=>{bt.value=!0});var xt={name:`ReclamantTypeBadgeComponent`,props:{reclamant:{type:Object,default:null},iconOnly:{type:Boolean,default:!1}},setup(){return{iconsReady:bt}},computed:{type(){return re(this.reclamant)}}},St=[`title`],Ct={key:1};function wt(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`);return o.type?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,{key:0,class:(0,i.normalizeClass)([`badge d-inline-flex align-items-center gap-1 border flex-shrink-0`,`bg-${o.type.couleur}-subtle text-${o.type.couleur}-emphasis border-${o.type.couleur}-subtle`]),title:o.type.libelle},[r.iconsReady?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,icon:o.type.icon,"fixed-width":``},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0),n.iconOnly?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`span`,Ct,(0,i.toDisplayString)(o.type.libelle),1))],10,St)):(0,i.createCommentVNode)(``,!0)}var Tt=N(xt,[[`render`,wt]]),Y=[{key:`locataire`,label:`Locataire`,icon:x.locataire.icon,recherche:`Rechercher un locataire`,aucun:`Aucun locataire trouvé.`,placeholder:`Nom, prénom, n° de contrat ou de module, adresse, téléphone ou mail…`},{key:`demandeur`,label:`Demandeur`,icon:x.demandeur.icon,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:x.tiers.icon,recherche:`Rechercher un tiers`,aucun:`Aucun tiers trouvé.`,placeholder:`Raison sociale, adresse, téléphone ou mail…`},{key:`autre`,label:`Autre`,icon:x.autre.icon,recherche:`Rechercher un individu « Autre »`,aucun:`Aucun individu « Autre » trouvé.`,placeholder:`Nom, prénom, adresse, téléphone ou mail…`},{key:`fournisseur`,label:`Fournisseur`,icon:x.fournisseur.icon,recherche:`Rechercher un fournisseur`,aucun:`Aucun fournisseur trouvé.`,placeholder:`Raison sociale, adresse, téléphone ou mail…`},{key:`personnel`,label:`Personnel`,icon:x.personnel.icon,recherche:`Rechercher un collaborateur`,aucun:`Aucun collaborateur trouvé.`,placeholder:`Nom, prénom, 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, de module ou de demande, adresse, téléphone ou mail…`}],Et={signataire:`Signataire`,occupant:`Occupant`,demandeur:`Demandeur`},Dt={name:`ReclamantRechercheBlock`,components:{AmsomAutocomplete:s.AmsomAutocomplete,AmsomOverlay:r.AmsomOverlay,IconSelectComponent:Pe,ReclamantTypeBadgeComponent:Tt},setup(){return{draft:M(),data:K(),options:q()}},data(){return{iconsReady:!1,categorie:null,trouves:[],rechercheEnCours:!1,rechercheFaite:!1}},computed:{typesAutorises(){return this.options.typesReclamant??w},autorisees(){return T(this.typesAutorises)},categories(){return Y.filter(e=>e.key===`tout`?this.autorisees.length>1:this.autorisees.includes(e.key))},categoriesItems(){return this.categories.map(e=>({id:e.key,libelle:e.label,icon:e.icon}))},categorieCourante(){return Y.find(e=>e.key===this.categorie)},selectionne(){return this.draft.reclamantSelectionne},estFige(){return this.draft.isReadonly(`reclamant`)},selectedTrouve:{get(){return this.categorie===`tout`||this.categorieOf(this.selectionne)===this.categorie?this.selectionne:null},set(e){this.select(e)}}},watch:{selectionne(e){this.categorie!==`tout`&&(this.categorie=this.categorieOf(e)??this.categorie)}},async created(){this.categorie=this.categorieOf(this.selectionne)??this.categories[0]?.key??null,await F(Y.map(e=>e.icon)),this.iconsReady=!0},beforeUnmount(){clearTimeout(this.rechercheTimeout),this.controller?.abort()},methods:{select(e){e&&!this.estFige&&this.draft.selectReclamant(e)},setCategorie(e){e&&e!==this.categorie&&!this.estFige&&(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===`tout`?this.autorisees.join(`,`):this.categorie,t,{signal:this.controller.signal}).then(e=>{this.trouves=(e??[]).filter(e=>this.typesAutorises.includes(e.type)),this.rechercheFaite=!0,this.rechercheEnCours=!1}).catch(()=>{this.rechercheEnCours=!1}))},cleReclamant(e){return e?`${e.type}|${e.id}`:null},categorieOf(e){let t=E(e);return this.autorisees.includes(t)?t:null},sortiLibelle(e){return e?.dateSortie==null?`sorti`:`sorti le ${J(e.dateSortie)}`},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=this.categorieOf(e);return t===`locataire`?e.libelleReclamant||this.nomsOf(e):t===`demandeur`?this.nomsOf(e):e.libelleReclamant},referenceOf(e){if(!e?.individus)return``;let t=this.categorieOf(e);return t===`locataire`?[`Contrat ${e.type}/${e.id}`,e.idModule&&`Module ${e.idModule}`].filter(Boolean).join(` — `):t===`demandeur`?e.libelleReclamant:t===`autre`?`Individu « Autre »`:re(e).libelle},detailOf(e){let t=e?.individus??[];if(![`locataire`,`demandeur`].includes(E(e))){let e=t[0];return e?[e.telephone,e.mail].filter(Boolean).join(` — `):``}return t.map(t=>{let n=[t.nom,t.prenom].filter(Boolean).join(` `),r=e.estActif&&t.dateSortie!=null&&t.dateSortie*1e3<Date.now()?`sorti le ${J(t.dateSortie)}`:null,i=[Et[t.role]?.toLowerCase(),r].filter(Boolean).join(`, `);return i?`${n} (${i})`:n}).join(`, `)}}},Ot={class:`row g-3`},kt={key:0,class:`col-12 col-md-6`},At={class:`col-12`},jt={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},Mt={key:0,class:`ms-1 text-danger`},Nt={class:`min-w-0`},Pt={key:0,class:`badge bg-warning-subtle text-warning-emphasis ms-1`},Ft={class:`text-muted d-block text-truncate`},It={key:0},Lt={key:0,class:`text-muted d-block text-truncate`},Rt={key:0,class:`text-muted`};function zt(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`icon-select-component`),c=(0,i.resolveComponent)(`reclamant-type-badge-component`),l=(0,i.resolveComponent)(`amsom-autocomplete`),u=(0,i.resolveComponent)(`amsom-overlay`);return a.iconsReady?((0,i.openBlock)(),(0,i.createBlock)(u,{key:0,loading:r.options.repriseReclamant},{default:(0,i.withCtx)(()=>[(0,i.createElementVNode)(`div`,Ot,[e.$slots[`avant-categorie`]?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,kt,[(0,i.renderSlot)(e.$slots,`avant-categorie`)])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`col-12`,{"col-md-6":e.$slots[`avant-categorie`]}])},[(0,i.createVNode)(s,{"model-value":a.categorie,items:o.categoriesItems,label:`Le réclamant est…`,disabled:o.estFige,"onUpdate:modelValue":t[0]||=e=>o.setCategorie(e)},null,8,[`model-value`,`items`,`disabled`])],2),(0,i.createElementVNode)(`div`,At,[(0,i.createElementVNode)(`label`,jt,[(0,i.createTextVNode)((0,i.toDisplayString)(o.categorieCourante.recherche),1),o.estFige?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`span`,Mt,`*`))]),((0,i.openBlock)(),(0,i.createBlock)(l,{key:a.categorie,modelValue:o.selectedTrouve,"onUpdate:modelValue":t[1]||=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`,disabled:o.estFige,"hide-choices":``,"debounce-delay":0,onSearch:o.rechercherPlusTard},{options:(0,i.withCtx)(e=>[(0,i.createElementVNode)(`div`,Nt,[(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`fw-medium text-truncate`,e?.estActif?``:`text-muted`])},[(0,i.createVNode)(c,{reclamant:e,"icon-only":``,class:`me-1`},null,8,[`reclamant`]),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(o.titreOf(e))+` `,1),e?.estActif?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`span`,Pt,(0,i.toDisplayString)(o.categorieOf(e)===`demandeur`?`inactive`:o.sortiLibelle(e)),1))],2),(0,i.createElementVNode)(`small`,Ft,[(0,i.createTextVNode)((0,i.toDisplayString)(o.referenceOf(e))+` `,1),e?.adresse?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,It,` — `+(0,i.toDisplayString)(e.adresse),1)):(0,i.createCommentVNode)(``,!0)]),o.detailOf(e)?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,Lt,(0,i.toDisplayString)(o.detailOf(e)),1)):(0,i.createCommentVNode)(``,!0)])]),_:1},8,[`modelValue`,`items`,`filtering-function`,`loading`,`get-id`,`get-input-libelle`,`placeholder`,`disabled`,`onSearch`])),a.rechercheFaite&&!a.rechercheEnCours&&!a.trouves.length?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,Rt,(0,i.toDisplayString)(o.categorieCourante.aucun),1)):(0,i.createCommentVNode)(``,!0)])])]),_:3},8,[`loading`])):(0,i.createCommentVNode)(``,!0)}var Bt=N(Dt,[[`render`,zt]]),Vt={name:`ReclamantSelecteurBlock`,components:{AmsomAutocomplete:s.AmsomAutocomplete,ReclamantTypeBadgeComponent:Tt},props:{mode:{type:String,default:null}},setup(){return{draft:M(),options:q()}},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=(I(e)??``).trim();return n?t.filter(e=>(I(e?.libelle)??``).includes(n)):t}}},Ht={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},Ut={key:0,class:`ms-1 text-danger`},Wt=[`value`],Gt={key:1,class:`btn-group btn-group-sm w-100`,role:`group`},Kt=[`onClick`],qt=[`value`],Jt=[`value`];function Yt(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`reclamant-type-badge-component`),c=(0,i.resolveComponent)(`amsom-autocomplete`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,null,[(0,i.createElementVNode)(`label`,Ht,[t[2]||=(0,i.createTextVNode)(` Réclamant`,-1),o.estFige?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`span`,Ut,`*`))]),o.estFige?((0,i.openBlock)(),(0,i.createElementBlock)(`input`,{key:0,class:`form-control form-control-sm`,disabled:``,value:o.reclamantSelectionne?.libelle??`—`},null,8,Wt)):o.presentation===`switch`?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Gt,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.reclamants,(e,t)=>((0,i.openBlock)(),(0,i.createElementBlock)(`button`,{key:t,type:`button`,class:(0,i.normalizeClass)([`btn d-inline-flex align-items-center justify-content-center`,e===o.reclamantSelectionne?`btn-primary`:`btn-outline-primary`]),onClick:t=>o.select(e)},(0,i.toDisplayString)(e.libelle),11,Kt))),128))])):o.presentation===`autocomplete`?((0,i.openBlock)(),(0,i.createBlock)(c,{key:2,"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`,required:``,"onUpdate:modelValue":t[0]||=e=>o.select(e)},{options:(0,i.withCtx)(e=>[(0,i.createVNode)(s,{reclamant:e,"icon-only":``,class:`me-1`},null,8,[`reclamant`]),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(e?.libelle),1)]),_:1},8,[`model-value`,`items`,`get-id`,`get-input-libelle`,`filtering-function`])):((0,i.openBlock)(),(0,i.createElementBlock)(`select`,{key:3,class:`form-select form-select-sm`,value:o.reclamants.indexOf(o.reclamantSelectionne),onChange:t[1]||=e=>o.select(o.reclamants[e.target.value])},[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.reclamants,(e,t)=>((0,i.openBlock)(),(0,i.createElementBlock)(`option`,{key:t,value:t},(0,i.toDisplayString)(e.libelle),9,Jt))),128))],40,qt))])}var Xt=N(Vt,[[`render`,Yt]]),Zt={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`:Zt[e]??n}function $t(e){return e?e.idCategorieModule===`L`?e.estCollectif?`Appartement`:`Maison`:e.categorieModule??``:``}var en=0,tn={name:`CiblePickerBlock`,components:{AmsomAutocomplete:s.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:K()}},data(){return{uid:++en,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:{formatDate:J,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=(I(t)??``).trim();return r?n.filter(t=>(I(t?.[e])??``).includes(r)):n}},filterModules({search:e,items:t}){let n=(I(e)??``).trim();return n?t.filter(e=>String(e?.idModule??``).includes(n)||(I(this.moduleInputLibelle(e))??``).includes(n)||(I(e?._autreLibelle)??``).includes(n)):t},getCategorieModuleIcon:Qt,categorieLibelle:$t,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)}}},nn={class:`d-flex flex-column gap-3`},rn={class:`btn-group w-100`,role:`group`},an=[`onClick`],on={class:`text-muted d-block mt-1`},sn={key:0,class:`form-check`},cn=[`id`,`checked`],ln=[`for`],un={key:1},dn={class:`min-w-0`},fn={class:`fw-medium text-truncate text-capitalize`},pn={class:`d-flex flex-wrap align-items-center gap-1`},mn={class:`text-muted`},hn={key:0,class:`badge bg-info`},gn={key:1,class:`badge bg-warning`},_n={key:0,class:`text-muted d-block text-truncate`},vn={key:1},yn={class:`row g-2`},bn=[`aria-pressed`,`onClick`],xn={class:`min-w-0`},Sn={class:`d-block fw-semibold fs-6`},Cn={class:`d-block text-muted`},wn={key:2,class:`row g-3`},Tn={class:`min-w-0`},En={class:`fw-medium text-truncate`},Dn={class:`text-muted d-block text-truncate`},On=[`value`],kn=[`value`],An=[`value`],jn={key:0,class:`col-12 col-md-6`},Mn={class:`d-flex flex-wrap align-items-center gap-1`},Nn=[`title`],Pn={class:`text-muted`},Fn={key:1,class:`d-block text-truncate`},In={key:2,class:`text-muted d-block`},Ln={key:0,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,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`),c=(0,i.resolveComponent)(`amsom-autocomplete`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,nn,[(0,i.createElementVNode)(`div`,null,[t[7]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` La sollicitation concerne… `,-1),(0,i.createElementVNode)(`div`,rn,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.availableModes,t=>((0,i.openBlock)(),(0,i.createElementBlock)(`button`,{key:t.key,type:`button`,class:(0,i.normalizeClass)([`btn btn-sm`,n.cibleMode===t.key?`btn-primary`:`btn-outline-primary`]),onClick:n=>e.$emit(`change-mode`,t.key)},[(0,i.createVNode)(s,{icon:t.icon,class:`me-1`},null,8,[`icon`]),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(t.label),1)],10,an))),128))]),(0,i.createElementVNode)(`small`,on,(0,i.toDisplayString)(o.currentMode?.aide),1)]),n.cibleMode===`contrat`?((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:0},[n.afficheCaseContratReclamant?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,sn,[(0,i.createElementVNode)(`input`,{id:`contrat-reclamant-${a.uid}`,class:`form-check-input`,type:`checkbox`,checked:n.contratReclamant,onChange:t[0]||=t=>e.$emit(`toggle-contrat-reclamant`,t.target.checked)},null,40,cn),(0,i.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`contrat-reclamant-${a.uid}`},` Contrat du réclamant `,8,ln)])):(0,i.createCommentVNode)(``,!0),n.contratReclamant?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,un,[t[8]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Contrat ciblé `,-1),(0,i.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,i.withCtx)(e=>[(0,i.createElementVNode)(`div`,dn,[(0,i.createElementVNode)(`div`,fn,(0,i.toDisplayString)(e?.libelle??`Contrat ${e?.idContrat}`),1),(0,i.createElementVNode)(`div`,pn,[(0,i.createElementVNode)(`small`,mn,`N° `+(0,i.toDisplayString)(e?.typeContrat)+`/`+(0,i.toDisplayString)(e?.idContrat),1),e?.nbModules>1?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,hn,(0,i.toDisplayString)(e.nbModules)+` modules`,1)):(0,i.createCommentVNode)(``,!0),e?.estSorti?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,gn,(0,i.toDisplayString)(e.dateSortie?`Sorti le ${o.formatDate(e.dateSortie)}`:`Sorti`),1)):(0,i.createCommentVNode)(``,!0)]),o.contratAdresse(e)?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,_n,(0,i.toDisplayString)(o.contratAdresse(e)),1)):(0,i.createCommentVNode)(``,!0)])]),_:1},8,[`modelValue`,`items`,`filtering-function`,`loading`,`get-id`,`get-input-libelle`,`onSearch`])]))],64)):(0,i.createCommentVNode)(``,!0),n.cibleMode===`patrimoine`?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,vn,[t[9]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Le problème concerne… `,-1),(0,i.createElementVNode)(`div`,yn,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.portees,t=>((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:t.titre,class:`col-12 col-md-6`},[(0,i.createElementVNode)(`button`,{type:`button`,class:(0,i.normalizeClass)([`btn w-100 h-100 text-start d-flex align-items-center gap-3 p-3 rounded border text-primary`,t.modulePrecis===n.modulePrecis?`border-primary bg-light`:`bg-white`]),"aria-pressed":t.modulePrecis===n.modulePrecis,onClick:n=>e.$emit(`set-module-precis`,t.modulePrecis)},[(0,i.createVNode)(s,{icon:t.icon,class:`fs-4`,"fixed-width":``},null,8,[`icon`]),(0,i.createElementVNode)(`span`,xn,[(0,i.createElementVNode)(`span`,Sn,(0,i.toDisplayString)(t.titre),1),(0,i.createElementVNode)(`small`,Cn,(0,i.toDisplayString)(t.aide),1)])],10,bn)]))),128))])])):(0,i.createCommentVNode)(``,!0),n.cibleMode===`contrat`||n.cibleMode===`patrimoine`?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,wn,[(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`col-12 d-flex flex-column gap-3`,{"col-md-6":o.afficheModule}])},[n.cibleMode===`patrimoine`?((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:0},[(0,i.createElementVNode)(`div`,null,[t[10]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Commune `,-1),(0,i.createVNode)(c,{modelValue:o.selectedCommune,"onUpdate:modelValue":t[2]||=e=>o.selectedCommune=e,items:r.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,i.createElementVNode)(`div`,null,[t[11]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Adresse `,-1),(0,i.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:!n.patrimoine.idCommune,placeholder:`Rechercher une adresse…`,"input-size":`sm`,"hide-choices":``},{options:(0,i.withCtx)(e=>[(0,i.createElementVNode)(`div`,Tn,[(0,i.createElementVNode)(`div`,En,(0,i.toDisplayString)(e?.entree),1),(0,i.createElementVNode)(`small`,Dn,(0,i.toDisplayString)(e?.commune)+` — Programme `+(0,i.toDisplayString)(e?.codeProgramme),1)])]),_:1},8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`filtering-function`,`disabled`])]),(0,i.createElementVNode)(`div`,null,[t[12]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Étage`,-1),(0,i.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:!n.patrimoine.idEntree,placeholder:`Tous les étages…`,"input-size":`sm`,"hide-choices":``},null,8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`disabled`])])],64)):((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:1},[(0,i.createElementVNode)(`div`,null,[t[13]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Commune `,-1),(0,i.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:n.patrimoine.commune??`—`},null,8,On)]),(0,i.createElementVNode)(`div`,null,[t[14]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Adresse `,-1),(0,i.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:n.patrimoine.entree??`—`},null,8,kn)]),(0,i.createElementVNode)(`div`,null,[t[15]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Étage`,-1),(0,i.createElementVNode)(`input`,{class:`form-control form-control-sm`,disabled:``,value:n.patrimoine.etage??`—`},null,8,An)])],64))],2),o.afficheModule?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,jn,[t[16]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Module`,-1),(0,i.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,i.withCtx)(e=>[(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`min-w-0 w-100 rounded position-relative`,e?._autreLibelle?`bg-yellow-subtle p-2`:``])},[e?._autreLibelle?((0,i.openBlock)(),(0,i.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,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`fw-medium text-truncate`,[e?._autreLibelle?`text-muted`:``,o.isExit(e)?`text-decoration-line-through`:``]])},(0,i.toDisplayString)(o.moduleLibelle(e)),3),(0,i.createElementVNode)(`div`,Mn,[o.categorieLibelle(e)?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,{key:0,class:`badge bg-info`,title:e?.categorieModule},[(0,i.createVNode)(s,{icon:o.getCategorieModuleIcon(e?.idCategorieModule,e?.estCollectif)},null,8,[`icon`])],8,Nn)):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`small`,Pn,`N° `+(0,i.toDisplayString)(e?.idModule),1)]),e?._autreLibelle?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,Fn,(0,i.toDisplayString)(e._autreLibelle),1)):e?.etage==null?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`small`,In,` Étage `+(0,i.toDisplayString)(e.etage),1))],2)]),_:1},8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`filtering-function`,`disabled`]),n.locataireActuelOption?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Ln,[(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`alert d-flex align-items-start gap-2 py-2 px-3 mt-2 mb-0 fs-7`,n.locataireActuelOption.reprendre?`alert-warning`:`alert-secondary border`])},[(0,i.createVNode)(s,{icon:`circle-info`,class:`mt-1`}),(0,i.createElementVNode)(`span`,null,(0,i.toDisplayString)(n.locataireActuelOption.hint),1)],2),(0,i.createElementVNode)(`div`,Rn,[(0,i.createElementVNode)(`input`,{id:`locataire-actuel-${a.uid}`,class:`form-check-input`,type:`checkbox`,checked:n.locataireActuelOption.reprendre,onChange:t[6]||=t=>e.$emit(`toggle-reprendre-locataire-actuel`,t.target.checked)},null,40,zn),(0,i.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`locataire-actuel-${a.uid}`},` Rattacher au locataire actuel du module `,8,Bn)])])):(0,i.createCommentVNode)(``,!0)])):(0,i.createCommentVNode)(``,!0)])):(0,i.createCommentVNode)(``,!0)])}var Hn=N(tn,[[`render`,Vn]]),Un=0,Wn={name:`LigneCibleBlock`,components:{AmsomOverlay:r.AmsomOverlay,CiblePickerBlock:Hn},props:{index:{type:Number,required:!0}},setup(){return{draft:M(),data:K(),options:q()}},data(){return{uid:++Un}},computed:{isPrincipale(){return this.index===0},ligne(){return this.draft.draft.lignes[this.index]},cibleFigee(){return this.draft.isReadonly(`cible`)},reclamantModules(){return this.options.modulesReclamant??[]},mainModule(){return this.draft.moduleReclamantPrincipal},localisation(){let e=this.ligne?.patrimoine;return{actif:!this.cibleFigee&&!!e&&this.ligne.cibleMode!==`demande`,idCommune:e?.idCommune??null,codeProgramme:this.ligne?.cibleMode===`patrimoine`?e?.codeProgramme??null:null}},locataireActuelOption(){let e=this.ligne;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}}},watch:{localisation:{immediate:!0,deep:!0,handler({actif:e,idCommune:t,codeProgramme:n}){e&&(this.data.loadCommunes(),this.data.loadAdresses(t),this.data.loadModulesOfProgramme(n))}}},created(){this.isPrincipale&&!this.cibleFigee&&!this.draft.reclamantEstContrat&&this.ligne.cibleMode===`contrat`&&this.draft.setCibleMode(0,`patrimoine`)},methods:{onChangeMode(e){this.draft.setCibleMode(this.index,e),e!==`demande`&&this.draft.prefillFromModule(this.index,this.mainModule)},onSelectModule(e){e&&this.ligne.cibleMode===`contrat`?this.draft.prefillFromModule(this.index,e):this.draft.setPatrimoineModule(this.index,e??null)},onToggleContratReclamant(e){this.draft.toggleContratReclamant(this.index,e),e&&this.draft.prefillFromModule(this.index,this.mainModule)},onSelectContrat(e){this.draft.setContratCible(this.index,e),e&&this.data.loadModulesOfContrat({idContrat:e.idContrat,typeContrat:e.typeContrat})}}},Gn={key:0,class:`d-flex flex-wrap align-items-center gap-2`},Kn={class:`fw-medium fs-7`},qn={key:0,class:`form-check form-switch mb-0`},Jn=[`id`,`checked`],Yn=[`for`];function Xn(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`),c=(0,i.resolveComponent)(`cible-picker-block`),l=(0,i.resolveComponent)(`amsom-overlay`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,{class:(0,i.normalizeClass)({"border rounded p-2":!o.isPrincipale})},[o.isPrincipale?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Gn,[(0,i.createElementVNode)(`span`,Kn,(0,i.toDisplayString)(o.ligne.libelle),1),o.cibleFigee?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,qn,[(0,i.createElementVNode)(`input`,{id:`memecible-${a.uid}`,class:`form-check-input`,type:`checkbox`,checked:!o.ligne.cibleOverride,onChange:t[0]||=e=>r.draft.toggleCibleOverride(n.index)},null,40,Jn),(0,i.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`memecible-${a.uid}`},` Même cible que la ligne principale `,8,Yn)]))])),o.cibleFigee?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:1,class:(0,i.normalizeClass)([`fs-7`,{"mt-1":!o.isPrincipale}])},[(0,i.createVNode)(s,{icon:`location-dot`,class:`text-primary me-2`}),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(r.draft.cibleResume(o.ligne)),1)],2)):o.isPrincipale||o.ligne.cibleOverride?((0,i.openBlock)(),(0,i.createBlock)(l,{key:2,loading:r.data.isLoading&&!r.data.cache.communes?.length},{default:(0,i.withCtx)(()=>[(0,i.createVNode)(c,{class:(0,i.normalizeClass)({"mt-2":!o.isPrincipale}),patrimoine:o.ligne.patrimoine,"cible-mode":o.ligne.cibleMode,"reclamant-modules":o.reclamantModules,"reclamant-type":r.draft.draft.reclamant.type,"contrat-reclamant":o.ligne.contratReclamant,"contrat-cible":o.ligne.contratCible,"module-precis":o.ligne.modulePrecis,"affiche-case-contrat-reclamant":r.draft.reclamantEstContrat,"locataire-actuel-option":o.locataireActuelOption,onChangeMode:o.onChangeMode,onSelectCommune:t[1]||=e=>r.draft.setPatrimoineCommune(n.index,e??null),onSelectAdresse:t[2]||=e=>r.draft.setPatrimoineEntree(n.index,e??null),onSelectEtage:t[3]||=e=>r.draft.setPatrimoineEtage(n.index,e??null),onSelectModule:o.onSelectModule,onSelectContrat:o.onSelectContrat,onToggleContratReclamant:o.onToggleContratReclamant,onToggleReprendreLocataireActuel:t[4]||=e=>r.draft.setReprendreLocataireActuel(n.index,e),onSetModulePrecis:t[5]||=e=>r.draft.setModulePrecis(n.index,e)},null,8,[`class`,`patrimoine`,`cible-mode`,`reclamant-modules`,`reclamant-type`,`contrat-reclamant`,`contrat-cible`,`module-precis`,`affiche-case-contrat-reclamant`,`locataire-actuel-option`,`onChangeMode`,`onSelectModule`,`onSelectContrat`,`onToggleContratReclamant`])]),_:1},8,[`loading`])):(0,i.createCommentVNode)(``,!0)],2)}var Zn=N(Wn,[[`render`,Xn]]),Qn={name:`EtapeReclamantCibleBlock`,components:{SectionComponent:P,ProvenanceSelecteurBlock:_t,ReclamantRechercheBlock:Bt,ReclamantSelecteurBlock:Xt,LigneCibleBlock:Zn},setup(){return{draft:M(),options:q()}}},$n={class:`d-flex flex-column gap-4`},er={key:2,class:`row g-3`},tr={class:`col-12 col-md-6`},nr={class:`col-12 col-md-6`};function rr(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`provenance-selecteur-block`),c=(0,i.resolveComponent)(`reclamant-recherche-block`),l=(0,i.resolveComponent)(`reclamant-selecteur-block`),u=(0,i.resolveComponent)(`section-component`),d=(0,i.resolveComponent)(`ligne-cible-block`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,$n,[(0,i.createVNode)(u,{titre:`Réclamant`,aide:`La personne à l’origine de la sollicitation : locataire, tiers, fournisseur…`},{default:(0,i.withCtx)(()=>[e.$slots.reclamant?((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:0},[(0,i.createVNode)(s),(0,i.renderSlot)(e.$slots,`reclamant`,{reclamant:r.draft.reclamantSelectionne,select:r.draft.selectReclamant})],64)):r.options.rechercheReclamant?((0,i.openBlock)(),(0,i.createBlock)(c,{key:1},{"avant-categorie":(0,i.withCtx)(()=>[(0,i.createVNode)(s)]),_:1})):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,er,[(0,i.createElementVNode)(`div`,tr,[(0,i.createVNode)(s)]),(0,i.createElementVNode)(`div`,nr,[(0,i.createVNode)(l)])]))]),_:3}),r.draft.reclamantSelectionne?((0,i.openBlock)(),(0,i.createBlock)(u,{key:0,titre:`Cible`,aide:r.draft.draft.reclamant.type===`D`?`Une demande de logement se cible elle-même`:`Ce sur quoi porte la sollicitation : un contrat ou un élément du patrimoine`},{default:(0,i.withCtx)(()=>[(0,i.createVNode)(d,{index:0})]),_:1},8,[`aide`])):(0,i.createCommentVNode)(``,!0)])}var ir=N(Qn,[[`render`,rr]]),ar={name:`SeparateurComponent`,props:{texte:{type:String,required:!0}}},or={class:`d-flex align-items-center gap-2 text-muted fs-7`};function sr(e,t,n,r,a,o){return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,or,[t[0]||=(0,i.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`},null,-1),(0,i.createElementVNode)(`span`,null,(0,i.toDisplayString)(n.texte),1),t[1]||=(0,i.createElementVNode)(`hr`,{class:`flex-grow-1 my-0`},null,-1)])}var cr=N(ar,[[`render`,sr]]),lr={reclamant:{icon:`user`,label:`Réclamant`},cible:{icon:`location-dot`,label:`Cible`},motif:{icon:`tag`,label:`Motif`}},ur={name:`RecapBlock`,props:{index:{type:Number,default:0},champs:{type:Array,default:()=>[`reclamant`,`cible`,`motif`],validator:e=>e.every(e=>lr[e])}},setup(){return{draft:M(),data:K()}},computed:{ligne(){return this.draft.draft.lignes[this.index]},valeurs(){return{reclamant:this.reclamant,cible:this.ligne?this.draft.cibleResume(this.ligne):null,motif:this.motif}},reclamant(){let e=this.draft.reclamantSelectionne?.libelle;if(!e)return null;let t=this.data.cache.provenances?.find(e=>e.id===this.draft.draft.provenance)?.libelle;return t?`${e} · via ${t}`:e},motif(){let e=this.ligne;return e?.idMotif?this.index>0?e.libelle??this.data.motifLibelle(e.idMotif):[this.data.categorieLibelle(e.idCategorie),this.data.typeLibelle(e.idType),this.data.natureLibelle(e.idNature),this.data.motifLibelle(e.idMotif)].filter(Boolean).join(` › `):null},items(){return this.champs.map(e=>({champ:e,...lr[e],valeur:this.valeurs[e]})).filter(e=>e.valeur)}}},dr={class:`alert alert-light border py-2 px-3 mb-0 d-flex flex-column gap-1`},fr={class:`text-muted text-uppercase fw-semibold text-nowrap`},pr={class:`min-w-0`};function mr(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,dr,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.items,e=>((0,i.openBlock)(),(0,i.createElementBlock)(`span`,{key:e.champ,class:`fs-7 d-flex align-items-start gap-2`},[(0,i.createVNode)(s,{icon:e.icon,class:`text-primary mt-1`,"fixed-width":``},null,8,[`icon`]),(0,i.createElementVNode)(`span`,fr,(0,i.toDisplayString)(e.label),1),(0,i.createElementVNode)(`span`,pr,(0,i.toDisplayString)(e.valeur),1)]))),128))])}var hr=N(ur,[[`render`,mr]]),gr={name:`MotifChaineComponent`,props:{chaine:{type:Array,default:()=>[]},readonly:{type:Boolean,default:!1}},emits:[`retirer`]},_r={class:`d-flex flex-wrap align-items-center gap-2`},vr=[`onClick`],yr={key:2,class:`badge rounded-pill bg-primary d-inline-flex align-items-center gap-2`};function br(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,_r,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(n.chaine,(t,r)=>((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:t.key},[r>0?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,icon:`chevron-right`,class:`text-muted fs-7`})):(0,i.createCommentVNode)(``,!0),n.readonly?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,yr,[t.icon?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,icon:t.icon,"fixed-width":``},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0),(0,i.createTextVNode)(` `+(0,i.toDisplayString)(t.libelle),1)])):((0,i.openBlock)(),(0,i.createElementBlock)(`button`,{key:1,type:`button`,class:`btn btn-sm btn-primary rounded-pill d-inline-flex align-items-center gap-2`,onClick:n=>e.$emit(`retirer`,t.key)},[t.icon?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,icon:t.icon,"fixed-width":``},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`span`,null,(0,i.toDisplayString)(t.libelle),1),(0,i.createVNode)(s,{icon:`xmark`,class:`fs-7 opacity-75`})],8,vr))],64))),128))])}var xr=N(gr,[[`render`,br]]),X=[{key:`categorie`,titre:`Catégorie`,idKey:`idCategorie`,libelleKey:`categorie`},{key:`type`,titre:`Type`,idKey:`idType`,libelleKey:`type`},{key:`nature`,titre:`Nature`,idKey:`idNature`,libelleKey:`nature`},{key:`motif`,titre:`Motif`,idKey:`idMotif`,libelleKey:`libelle`}],Sr=e=>e.filter(e=>e.selectedId!=null).map(e=>{let t=e.options.find(t=>t.id===e.selectedId);return{key:e.key,libelle:t?.libelle??e.selectedId,icon:t?.icon??null}}),Cr={name:`MotifBubbleBlock`,components:{MotifChaineComponent:xr},props:{niveaux:{type:Array,required:!0}},emits:[`choisir`,`retirer`],computed:{chaine(){return Sr(this.niveaux)},courant(){return this.niveaux.find(e=>e.selectedId==null)??null}}},wr={class:`d-flex flex-column gap-3`},Tr={key:1},Er={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-2`},Dr={class:`row justify-content-around g-3`},Or=[`title`,`onClick`],kr={class:`fs-7 mt-1 lh-sm`},Ar={key:0,class:`col-12 text-muted fs-7`};function jr(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`motif-chaine-component`),c=(0,i.resolveComponent)(`font-awesome-icon`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,wr,[o.chaine.length?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,chaine:o.chaine,onRetirer:t[0]||=t=>e.$emit(`retirer`,t)},null,8,[`chaine`])):(0,i.createCommentVNode)(``,!0),o.courant?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Tr,[(0,i.createElementVNode)(`label`,Er,(0,i.toDisplayString)(o.courant.titre),1),(0,i.createElementVNode)(`div`,Dr,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.courant.options,t=>((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:t.id,class:`col-3 text-center`},[(0,i.createElementVNode)(`button`,{type:`button`,class:`btn btn-lg btn-outline-primary btn-circle d-flex align-items-center justify-content-center mx-auto`,title:t.libelle,onClick:n=>e.$emit(`choisir`,{key:o.courant.key,id:t.id})},[t.icon?((0,i.openBlock)(),(0,i.createBlock)(c,{key:0,icon:t.icon,size:`lg`},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0)],8,Or),(0,i.createElementVNode)(`div`,kr,(0,i.toDisplayString)(t.libelle),1)]))),128)),o.courant.options.length?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Ar,` Aucun choix disponible `))])])):(0,i.createCommentVNode)(``,!0)])}var Mr=N(Cr,[[`render`,jr]]),Nr={categorie:`une catégorie`,type:`un type`,nature:`une nature`},Pr={name:`MotifColonnesBlock`,props:{niveaux:{type:Array,required:!0}},emits:[`choisir`],methods:{article(e){return Nr[e.key]??e.titre.toLowerCase()}}},Fr={class:`row g-0 border rounded overflow-hidden`},Ir={class:`d-flex align-items-center justify-content-between bg-light border-bottom px-2 py-1`},Lr={class:`fs-7 fw-semibold text-muted text-uppercase`},Rr={key:0,class:`badge bg-secondary`},zr={class:`list-group list-group-flush overflow-auto`,style:{"max-height":`260px`}},Br=[`aria-pressed`,`onClick`],Vr={class:`flex-grow-1 lh-sm text-start`},Hr={key:0,class:`text-muted fst-italic p-2`};function Ur(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`font-awesome-icon`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,Fr,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(n.niveaux,(t,r)=>((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:t.key,class:(0,i.normalizeClass)([`col-6 col-md-3 d-flex flex-column`,{"border-start":r>0}])},[(0,i.createElementVNode)(`div`,Ir,[(0,i.createElementVNode)(`span`,Lr,(0,i.toDisplayString)(t.titre),1),t.options.length?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,Rr,(0,i.toDisplayString)(t.options.length),1)):(0,i.createCommentVNode)(``,!0)]),(0,i.createElementVNode)(`div`,zr,[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(t.options,a=>((0,i.openBlock)(),(0,i.createElementBlock)(`button`,{key:a.id,type:`button`,class:(0,i.normalizeClass)([`list-group-item list-group-item-action d-flex align-items-center gap-2 fs-7 px-2 py-1`,{active:a.id===t.selectedId}]),"aria-pressed":a.id===t.selectedId,onClick:n=>e.$emit(`choisir`,{key:t.key,id:a.id})},[a.icon?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,icon:a.icon,"fixed-width":``},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`span`,Vr,(0,i.toDisplayString)(a.libelle),1),r<n.niveaux.length-1?((0,i.openBlock)(),(0,i.createBlock)(s,{key:1,icon:`chevron-right`,class:`opacity-50`})):a.id===t.selectedId?((0,i.openBlock)(),(0,i.createBlock)(s,{key:2,icon:`check`})):(0,i.createCommentVNode)(``,!0)],10,Br))),128))]),t.options.length?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`small`,Hr,(0,i.toDisplayString)(r>0?`← Choisir ${o.article(n.niveaux[r-1])}`:`Aucun choix disponible`),1))],2))),128))])}var Wr=N(Pr,[[`render`,Ur]]),Gr={name:`EtapeMotifBlock`,components:{AmsomOverlay:r.AmsomOverlay,AmsomAutocomplete:s.AmsomAutocomplete,SectionComponent:P,SeparateurComponent:cr,RecapBlock:hr,MotifChaineComponent:xr,MotifBubbleBlock:Mr,MotifColonnesBlock:Wr,LigneCibleBlock:Zn},setup(){return{draft:M(),data:K(),options:q()}},data(){return{iconsReady:!1}},computed:{mainLigne(){return this.draft.lignePrincipale},lignesAssociees(){return this.draft.lignesAssociees},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(){return this.activeMotifs.filter(e=>this.options.estMotifPropose(e))},motifBloque(){return this.options.motifNonProposeMode===`block`&&!this.options.motifPrincipalPropose},niveaux(){let e={categorie:this.data.categorieIcon,type:this.data.typeIcon,nature:this.data.natureIcon},t=this.allowedMotifs;return X.map((n,r)=>{let i=X[r-1],a=!i||this.mainLigne[i.idKey]!=null?t:[],o=n.key===`motif`?a.map(e=>({id:e.id,libelle:e.libelle,icon:e.icon})):this.distinct(a,n.idKey,n.libelleKey,e[n.key]),s=this.mainLigne[n.idKey];return s!=null&&(t=t.filter(e=>e[n.idKey]===s)),{key:n.key,titre:n.titre,options:o,selectedId:s}})},chaine(){let e=this.mainLigne,t={categorie:this.data.categorieLibelle,type:this.data.typeLibelle,nature:this.data.natureLibelle,motif:this.data.motifLibelle},n={categorie:this.data.categorieIcon,type:this.data.typeIcon,nature:this.data.natureIcon,motif:this.data.motifIcon};return Sr(X.map(r=>{let i=e[r.idKey];return{key:r.key,selectedId:i,options:i==null?[]:[{id:i,libelle:t[r.key](i),icon:n[r.key](i)}]}}))},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})):[]},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:{setNiveau(e,t){({categorie:this.draft.setCategorie,type:this.draft.setType,nature:this.draft.setNature,motif:this.draft.setMotif})[e](t)},choisir({key:e,id:t}){if(this.setNiveau(e,t),this.options.motifSelectionMode!==`columns`)return;let n=X.findIndex(t=>t.key===e)+1;for(;n<X.length;){let e=this.niveaux[n];if(e.selectedId!=null||e.options.length!==1)break;this.setNiveau(e.key,e.options[0].id),n+=1}},retirer(e){this.setNiveau(e,null)},isActive(e){return this.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 F([...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=(I(e)??``).trim();if(!n)return t;let r=n.split(/\s+/);return t.filter(e=>{let t=I(`${e.libelle} ${e.categorie} ${e.type} ${e.nature}`)??``;return r.every(e=>t.includes(e))})},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}}},Kr={key:0,class:`d-flex flex-column gap-4`},qr={key:0,class:`alert alert-info d-flex align-items-start gap-2 py-2 px-3 mb-0 fs-7`},Jr={key:1,class:`alert alert-warning d-flex align-items-start gap-2 py-2 px-3 mb-0 fs-7`},Yr={class:`d-flex align-items-center gap-2`},Xr={class:`min-w-0`},Zr={class:`fw-medium text-truncate`},Qr={class:`text-muted d-block text-truncate`},$r=[`id`,`checked`,`disabled`,`onChange`],ei=[`for`],ti={key:0,class:`alert alert-warning d-flex align-items-start gap-2 py-2 px-3 mb-0 fs-7`};function ni(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`recap-block`),c=(0,i.resolveComponent)(`font-awesome-icon`),l=(0,i.resolveComponent)(`motif-chaine-component`),u=(0,i.resolveComponent)(`amsom-autocomplete`),d=(0,i.resolveComponent)(`separateur-component`),f=(0,i.resolveComponent)(`motif-colonnes-block`),p=(0,i.resolveComponent)(`motif-bubble-block`),m=(0,i.resolveComponent)(`section-component`),h=(0,i.resolveComponent)(`ligne-cible-block`),g=(0,i.resolveComponent)(`amsom-overlay`);return(0,i.openBlock)(),(0,i.createBlock)(g,{loading:r.data.isLoading&&!r.data.cache.motifs||!a.iconsReady},{default:(0,i.withCtx)(()=>[a.iconsReady?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Kr,[(0,i.createVNode)(s,{champs:[`reclamant`,`cible`]}),(0,i.createVNode)(m,{titre:`Motif`},{default:(0,i.withCtx)(()=>[r.options.motifRetire?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,qr,[(0,i.createVNode)(c,{icon:`circle-info`,class:`mt-1`}),(0,i.createElementVNode)(`span`,null,[(0,i.createTextVNode)(` Le motif « `+(0,i.toDisplayString)(r.options.motifRetire.libelle)+` » a été retiré `,1),r.options.motifRetire.associes.length?((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:0},[(0,i.createTextVNode)(` avec ses motifs associés (`+(0,i.toDisplayString)(r.options.motifRetire.associes.join(`, `))+`) `,1)],64)):(0,i.createCommentVNode)(``,!0),t[1]||=(0,i.createTextVNode)(` : il n’est pas proposé pour ce réclamant. `,-1)])])):(0,i.createCommentVNode)(``,!0),o.motifBloque?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Jr,[(0,i.createVNode)(c,{icon:`circle-exclamation`,class:`mt-1`}),(0,i.createElementVNode)(`span`,null,` Le motif « `+(0,i.toDisplayString)(r.data.motifLibelle(o.mainLigne.idMotif))+` » n’est pas proposé pour ce réclamant : choisissez-en un autre pour continuer. `,1)])):(0,i.createCommentVNode)(``,!0),o.motifFige?((0,i.openBlock)(),(0,i.createBlock)(l,{key:2,chaine:o.chaine,readonly:``},null,8,[`chaine`])):((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:3},[(0,i.createElementVNode)(`div`,null,[t[2]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},[(0,i.createTextVNode)(` Rechercher un motif`),(0,i.createElementVNode)(`span`,{class:`ms-1 text-danger`},`*`)],-1),(0,i.createVNode)(u,{modelValue:o.motifRecherche,"onUpdate:modelValue":t[0]||=e=>o.motifRecherche=e,items:o.allowedMotifs,"get-id":e=>e?.id??null,"get-input-libelle":e=>e?.libelle??``,"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,i.withCtx)(e=>[(0,i.createElementVNode)(`div`,Yr,[e?.icon?((0,i.openBlock)(),(0,i.createBlock)(c,{key:0,icon:e.icon,class:`text-primary`,"fixed-width":``},null,8,[`icon`])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`div`,Xr,[(0,i.createElementVNode)(`div`,Zr,(0,i.toDisplayString)(e?.libelle),1),(0,i.createElementVNode)(`small`,Qr,(0,i.toDisplayString)(e?.categorie)+` › `+(0,i.toDisplayString)(e?.type)+` › `+(0,i.toDisplayString)(e?.nature),1)])])]),_:1},8,[`modelValue`,`items`,`get-id`,`get-input-libelle`,`get-input-libelle-from-id`,`filtering-function`])]),(0,i.createVNode)(d,{texte:`ou sélection guidée`}),r.options.motifSelectionMode===`columns`?((0,i.openBlock)(),(0,i.createBlock)(f,{key:0,niveaux:o.niveaux,onChoisir:o.choisir},null,8,[`niveaux`,`onChoisir`])):((0,i.openBlock)(),(0,i.createBlock)(p,{key:1,niveaux:o.niveaux,onChoisir:o.choisir,onRetirer:o.retirer},null,8,[`niveaux`,`onChoisir`,`onRetirer`]))],64))]),_:1}),o.motifsAssocies.length?((0,i.openBlock)(),(0,i.createBlock)(m,{key:0,titre:`Motifs complémentaires`},{default:(0,i.withCtx)(()=>[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.motifsAssocies,e=>((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:e.idMotif,class:`form-check form-switch`},[(0,i.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,$r),(0,i.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`assoc-${e.idMotif}`},(0,i.toDisplayString)(e.libelle)+` ? `,9,ei)]))),128)),r.draft.ciblesAssocieesReinitialisees&&r.draft.draft.reclamant.type!==`D`?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,ti,[(0,i.createVNode)(c,{icon:`circle-exclamation`,class:`mt-1`}),(0,i.createElementVNode)(`span`,null,` Le réclamant a changé : `+(0,i.toDisplayString)(r.draft.ciblesAssocieesReinitialisees>1?`${r.draft.ciblesAssocieesReinitialisees} motifs associés reprennent`:`un motif associé reprend`)+` la cible de la ligne principale. Vérifiez-la ci-dessous si elle doit être différente. `,1)])):(0,i.createCommentVNode)(``,!0),o.lignesAssociees.length&&r.draft.draft.reclamant.type!==`D`?((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:1},[(0,i.createVNode)(d,{texte:`Cible des autres motifs`}),((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.lignesAssociees,(e,t)=>((0,i.openBlock)(),(0,i.createBlock)(h,{key:e.idMotif,index:t+1},null,8,[`index`]))),128))],64)):(0,i.createCommentVNode)(``,!0)]),_:1})):(0,i.createCommentVNode)(``,!0)])):(0,i.createCommentVNode)(``,!0)]),_:1},8,[`loading`])}var ri=N(Gr,[[`render`,ni]]),ii={name:`LigneDocumentBlock`,components:{AmsomUploadFile:d.AmsomUploadFile},props:{index:{type:Number,required:!0},fichier:{type:[Object,Array],default:null},readonly:{type:Boolean,default:!1}},emits:[`update`]};function ai(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`amsom-upload-file`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,null,[t[1]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},`Document`,-1),(0,i.createVNode)(s,{"model-value":n.fichier,renameable:``,"output-format":`object`,name:`cresol-creation-ged-${n.index}`,"merge-pdfs":``,"read-only":n.readonly,"onUpdate:modelValue":t[0]||=t=>e.$emit(`update`,t)},null,8,[`model-value`,`name`,`read-only`])])}var oi=N(ii,[[`render`,ai]]),si=4e3,ci={name:`LigneDetailBlock`,components:{AmsomAutocomplete:s.AmsomAutocomplete,AmsomTextarea:u.AmsomTextarea,LigneDocumentBlock:oi},props:{index:{type:Number,required:!0}},setup(){return{draft:M(),data:K()}},computed:{descriptionMaxLength:()=>si,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}},mounted(){this.isPrincipale&&this.$refs.description?.$el.querySelector(`textarea`)?.focus()},methods:{timestampToDateInput:vt,dateInputToTimestamp:yt,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=(I(e)??``).trim();return n?t.filter(e=>(I(`${e.prenom} ${e.nom} ${e.service}`)??``).includes(n)):t}}},li={class:`d-flex flex-column gap-2`},ui={class:`d-flex align-items-center gap-2 mb-1`},di={class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-0`},fi={key:0,class:`ms-1 text-danger`},pi={key:0,class:`form-check form-switch mb-0`},mi=[`id`,`checked`,`disabled`],hi=[`for`],gi=[`rows`,`value`],_i={class:`row g-3`},vi={class:`col-6`},yi={class:`d-flex align-items-center gap-2 mb-1`},bi={key:0,class:`form-check form-switch mb-0`},xi=[`id`,`checked`,`disabled`],Si=[`for`],Ci=[`value`],wi=[`value`],Ti=[`value`],Ei={class:`min-w-0`},Di={class:`fw-medium text-truncate`},Oi={key:0,class:`text-muted d-block`},ki={key:2,class:`text-muted`},Ai={class:`col-12 col-md-6`};function ji(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`amsom-textarea`),c=(0,i.resolveComponent)(`amsom-autocomplete`),l=(0,i.resolveComponent)(`ligne-document-block`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,li,[(0,i.createElementVNode)(`div`,null,[(0,i.createElementVNode)(`div`,ui,[(0,i.createElementVNode)(`label`,di,[t[6]||=(0,i.createTextVNode)(` Description`,-1),o.isPrincipale?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,fi,`*`)):(0,i.createCommentVNode)(``,!0)]),o.isPrincipale?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,pi,[(0,i.createElementVNode)(`input`,{id:`memedetail-${o.ligne.idMotif}`,class:`form-check-input`,type:`checkbox`,checked:o.ligne.description==null,disabled:r.draft.isReadonly(`description`),onChange:t[0]||=e=>r.draft.toggleDescriptionOverride(n.index)},null,40,mi),(0,i.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`memedetail-${o.ligne.idMotif}`},` Même description `,8,hi)]))]),!r.draft.isReadonly(`description`)&&(o.isPrincipale||o.ligne.description!=null)?((0,i.openBlock)(),(0,i.createBlock)(s,{key:0,ref:`description`,"model-value":o.ligne.description,"input-size":`sm`,rows:o.isPrincipale?7:5,maxlength:o.descriptionMaxLength,placeholder:o.isPrincipale?`Décrivez la sollicitation…`:`Décrivez ce motif…`,"onUpdate:modelValue":t[1]||=e=>r.draft.setDescription(n.index,e)},null,8,[`model-value`,`rows`,`maxlength`,`placeholder`])):((0,i.openBlock)(),(0,i.createElementBlock)(`textarea`,{key:1,class:`form-control form-control-sm`,disabled:``,rows:o.isPrincipale?7:5,value:(o.ligne.description??o.lignePrincipale.description)||``},null,8,gi))]),(0,i.createElementVNode)(`div`,_i,[(0,i.createElementVNode)(`div`,vi,[(0,i.createElementVNode)(`div`,null,[(0,i.createElementVNode)(`div`,yi,[t[7]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-0`},` Date des faits `,-1),o.isPrincipale?(0,i.createCommentVNode)(``,!0):((0,i.openBlock)(),(0,i.createElementBlock)(`div`,bi,[(0,i.createElementVNode)(`input`,{id:`memedate-${o.ligne.idMotif}`,class:`form-check-input`,type:`checkbox`,checked:!o.ligne.dateFaitsOverride,disabled:r.draft.isReadonly(`dateFaits`),onChange:t[2]||=e=>r.draft.toggleDateFaitsOverride(n.index)},null,40,xi),(0,i.createElementVNode)(`label`,{class:`form-check-label fs-7`,for:`memedate-${o.ligne.idMotif}`},` Même date `,8,Si)]))]),!r.draft.isReadonly(`dateFaits`)&&(o.isPrincipale||o.ligne.dateFaitsOverride)?((0,i.openBlock)(),(0,i.createElementBlock)(`input`,{key:0,value:o.timestampToDateInput(o.ligne.dateFaits),type:`date`,class:`form-control form-control-sm`,onInput:t[3]||=e=>r.draft.setDateFaits(n.index,o.dateInputToTimestamp(e.target.value))},null,40,Ci)):((0,i.openBlock)(),(0,i.createElementBlock)(`input`,{key:1,value:o.timestampToDateInput(o.dateFaits),type:`date`,class:`form-control form-control-sm`,disabled:``},null,8,wi))]),(0,i.createElementVNode)(`div`,null,[t[8]||=(0,i.createElementVNode)(`label`,{class:`form-label fs-7 fw-semibold text-muted text-uppercase mb-1`},` Responsable `,-1),r.draft.isReadonly(`responsable`)?((0,i.openBlock)(),(0,i.createElementBlock)(`input`,{key:0,class:`form-control form-control-sm`,disabled:``,value:o.responsableLibelle(o.ligne.responsable)||`Déterminé automatiquement`},null,8,Ti)):((0,i.openBlock)(),(0,i.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=>r.draft.setResponsable(n.index,e??null)},{options:(0,i.withCtx)(e=>[(0,i.createElementVNode)(`div`,Ei,[(0,i.createElementVNode)(`div`,Di,(0,i.toDisplayString)(e?.prenom)+` `+(0,i.toDisplayString)(e?.nom),1),e?.service?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,Oi,(0,i.toDisplayString)(e.service),1)):(0,i.createCommentVNode)(``,!0)])]),_:1},8,[`model-value`,`items`,`get-id`,`get-input-libelle`,`filtering-function`])),o.isPrincipale&&!o.ligne.responsable&&!r.draft.isReadonly(`responsable`)?((0,i.openBlock)(),(0,i.createElementBlock)(`small`,ki,` Aucun paramétrage trouvé : le responsable sera déterminé automatiquement. `)):(0,i.createCommentVNode)(``,!0)])]),(0,i.createElementVNode)(`div`,Ai,[(0,i.createVNode)(l,{index:n.index,fichier:o.ligne.fichier,readonly:r.draft.isReadonly(`fichier`),onUpdate:t[5]||=e=>r.draft.setFichier(n.index,e)},null,8,[`index`,`fichier`,`readonly`])])])])}var Mi=N(ci,[[`render`,ji]]),Ni={name:`EtapeDetailsBlock`,components:{AmsomOverlay:r.AmsomOverlay,LigneDetailBlock:Mi,RecapBlock:hr,SectionComponent:P},setup(){return{draft:M(),data:K()}},computed:{lignePrincipale(){return this.draft.lignePrincipale},lignesAssociees(){return this.draft.lignesAssociees},collaborateurs(){return(this.data.cache.collaborateurs??[]).filter(e=>e.actif!==!1)}},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)}}}},Pi={class:`d-flex flex-column gap-4`},Fi={class:`text-muted d-flex align-items-start gap-2`};function Ii(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`recap-block`),c=(0,i.resolveComponent)(`font-awesome-icon`),l=(0,i.resolveComponent)(`ligne-detail-block`),u=(0,i.resolveComponent)(`section-component`),d=(0,i.resolveComponent)(`amsom-overlay`);return(0,i.openBlock)(),(0,i.createBlock)(d,{loading:r.data.isLoading&&!r.data.cache.collaborateurs},{default:(0,i.withCtx)(()=>[(0,i.createElementVNode)(`div`,Pi,[(0,i.createVNode)(s),(0,i.createElementVNode)(`small`,Fi,[(0,i.createVNode)(c,{icon:`circle-info`,class:`mt-1`}),t[0]||=(0,i.createTextVNode)(` Rappel RGPD : ne saisissez que les informations nécessaires au traitement de la sollicitation, aucune donnée sensible (santé, opinions, situation judiciaire…) ni appréciation personnelle sur le réclamant. `,-1)]),(0,i.createVNode)(u,{titre:o.lignesAssociees.length?`Motif principal`:`Détails`},{default:(0,i.withCtx)(()=>[(0,i.createVNode)(l,{index:0})]),_:1},8,[`titre`]),o.lignesAssociees.length?((0,i.openBlock)(),(0,i.createBlock)(u,{key:0,titre:`Détail des autres motifs`},{default:(0,i.withCtx)(()=>[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(o.lignesAssociees,(e,t)=>((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:e.idMotif,class:`border rounded p-2 d-flex flex-column gap-2`},[(0,i.createVNode)(s,{index:t+1,champs:[`motif`,`cible`]},null,8,[`index`]),(0,i.createVNode)(l,{index:t+1},null,8,[`index`])]))),128))]),_:1})):(0,i.createCommentVNode)(``,!0)])]),_:1},8,[`loading`])}var Li=N(Ni,[[`render`,Ii]]),Ri=[{key:`reclamantCible`,label:`Réclamant et cible`,icon:`user`},{key:`motif`,label:`Motif`,icon:`tag`},{key:`details`,label:`Détails`,icon:`info`}],zi={name:`StepperBlock`,components:{AmsomHorizontalStepper:o.default,AmsomOverlay:r.AmsomOverlay,EtapeReclamantCibleBlock:ir,EtapeMotifBlock:ri,EtapeDetailsBlock:Li},props:{step:{type:Number,default:1},creating:{type:Boolean,default:!1}},emits:[`update:step`,`stepChange`,`submit`],setup(){return{draft:M(),data:K(),options:q()}},computed:{steps:()=>Ri,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},provenanceValid(){return this.options.provenances.some(e=>e.id===this.draft.draft.provenance)},motifPropose(){return this.options.motifNonProposeMode!==`block`||this.options.motifPrincipalPropose},canGoNext(){return this.gatePassed(this.currentKey)},canCreer(){return!!this.lignePrincipale.idMotif&&this.motifPropose&&this.provenanceValid&&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===`reclamantCible`?this.draft.reclamantSelectionne!=null&&this.provenanceValid&&this.draft.ligneCibleValid(0):e!==`motif`||!!this.lignePrincipale.idMotif&&this.motifPropose&&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===`motif`&&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}))}}},Bi={class:`d-flex flex-column gap-3`},Vi={key:0,class:`w-100 fs-6 fw-medium my-3 alert alert-info`,style:{"white-space":`pre-line`}},Hi={style:{"min-height":`260px`}},Ui={class:`d-flex justify-content-between`},Wi={key:1},Gi=[`disabled`],Ki=[`disabled`];function qi(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`amsom-horizontal-stepper`),c=(0,i.resolveComponent)(`font-awesome-icon`),l=(0,i.resolveComponent)(`etape-reclamant-cible-block`),u=(0,i.resolveComponent)(`etape-motif-block`),d=(0,i.resolveComponent)(`etape-details-block`),f=(0,i.resolveComponent)(`amsom-overlay`);return(0,i.openBlock)(),(0,i.createBlock)(f,{loading:n.creating},{default:(0,i.withCtx)(()=>[(0,i.createElementVNode)(`div`,Bi,[(0,i.createVNode)(s,{steps:o.stepperSteps,size:`md`,onStepClick:o.onStepClick},null,8,[`steps`,`onStepClick`]),o.aideMotif?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,Vi,[(0,i.createVNode)(c,{icon:`circle-info`,class:`text-info-emphasis me-2`}),(0,i.createElementVNode)(`span`,null,(0,i.toDisplayString)(o.aideMotif),1)])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`div`,Hi,[o.currentKey===`reclamantCible`?((0,i.openBlock)(),(0,i.createBlock)(l,{key:0},(0,i.createSlots)({_:2},[e.$slots.reclamant?{name:`reclamant`,fn:(0,i.withCtx)(t=>[(0,i.renderSlot)(e.$slots,`reclamant`,(0,i.normalizeProps)((0,i.guardReactiveProps)(t)))]),key:`0`}:void 0]),1024)):o.currentKey===`motif`?((0,i.openBlock)(),(0,i.createBlock)(u,{key:1})):o.currentKey===`details`?((0,i.openBlock)(),(0,i.createBlock)(d,{key:2})):(0,i.createCommentVNode)(``,!0)]),(0,i.createElementVNode)(`div`,Ui,[n.step>1?((0,i.openBlock)(),(0,i.createElementBlock)(`button`,{key:0,class:`btn btn-sm btn-outline-secondary`,onClick:t[0]||=(...e)=>o.goPrevious&&o.goPrevious(...e)},[(0,i.createVNode)(c,{icon:`chevron-left`,class:`me-1`}),t[3]||=(0,i.createTextVNode)(` Précédent `,-1)])):((0,i.openBlock)(),(0,i.createElementBlock)(`span`,Wi)),n.step<o.steps.length?((0,i.openBlock)(),(0,i.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,i.createTextVNode)(` Suivant `,-1),(0,i.createVNode)(c,{icon:`chevron-right`,class:`ms-1`})],8,Gi)):((0,i.openBlock)(),(0,i.createElementBlock)(`button`,{key:3,class:`btn btn-sm btn-success`,disabled:!o.canCreer||n.creating,onClick:t[2]||=t=>e.$emit(`submit`)},[(0,i.createVNode)(c,{icon:`check`,class:`me-1`}),t[5]||=(0,i.createTextVNode)(` Créer la sollicitation `,-1)],8,Ki))])])]),_:3},8,[`loading`])}var Ji=N(zi,[[`render`,qi]]),Yi=(e,{signal:t,baseUrl:n}={})=>Ve(`/v2/cresol/creer_sollicitation`,e,{signal:t,baseUrl:n}),Xi=({idSollicitation:e,pj:t},{signal:n,baseUrl:r}={})=>Ve(`/v2/cresol/upload_sollicitation_ged`,{idSollicitation:e,pj:t},{signal:n,baseUrl:r}),Z={modelValue:{type:Object,default:null},reclamants:{type:Array,default:()=>[]},reclamantMode:{type:String,default:`select`,validator:e=>[`select`,`switch`,`autocomplete`,`recherche`].includes(e)},motifSelectionMode:{type:String,default:`bubble`,validator:e=>[`bubble`,`columns`].includes(e)},motifNonProposeMode:{type:String,default:`clear`,validator:e=>[`clear`,`block`,`ignore`].includes(e)},typesReclamant:{type:Array,default:null,validator:e=>e.every(e=>w.includes(e))},typesReclamantExclus:{type:Array,default:()=>[],validator:e=>e.every(e=>w.includes(e))},provenances:{type:Array,default:()=>[...te]},provenancesExclues:{type:Array,default:()=>[]},readonly:{type:[Boolean,Array],default:!1,validator:e=>typeof e==`boolean`||e.every(e=>A.includes(e))},modules:{type:Array,default:null},idModuleCibleDefaut:{type:[String,Number],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}},Zi=Object.keys(Z),Q=[`update:modelValue`,`reclamantChange`,`motifChange`,`stepChange`,`beforeCreate`,`created`,`createError`,`error`],Qi={name:`CreerSollicitationForm`,components:{AsideBlock:xe,StepperBlock:Ji},props:{...Z},emits:[...Q],setup(e,{emit:t}){let n=e=>t(`error`,e),r={baseUrl:(0,i.toRef)(e,`baseUrl`)},a=ct(st({onError:n,...r})),o=(0,i.ref)(null),s=(0,i.ref)(!1),c=(0,i.computed)(()=>o.value??e.modules??[]),l=(0,i.computed)(()=>e.reclamantMode===`recherche`),u=me(pe({reclamants:(0,i.computed)(()=>l.value?[]:e.reclamants),modules:c,idModulePrefere:(0,i.computed)(()=>e.idModuleCibleDefaut??e.idModule),readonly:(0,i.toRef)(e,`readonly`)})),d=t=>{if(!t||t.estDesactive)return!1;let n=e.nomenclatureFilter;return typeof n!=`function`||n(t,{reclamant:u.reclamantSelectionne})},f=(0,i.computed)(()=>{let e=u.lignePrincipale.idMotif;if(e==null||u.isReadonly(`motif`))return!0;let t=a.cache.motifs?.find(t=>t.id===e);return!a.cache.motifs||d(t)}),p=(0,i.ref)(null);return ut((0,i.reactive)({nomenclatureFilter:(0,i.toRef)(e,`nomenclatureFilter`),estMotifPropose:d,motifPrincipalPropose:f,motifNonProposeMode:(0,i.toRef)(e,`motifNonProposeMode`),motifRetire:p,reclamantMode:(0,i.toRef)(e,`reclamantMode`),rechercheReclamant:l,motifSelectionMode:(0,i.toRef)(e,`motifSelectionMode`),typesReclamant:(0,i.computed)(()=>(e.typesReclamant??w).filter(t=>!e.typesReclamantExclus.includes(t))),provenances:(0,i.computed)(()=>{let t=a.cache.provenances??[];return(e.provenances??t.map(e=>e.id)).filter(t=>!e.provenancesExclues.includes(t)).flatMap(e=>{let n=t.find(t=>t.id===e);return n?[{...n,icon:ee(e)}]:[]})}),modulesReclamant:c,repriseReclamant:s,...r})),{data:a,draft:u,modulesCharges:o,repriseReclamant:s,rechercheReclamant:l,motifPrincipalPropose:f,motifRetire:p,onError:n}},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.data.loadNomenclature(),this.data.loadProvenances(),this.draft.reset(this.modelValue),this.rechercheReclamant&&await this.reprendreReclamantFourni(),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(`motifPrincipalPropose`,this.retirerMotifNonPropose,{immediate:!0}),this.$watch(()=>this.draft.lignePrincipale.idMotif,e=>{e!=null&&(this.motifRetire=null)}),this.$watch(()=>JSON.stringify(this.motifChoisi),()=>this.$emit(`motifChange`,this.motifChoisi)),await this.chargerModulesReclamant(e,e)&&this.draft.prefillCiblePrincipale(),this.draft.libererCibleFournie()},methods:{retirerMotifNonPropose(e){if(e||this.motifNonProposeMode!==`clear`)return;let t=this.draft.lignePrincipale.idMotif,n={libelle:this.data.motifLibelle(t),associes:this.draft.lignesAssociees.map(e=>e.libelle??this.data.motifLibelle(e.idMotif))};this.draft.setCategorie(null),this.motifRetire=n},async reprendreReclamantFourni(){let{type:e,id:t}=this.draft.draft.reclamant;if(!e||t==null)return;let n=n=>n.type===e&&String(n.id)===String(t),[r]=T([e]),i=null;if(r){this.repriseReclamant=!0;try{i=(await this.data.searchReclamants(r,String(t))??[]).find(n)??null}catch{}finally{this.repriseReclamant=!1}}n(this.draft.draft.reclamant)&&this.draft.selectReclamant(i??{type:e,id:t,libelle:`${e}/${t}`})},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 Yi(e,this.requestOptions)??[]}catch(t){if(rt(t))return;let n=B(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?Xi({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(B(e))):Promise.resolve(s(`sollicitation introuvable dans la réponse`))});return Promise.all(n)}}},$i={class:`row g-3`},ea={key:0,class:`col-12 col-lg-4`};function ta(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`aside-block`),c=(0,i.resolveComponent)(`stepper-block`);return(0,i.openBlock)(),(0,i.createElementBlock)(`div`,$i,[e.aside?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,ea,[(0,i.renderSlot)(e.$slots,`aside`,{},()=>[(0,i.createVNode)(s,{"nb-similaires":e.nbSimilaires},(0,i.createSlots)({_:2},[e.$slots[`aside-similaires`]?{name:`similaires`,fn:(0,i.withCtx)(t=>[(0,i.renderSlot)(e.$slots,`aside-similaires`,(0,i.normalizeProps)((0,i.guardReactiveProps)(t)))]),key:`0`}:void 0,e.$slots[`aside-evenements`]?{name:`evenements`,fn:(0,i.withCtx)(()=>[(0,i.renderSlot)(e.$slots,`aside-evenements`)]),key:`1`}:void 0]),1032,[`nb-similaires`])])])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`div`,{class:(0,i.normalizeClass)([`col-12`,e.aside?`col-lg-8`:``])},[(0,i.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,i.createSlots)({_:2},[e.$slots.reclamant?{name:`reclamant`,fn:(0,i.withCtx)(t=>[(0,i.renderSlot)(e.$slots,`reclamant`,(0,i.normalizeProps)((0,i.guardReactiveProps)(t)))]),key:`0`}:void 0]),1032,[`step`,`creating`,`onSubmit`])],2)])}var $=N(Qi,[[`render`,ta]]),na={name:`CreerSollicitationModal`,components:{AmsomModal:r.AmsomModal,CreerSollicitationForm:$},props:{...Z,titre:{type:String,default:`Nouvelle sollicitation`},closeOnCreated:{type:Boolean,default:!0}},emits:[...Q,`close`],computed:{formProps(){return Object.fromEntries(Zi.map(e=>[e,this[e]]))},formListeners(){return Object.fromEntries(Q.filter(e=>e!==`created`).map(e=>[e,(...t)=>this.$emit(e,...t)]))}},methods:{onCreated(...e){this.$emit(`created`,...e),this.closeOnCreated&&this.$emit(`close`)}}},ra={class:`fw-medium fs-5`};function ia(e,t,n,r,a,o){let s=(0,i.resolveComponent)(`creer-sollicitation-form`),c=(0,i.resolveComponent)(`amsom-modal`);return(0,i.openBlock)(),(0,i.createBlock)(c,{"close-option":``,size:`xl`,onClose:t[0]||=t=>e.$emit(`close`)},{default:(0,i.withCtx)(()=>[(0,i.createElementVNode)(`span`,ra,(0,i.toDisplayString)(n.titre),1),(0,i.createVNode)(s,(0,i.mergeProps)({class:`pt-3`},o.formProps,(0,i.toHandlers)(o.formListeners),{onCreated:o.onCreated}),(0,i.createSlots)({_:2},[(0,i.renderList)(e.$slots,(t,n)=>({name:n,fn:(0,i.withCtx)(t=>[(0,i.renderSlot)(e.$slots,n,(0,i.normalizeProps)((0,i.guardReactiveProps)(t??{})))])}))]),1040,[`onCreated`])]),_:3})}var aa=N(na,[[`render`,ia]]),oa={CreerSollicitationModal:aa,CreerSollicitationForm:$};e.CIBLE_FIELDS=k,e.CreerSollicitationForm=$,e.CreerSollicitationModal=aa,e.DEFAULT_PROVENANCE_CONTACT=ne,e.PROVENANCES_CONTACT_DEFAUT=te,e.PROVENANCE_CONTACT_ICONS=b,e.READONLY_FIELDS=A,e.cibleOfLigne=ae,e.configureCresol=Ie,e.default=oa,e.getDefaultDraft=j,e.getDefaultLigne=O,e.getDefaultPatrimoine=D,e.resetCresolCache=ot});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amsom-habitat/cresol",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Création de sollicitation (assistant 3 étapes) réutilisable par les outils AMSOM Habitat",
5
5
  "type": "module",
6
6
  "scripts": {