1import{a as $}from"./chunk-Q2GT5GOT.js";import{a as j}from"./chunk-Z27RM62R.js";import{a as z}from"./chunk-6JT3DWVC.js";import{a as F}from"./chunk-K27K6AWE.js";import"./chunk-ZDT2AJFA.js";import{h as R,j as V}from"./chunk-HR6WCQUD.js";import"./chunk-775PCSDQ.js";import{$ as _,Ia as P,Ib as U,Jb as I,U as h,Ya as u,Z as C,Za as f,_ as y,_a as A,aa as M,ab as k,bb as S,cb as x,db as n,eb as i,fb as p,gc as D,ha as c,ib as w,jb as g,kb as l,lc as E,nc as L,tb as s,ua as O,ub as b,vb as v,xb as T,ya as a}from"./chunk-C6BF5WAC.js";function N(r,e){if(r&1&&(n(0,"p",12)(1,"span",16),s(2),i(),n(3,"span",17),s(4),i(),n(5,"span",18),s(6),i()()),r&2){let t=l();a(2),b(t.getUserFullName()),a(2),v("(",t.userData().email,")"),a(2),v("ID: ",t.userData().id)}}function H(r,e){if(r&1&&(n(0,"span",14),s(1),i()),r&2){let t=l();a(),v("",t.totalAdverts()," listing(s)")}}function G(r,e){r&1&&(n(0,"div",15),p(1,"div",19),n(2,"p"),s(3,"Loading listings..."),i()())}function q(r,e){if(r&1&&(n(0,"p",31),s(1),i()),r&2){let t=l().$implicit;a(),T("\u{1F4CD} ",t.region,"",t.region&&t.country?", ":"","",t.country)}}function J(r,e){if(r&1){let t=w();n(0,"herdspace-tooltip",43)(1,"button",50),g("click",function(){C(t);let d=l().$implicit,m=l(3);return y(m.onReactivateAdvert(d))}),_(),n(2,"svg",37),p(3,"polyline",51)(4,"polyline",52)(5,"path",53)(6,"path",54),i()()()}if(r&2){let t=l().$implicit,o=l(3);a(),x("disabled",o.updatingAdvertId()===t.id)}}function Y(r,e){if(r&1){let t=w();n(0,"div",22)(1,"div",23),p(2,"img",24),n(3,"span",25),s(4),i(),n(5,"span",26),s(6),U(7,"uppercase"),i()(),n(8,"div",27)(9,"h3",28),s(10),i(),n(11,"div",29)(12,"p",30),s(13),i(),u(14,q,2,3,"p",31),n(15,"p",32),s(16),i(),n(17,"p",33),s(18),i()(),n(19,"div",34)(20,"herdspace-tooltip",35)(21,"button",36),g("click",function(){let d=C(t).$implicit,m=l(3);return y(m.onViewAdvert(d))}),_(),n(22,"svg",37),p(23,"path",38)(24,"circle",39),i()()(),M(),n(25,"herdspace-tooltip",40)(26,"button",41),g("click",function(){let d=C(t).$implicit,m=l(3);return y(m.onEditAdvert(d))}),_(),n(27,"svg",37),p(28,"path",42),i()()(),u(29,J,7,1,"herdspace-tooltip",43),M(),n(30,"herdspace-tooltip",44)(31,"button",45),g("click",function(){let d=C(t).$implicit,m=l(3);return y(m.onDeleteAdvert(d))}),_(),n(32,"svg",37),p(33,"polyline",46)(34,"path",47)(35,"line",48)(36,"line",49),i()()()()()()}if(r&2){let t=e.$implicit,o=l(3);a(2),x("src",o.getAdvertImage(t),O)("alt",t.headline),a(2),b(t.item_type),a(),x("ngClass",o.getStatusBadgeClass(t.status)),a(),v(" ",I(7,11,t.status)," "),a(4),b(t.headline),a(3),b(o.formatPrice(t.price)),a(),f(t.region||t.country?14:-1),a(2),v("Posted: ",o.formatDate(t.createdAt)),a(2),v("Entity ID: ",t.entityId),a(11),f(o.canReactivateAdvert(t)?29:-1)}}function K(r,e){if(r&1&&(n(0,"div",20),k(1,Y,37,13,"div",22,A),i()),r&2){let t=l(2);a(),S(t.adverts())}}function Q(r,e){r&1&&(n(0,"div",21)(1,"h2"),s(2,"No listings found"),i(),n(3,"p"),s(4,"This user hasn't created any listings yet."),i()())}function W(r,e){if(r&1&&u(0,K,3,0,"div",20)(1,Q,5,0,"div",21),r&2){let t=l();f(t.adverts().length>0?0:1)}}var B=class r{router=h(V);route=h(R);userSearchService=h(j);toastService=h(F);userId=c(0);userData=c(null);adverts=c([]);totalAdverts=c(0);isLoading=c(!1);showDeleteModal=c(!1);advertToDelete=c(null);showReactivateModal=c(!1);advertToReactivate=c(null);updatingAdvertId=c(null);ngOnInit(){let e=this.route.snapshot.paramMap.get("userId");e?(this.userId.set(parseInt(e)),this.loadUserAdverts()):this.router.navigate(["/admin-panel/user-search"])}loadUserAdverts(){this.isLoading.set(!0),this.userSearchService.getUserAdverts(this.userId()).subscribe({next:e=>{this.userData.set(e.user),this.adverts.set(e.adverts),this.totalAdverts.set(e.totalAdverts),this.isLoading.set(!1)},error:e=>{console.error("Error loading user adverts:",e),this.isLoading.set(!1),this.toastService.error("Error","Failed to load user adverts")}})}getUserFullName(){let e=this.userData();return e?`${e.firstName} ${e.lastName}`.trim()||e.email:"Unknown User"}formatDate(e){return new Date(e).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric"})}formatPrice(e){return e==null?"N/A":typeof e=="string"?e.includes("\xA3")?e:`\xA3${e}
1`:`\xA3${e.toLocaleString()}`}getStatusBadgeClass(e){return e&&{approved:"status-approved",accepted:"status-accepted",pending:"status-pending",draft:"status-draft",rejected:"status-rejected",archived:"status-archived",sold:"status-sold",deleted:"status-rejected"}[e.toLowerCase()]||"status-pending"}canReactivateAdvert(e){return!e.isDraft&&e.status?.toLowerCase()==="sold"}getAdvertImage(e){return e.mainImage||(e.imageUrls&&e.imageUrls.length>0?e.imageUrls[0]:null)||"assets/images/png/placeholder-image.png"}getCategoryFromItemType(e){return{Horse:"horses",Pony:"ponies",Job:"jobs",Property:"properties",Vehicle:"vehicles",Horsebox:"vehicles",Trailer:"vehicles"}[e]||"horses"}onViewAdvert(e){if(e.status?.toLowerCase()==="draft"){let d=this.getCategoryFromItemType(e.item_type);this.router.navigate(["/create-an-advert"],{queryParams:{category:d,draftId:e.entityId}});return}let o={Horse:"/categories-horses",Pony:"/categories-ponies",Job:"/categories-jobs",Property:"/categories-properties",Vehicle:"/categories-vehicles",Horsebox:"/categories-vehicles",Trailer:"/categories-vehicles"}[e.item_type]||"/categories-horses";this.router.navigate([`${o}/${e.entityId}`])}onEditAdvert(e){if(e.status?.toLowerCase()==="draft"){let t=this.getCategoryFromItemType(e.item_type);this.router.navigate(["/create-an-advert"],{queryParams:{category:t,draftId:e.entityId}});return}this.router.navigate(["/edit-an-advert"],{queryParams:{id:e.entityId,type:e.item_type}})}onDeleteAdvert(e){this.advertToDelete.set(e),this.showDeleteModal.set(!0)}onReactivateAdvert(e){this.advertToReactivate.set(e),this.showReactivateModal.set(!0)}onConfirmReactivate(){let e=this.advertToReactivate();!e||this.updatingAdvertId()!==null||(this.updatingAdvertId.set(e.id),this.userSearchService.reactivateSoldAdvert(e.id).subscribe({next:()=>{this.toastService.success("Success","Listing status changed from SOLD to ACTIVE"),this.showReactivateModal.set(!1),this.advertToReactivate.set(null),this.updatingAdvertId.set(null),this.loadUserAdverts()},error:t=>{console.error("Error reactivating advert:",t);let o=t?.error?.error||"Failed to change listing status";this.toastService.error("Error",o),this.showReactivateModal.set(!1),this.advertToReactivate.set(null),this.updatingAdvertId.set(null)}}))}onCancelReactivate(){this.showReactivateModal.set(!1),this.advertToReactivate.set(null)}onConfirmDelete(){let e=this.advertToDelete();e&&this.userSearchService.deleteAdvert(e.entityId,e.item_type).subscribe({next:()=>{this.toastService.success("Success","Advert deleted successfully"),this.showDeleteModal.set(!1),this.advertToDelete.set(null),this.loadUserAdverts()},error:t=>{console.error("Error deleting advert:",t),this.toastService.error("Error","Failed to delete advert"),this.showDeleteModal.set(!1),this.advertToDelete.set(null)}})}onCancelDelete(){this.showDeleteModal.set(!1),this.advertToDelete.set(null)}onBack(){this.router.navigate(["/admin-panel/user-search"])}static \u0275fac=function(t){return new(t||r)};static \u0275cmp=P({type:r,selectors:[["app-user-adverts"]],decls:19,vars:5,consts:[[1,"user-listings-container"],[1,"user-listings-content"],["title","Delete Listing","message","Are you sure you want to delete this listing? This action cannot be undone.","confirmText","Delete","cancelText","Cancel","confirmButtonClass","danger",3,"confirm","cancel","isOpen"],["title","Mark Listing as Active","message","Set this listing back to ACTIVE? This removes the SOLD lifecycle status.","confirmText","Mark Active","cancelText","Cancel","confirmButtonClass","success",3,"confirm","cancel","isOpen"],[1,"user-listings-header"],[1,"header-left"],[1,"back-button",3,"click"],["xmlns","http://www.w3.org/2000/svg","width","20","height","20","viewBox","0 0 24 24","fill","none","stroke","currentColor","stroke-width","2","stroke-linecap","round","stroke-linejoin","round"],["x1","19","y1","12","x2","5","y2","12"],["points","12 19 5 12 12 5"],[1,"header-info"],[1,"page-title"],[1,"user-meta"],[1,"header-right"],[1,"total-count-badge"],[1,"loading-state"],[1,"user-name"],[1,"user-email"],[1,"user-id-badge"],[1,"loading-spinner"],[1,"listings-grid"],[1,"empty-state"],[1,"listing-card"],[1,"listing-card-image"],[3,"src","alt"],[1,"listing-type-badge"],[1,"listing-status-badge",3,"ngClass"],[1,"listing-card-content"],[1,"listing-title"],[1,"listing-details"],[1,"listing-price"],[1,"listing-location"],[1,"listing-date"],[1,"listing-entity-id"],[1,"listing-card-actions"],["text","View listing"],[1,"action-btn","view-btn",3,"click"],["xmlns","http://www.w3.org/2000/svg","width","18","height","18","viewBox","0 0 24 24","fill","none","stroke","currentColor","stroke-width","2","stroke-linecap","round","stroke-linejoin","round"],["d","M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"],["cx","12","cy","12","r","3"],["text","Edit listing"],[1,"action-btn","edit-btn",3,"click"],["d","M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"],["text","Mark listing as active"],["text","Delete listing"],[1,"action-btn","delete-btn",3,"click"],["points","3 6 5 6 21 6"],["d","M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"],["x1","10","y1","11","x2","10","y2","17"],["x1","14","y1","11","x2","14","y2","17"],[1,"action-btn","restore-btn",3,"click","disabled"],["points","23 4 23 10 17 10"],["points","1 20 1 14 7 14"],["d","M3.51 9a9 9 0 0 1 14.13-3.36L23 10"],["d","M20.49 15a9 9 0 0 1-14.13 3.36L1 14"]],template:function(t,o){t&1&&(n(0,"div",0)(1,"div",1)(2,"app-confirm-modal",2),g("confirm",function(){return o.onConfirmDelete()})("cancel",function(){return o.onCancelDelete()}),i(),n(3,"app-confirm-modal",3),g("confirm",function(){return o.onConfirmReactivate()})("cancel",function(){return o.onCancelReactivate()}),i(),n(4,"div",4)(5,"div",5)(6,"button",6),g("click",function(){return o.onBack()}),_(),n(7,"svg",7),p(8,"line",8)(9,"polyline",9),i(),s(10," Back "),i(),M(),n(11,"div",10)(12,"h1",11),s(13,"User Listings"),i(),u(14,N,7,3,"p",12),i()(),n(15,"div",13),u(16,H,2,1,"span",14),i()(),u(17,G,4,0,"div",15)(18,W,2,1),i()()),t&2&&(a(2),x("isOpen",o.showDeleteModal()),a(),x("isOpen",o.showReactivateModal()),a(11),f(o.userData()?14:-1),a(2),f(o.isLoading()?-1:16),a(),f(o.isLoading()?17:18))},dependencies:[L,D,E,$,z],styles:['.user-listings-container[_ngcontent-%COMP%]{min-height:100vh;background-color:#efe7da;padding:2rem}.user-listings-content[_ngcontent-%COMP%]{max-width:1400px;margin:0 auto}.user-listings-header[_ngcontent-%COMP%]{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:2rem;flex-wrap:wrap;gap:1.5rem}.header-left[_ngcontent-%COMP%]{display:flex;align-items:flex-start;gap:1.25rem}.back-button[_ngcontent-%COMP%]{display:flex;align-items:center;gap:8px;padding:10px 18px;background:#fff;border:1px solid var(--color-border, #d6d3d1);border-radius:var(--radius-md, 8px);cursor:pointer;font-size:14px;font-family:var(--font-body, "Outfit", sans-serif);color:var(--color-primary, #50503f);transition:all .2s ease;flex-shrink:0}.back-button[_ngcontent-%COMP%]:hover{background:var(--color-secondary-hover, #e7e5e4);border-color:var(--color-primary, #50503f)}.header-info[_ngcontent-%COMP%]{display:flex;flex-direction:column;gap:6px}.page-title[_ngcontent-%COMP%]{font-family:var(--font-heading, "Literata", serif);font-size:40px;font-weight:300;color:var(--color-primary, #50503f);margin:0}.user-meta[_ngcontent-%COMP%]{display:flex;align-items:center;gap:12px;flex-wrap:wrap;margin:0;font-size:14px;font-family:var(--font-body, "Outfit", sans-serif)}
1.user-name[_ngcontent-%COMP%]{font-weight:600;color:var(--color-primary, #50503f)}.user-email[_ngcontent-%COMP%]{color:var(--color-text-secondary, #666)}.user-id-badge[_ngcontent-%COMP%]{color:var(--color-text-muted, #999);font-size:12px;background:var(--color-secondary, #f5f5f4);padding:2px 10px;border-radius:var(--radius-sm, 4px)}.header-right[_ngcontent-%COMP%]{display:flex;align-items:center}.total-count-badge[_ngcontent-%COMP%]{background:var(--color-primary, #50503f);color:var(--color-text-herdspace, #efe7da);padding:10px 20px;border-radius:20px;font-size:14px;font-weight:600;font-family:var(--font-body, "Outfit", sans-serif)}.loading-state[_ngcontent-%COMP%]{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:80px 20px;background:#fff;border-radius:var(--radius-md, 8px);box-shadow:var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, .1))}.loading-state[_ngcontent-%COMP%] p[_ngcontent-%COMP%]{margin-top:16px;color:var(--color-text-secondary, #666);font-family:var(--font-body, "Outfit", sans-serif)}.loading-spinner[_ngcontent-%COMP%]{width:40px;height:40px;border:3px solid var(--color-secondary, #f5f5f4);border-top:3px solid var(--color-primary, #50503f);border-radius:50%;animation:_ngcontent-%COMP%_spin 1s linear infinite}@keyframes _ngcontent-%COMP%_spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.listings-grid[_ngcontent-%COMP%]{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:1.5rem}.listing-card[_ngcontent-%COMP%]{background:#fff;border-radius:var(--radius-md, 8px);overflow:hidden;box-shadow:var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, .1));transition:transform .2s ease,box-shadow .2s ease}.listing-card[_ngcontent-%COMP%]:hover{transform:translateY(-4px);box-shadow:var(--shadow-lg, 0 8px 24px rgba(0, 0, 0, .15))}.listing-card-image[_ngcontent-%COMP%]{position:relative;height:200px;overflow:hidden;background:var(--color-secondary, #f5f5f4)}.listing-card-image[_ngcontent-%COMP%] img[_ngcontent-%COMP%]{width:100%;height:100%;object-fit:cover}.listing-type-badge[_ngcontent-%COMP%]{position:absolute;top:12px;left:12px;background:var(--color-primary, #50503f);color:var(--color-text-herdspace, #efe7da);padding:6px 12px;border-radius:var(--radius-sm, 4px);font-size:11px;font-weight:600;font-family:var(--font-body, "Outfit", sans-serif);text-transform:uppercase;letter-spacing:.5px}.listing-status-badge[_ngcontent-%COMP%]{position:absolute;top:12px;right:12px;padding:6px 12px;border-radius:var(--radius-sm, 4px);font-size:11px;font-weight:600;font-family:var(--font-body, "Outfit", sans-serif);letter-spacing:.5px}.status-approved[_ngcontent-%COMP%], .status-accepted[_ngcontent-%COMP%]{background:#2d6a4f;color:#fff}.status-pending[_ngcontent-%COMP%]{background:#e9c46a;color:#333}.status-draft[_ngcontent-%COMP%]{background:var(--color-background-dark, #a09484);color:#fff}.status-rejected[_ngcontent-%COMP%]{background:#9b2226;color:#fff}.status-archived[_ngcontent-%COMP%]{background:#457b9d;color:#fff}.status-sold[_ngcontent-%COMP%]{background:#6f1d1b;color:#fff}.listing-card-content[_ngcontent-%COMP%]{padding:1.25rem}.listing-title[_ngcontent-%COMP%]{font-family:var(--font-heading, "Literata", serif);font-size:18px;font-weight:500;color:var(--color-primary, #50503f);margin:0 0 12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.listing-details[_ngcontent-%COMP%]{display:flex;flex-direction:column;gap:6px;margin-bottom:1rem}.listing-price[_ngcontent-%COMP%]{font-family:var(--font-body, "Outfit", sans-serif);font-size:20px;font-weight:700;color:var(--color-primary, #50503f);margin:0}.listing-location[_ngcontent-%COMP%]{font-size:13px;color:var(--color-text-secondary, #666);margin:0}.listing-date[_ngcontent-%COMP%], .listing-entity-id[_ngcontent-%COMP%]{font-size:12px;color:var(--color-text-muted, #999);margin:0}.listing-card-actions[_ngcontent-%COMP%]{display:flex;gap:8px;padding-top:1rem;border-top:1px solid var(--color-border, #d6d3d1)}.action-btn[_ngcontent-%COMP%]{display:flex;align-items:center;justify-content:center;width:42px;height:42px;border:1px solid var(--color-border, #d6d3d1);border-radius:var(--radius-md, 8px);background:#fff;cursor:pointer;transition:all .2s ease}.action-btn[_ngcontent-%COMP%]:hover{background:var(--color-secondary, #f5f5f4)}.action-btn[_ngcontent-%COMP%]:disabled{opacity:.55;cursor:not-allowed}.view-btn[_ngcontent-%COMP%]{color:var(--color-primary, #50503f)}.view-btn[_ngcontent-%COMP%]:hover{background:#50503f1a;border-color:var(--color-primary, #50503f)}.edit-btn[_ngcontent-%COMP%]{color:#2d6a4f}.edit-btn[_ngcontent-%COMP%]:hover{background:#2d6a4f1a;border-color:#2d6a4f}.delete-btn[_ngcontent-%COMP%]{color:#9b2226}.delete-btn[_ngcontent-%COMP%]:hover{background:#9b22261a;border-color:#9b2226}.restore-btn[_ngcontent-%COMP%]{color:#1d4ed8}.restore-btn[_ngcontent-%COMP%]:hover:not(:disabled){background:#1d4ed81a;border-color:#1d4ed8}.empty-state[_ngcontent-%COMP%]{text-align:center;padding:80px 20px;background:#fff;border-radius:var(--radius-md, 8px);
1box-shadow:var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, .1))}.empty-state[_ngcontent-%COMP%] h2[_ngcontent-%COMP%]{font-family:var(--font-heading, "Literata", serif);font-weight:400;margin:0 0 10px;color:var(--color-primary, #50503f)}.empty-state[_ngcontent-%COMP%] p[_ngcontent-%COMP%]{margin:0;color:var(--color-text-secondary, #666);font-family:var(--font-body, "Outfit", sans-serif)}@media (max-width: 768px){.user-listings-container[_ngcontent-%COMP%]{padding:1rem}.user-listings-header[_ngcontent-%COMP%]{flex-direction:column}.header-left[_ngcontent-%COMP%]{flex-direction:column;width:100%}.page-title[_ngcontent-%COMP%]{font-size:28px}.listings-grid[_ngcontent-%COMP%]{grid-template-columns:1fr}.user-meta[_ngcontent-%COMP%]{flex-direction:column;align-items:flex-start;gap:4px}}']})};export{B as UserAdverts};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.