import{d as e}from"./objectSpread2-DtFdQpqy.js";import{a as t,n}from"./preload-helper-EQ20WQt-.js";import{c as r,l as i,o as a}from"./prop-types-DdDwMzX7.js";import{U as o,ft as s}from"./poll-D7UTo6nN.js";import{Do as c,Eo as l,ct as u,dt as d,st as f,ut as p,wo as m}from"./time-BE5vfriQ.js";import{m as h}from"./account-tnN1L2J2.js";import{c as g,u as _}from"./form_fields-BFfmILJg.js";import{t as v}from"./callout-DN5SLZLr.js";import{t as y}from"./tag-DneWk4Wz.js";import{n as b}from"./useAccountId-hZkNcTVU.js";import{a as x,i as S,n as C,r as w,t as T}from"./edit_button-DHSktOQt.js";import{t as E}from"./useSearchTags-BrKkR-Td.js";var D=e(t()),O=n(),k=({renderItem:e,items:t,onEdit:n,onDelete:r,disabled:i})=>t.length===0?null:(0,O.jsx)(`ul`,{className:x.itemList,children:t.map(t=>{var a;return(0,O.jsxs)(`li`,{children:[(0,O.jsx)(`span`,{children:(a=e==null?void 0:e(t))==null?t.name:a}),(0,O.jsx)(j,{item:t,onEdit:n,onDelete:r,disabled:i})]},t.id)})}),A=r({edit:{id:`account_edit.item_list.edit`,defaultMessage:`Edit {name}`},delete:{id:`account_edit.item_list.delete`,defaultMessage:`Delete {name}`}}),j=({item:e,onDelete:t,onEdit:n,disabled:r})=>{let a=(0,D.useCallback)(()=>{n==null||n(e)},[e,n]),o=(0,D.useCallback)(()=>{t==null||t(e)},[e,t]),s=i();return!n&&!t?null:(0,O.jsxs)(`div`,{className:x.itemListButtons,children:[n&&(0,O.jsx)(C,{icon:!0,label:s.formatMessage(A.edit,{name:e.name}),disabled:r,onClick:a}),t&&(0,O.jsx)(T,{label:s.formatMessage(A.delete,{name:e.name}),disabled:r,onClick:o})]})},M=r({placeholder:{id:`account_edit_tags.search_placeholder`,defaultMessage:`Enter a hashtag…`}}),N=()=>{let e=i(),[t,n]=(0,D.useState)(``),{tags:r,searchTags:a,resetSearch:o,isLoading:s}=E({query:t,filterResults:e=>!e.featuring}),c=(0,D.useCallback)(e=>{n(e.target.value),a(e.target.value)},[a]),u=l(),d=(0,D.useCallback)(e=>{o(),n(``),u(f({names:[e.name]}))},[u,o]),p=(0,D.useId)(),m=e.formatMessage(M.placeholder);return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`label`,{htmlFor:p,className:`sr-only`,children:m}),(0,O.jsx)(g,{id:p,value:t,onChange:c,placeholder:m,items:r,isLoading:s,renderItem:P,onSelectItem:d,className:x.autoComplete,icon:h,type:`search`})]})},P=e=>{var t;return(0,O.jsx)(_,{children:(t=e.label)==null?`#${e.name}`:t})},F=r({columnTitle:{id:`account_edit_tags.column_title`,defaultMessage:`Edit Tags`}}),I=m([e=>e.profileEdit,e=>e.server.getIn([`server`,`accounts`,`max_featured_tags`],10)],(e,t)=>{var n,r,i;return{tags:(n=(r=e.profile)==null?void 0:r.featuredTags)==null?[]:n,tagSuggestions:(i=e.tagSuggestions)==null?[]:i,isLoading:!e.profile||!e.tagSuggestions,isPending:e.isPending,maxTags:t}}),L=()=>{let e=b(),t=o(e),n=i(),{tags:r,tagSuggestions:f,isLoading:m,isPending:h,maxTags:g}=c(I),_=l();(0,D.useEffect)(()=>{_(p()),_(d())},[_]);let y=(0,D.useCallback)(({id:e})=>{_(u({tagId:e}))},[_]);if(!e||!t)return(0,O.jsx)(S,{notFound:!e});let C=r.length<g;return(0,O.jsx)(w,{title:n.formatMessage(F.columnTitle),to:`/profile/edit`,children:(0,O.jsxs)(`div`,{className:x.wrapper,children:[(0,O.jsx)(a,{id:`account_edit_tags.help_text`,defaultMessage:`Featured hashtags help users discover and interact with your profile. They appear as filters on your Profile page’s Activity view.`,tagName:`p`}),C&&(0,O.jsx)(N,{}),f.length>0&&C&&(0,O.jsxs)(`div`,{className:x.tagSuggestions,children:[(0,O.jsx)(a,{id:`account_edit_tags.suggestions`,defaultMessage:`Suggestions:`}),f.map(e=>(0,O.jsx)(z,{name:e.name,disabled:h},e.id))]}),!C&&(0,O.jsx)(v,{icon:!1,className:x.maxTagsWarning,children:(0,O.jsx)(a,{id:`account_edit_tags.max_tags_reached`,defaultMessage:`You have reached the maximum number of featured hashtags.`})}),m&&(0,O.jsx)(s,{}),(0,O.jsx)(k,{items:r,disabled:h,renderItem:R,onDelete:y})]})})};function R(e){return(0,O.jsxs)(`div`,{className:x.tagItem,children:[(0,O.jsxs)(`h4`,{children:[`#`,e.name]}),e.statusesCount>0&&(0,O.jsx)(a,{id:`account_edit_tags.tag_status_count`,defaultMessage:`{count,plural,one{# post} other{# posts}}`,values:{count:e.statusesCount},tagName:`p`})]})}var z=({name:e,disabled:t})=>{let n=l();return(0,O.jsx)(y,{name:e,onClick:(0,D.useCallback)(()=>{n(f({names:[e]}))},[n,e]),disabled:t})};export{L as AccountEditFeaturedTags};
//# sourceMappingURL=featured_tags-B9M_FCLV.js.map