@amsom-habitat/cresol 0.1.0

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