import{a as c,b as h,c as w}from"./chunk-QQHSERQW.js";import{c as l,d as s}from"./chunk-QWKADPWV.js";import{T as d,U as p}from"./chunk-YEFQA5EZ.js";import{b as f}from"./chunk-KNXXDNCS.js";import{O as u,S as i,T as m}from"./chunk-KBLF2WKH.js";import{f as o}from"./chunk-S5EYVFES.js";var U=(()=>{let e=class e{constructor(t,a){this.actionSheetController=t,this.alertController=a,this.translate=m(f),this._camera=w}selectPhotoSource(){return o(this,null,function*(){let t=yield this.actionSheetController.create({header:this.translate.instant("photo.change_header"),buttons:[{text:this.translate.instant("avatar_selector.take_photo"),icon:"camera-outline",data:{action:"camera"}},{text:this.translate.instant("photo.gallery_btn"),icon:"images-outline",data:{action:"gallery"}},{text:this.translate.instant("photo.defaults_btn"),icon:"person-outline",data:{action:"default"}},{text:this.translate.instant("common.cancel"),icon:"close",role:"cancel"}]});yield t.present();let{data:a}=yield t.onDidDismiss();if(!a?.action)return null;try{switch(a.action){case"camera":return yield this.takePhoto();case"gallery":return yield this.selectFromGallery();case"default":return yield this.selectDefaultAvatar();default:return null}}catch(r){throw console.error("Erreur lors de la s\xE9lection de photo:",r),r}})}takePhoto(){return o(this,null,function*(){try{let t=yield this._camera.getPhoto({quality:90,allowEditing:!1,resultType:h.DataUrl,source:c.Camera,width:600,height:600});if(t.dataUrl)return t.dataUrl;throw new Error("Impossible de capturer la photo")}catch(t){throw console.error("Erreur lors de la prise de photo:",t),t}})}selectFromGallery(){return o(this,null,function*(){try{let t=yield this._camera.getPhoto({quality:90,allowEditing:!1,resultType:h.DataUrl,source:c.Photos,width:600,height:600});if(t.dataUrl)return t.dataUrl;throw new Error("Impossible de s\xE9lectionner la photo")}catch(t){throw console.error("Erreur lors de la s\xE9lection de photo:",t),t}})}selectDefaultAvatar(){return o(this,null,function*(){let t=yield this.alertController.create({header:this.translate.instant("photo.avatar_header"),message:this.translate.instant("photo.avatar_message"),inputs:l.map((r,y)=>({name:"avatar",type:"radio",label:`Avatar ${y+1}`,value:r,checked:r===s})),buttons:[{text:this.translate.instant("common.cancel"),role:"cancel"},{text:this.translate.instant("common.confirm"),handler:r=>r}]});yield t.present();let{data:a}=yield t.onDidDismiss();return a||s})}getDefaultAvatar(){return s}getDefaultAvatars(){return l.map((t,a)=>({url:t,isDefault:!0,name:`Avatar ${a+1}`}))}isValidPhotoUrl(t){return t?t.startsWith("assets/")||t.startsWith("file://")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("data:"):!1}};e.\u0275fac=function(a){return new(a||e)(i(d),i(p))},e.\u0275prov=u({token:e,factory:e.\u0275fac,providedIn:"root"});let n=e;return n})();export{U as a};
