/**
 * Minified by jsDelivr using Terser v5.48.0.
 * Original file: /npm/sanity-plugin-taxonomy-manager@6.0.0/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import{useFormValue as e,set as t,useDocumentStore as n,useClient as i,useGetFormValue as o,usePerspective as r,isDraftId as c,FormField as s,isVersionId as a,unset as d,defineField as l,defineType as p,defineArrayMember as h,useSchema as m,getPublishedId as u,Preview as f,definePlugin as g}from"sanity";import{usePaneRouter as y,structureTool as b}from"sanity/structure";import{jsxs as C,jsx as I,Fragment as v}from"react/jsx-runtime";import{GenerateIcon as w}from"@sanity/icons/Generate";import{Stack as _,Text as x,Button as V,Card as T,Box as k,Flex as S,Dialog as z,Label as L,Badge as H,Inline as $,TextInput as N,TextArea as E,Spinner as P,Container as M,Grid as R}from"@sanity/ui";import{useToast as A}from"@sanity/ui/toast";import{useCallback as O,createContext as D,useState as Z,useRef as B,useEffect as U,useMemo as j,useContext as F}from"react";import{customAlphabet as q,nanoid as G}from"nanoid";import{c as K}from"react/compiler-runtime";import{distinctUntilChanged as W,catchError as Y}from"rxjs/operators";import{getPublishedId as X,DocumentId as Q,isVersionId as J,getVersionNameFromId as ee,getVersionId as te,getDraftId as ne,isPublishedId as ie}from"@sanity/id-utils";import{AddCircleIcon as oe}from"@sanity/icons/AddCircle";import{uuid as re}from"@sanity/uuid";import{RouterContext as ce}from"sanity/router";import{AddIcon as se}from"@sanity/icons/Add";import{InfoOutlineIcon as ae}from"@sanity/icons/InfoOutline";import{Tooltip as de}from"@sanity/ui/tooltip";import{TrashIcon as le}from"@sanity/icons/Trash";import{ErrorOutlineIcon as pe}from"@sanity/icons/ErrorOutline";import{ToggleArrowRightIcon as he}from"@sanity/icons/ToggleArrowRight";import{AiOutlineTags as me,AiOutlineTag as ue}from"react-icons/ai";import{DocumentsIcon as fe}from"@sanity/icons/Documents";import{EditIcon as ge}from"@sanity/icons/Edit";function ye(e){const t=e?.pattern||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",n=e?.length||6;return(e?.prefix||"")+q(t,n)()}const be=e=>{const{onChange:n,ident:i}=e,o=A(),r=O(()=>{const e=ye(i);n(t(e)),o.push({status:"success",title:"Identifier created.",closable:!0})},[n,o,i]);return I(_,{gap:2,children:I(V,{icon:w,mode:"ghost",width:"fill",onClick:r,text:"Generate identifier"})})};be.defaultProps={ident:void 0};const Ce=D(null),Ie=D({editControls:!1}),ve=D(void 0),we=D({}),_e=D({markRemoved:()=>{},unmarkRemoved:()=>{}});function xe(e,t){const n=t.has(X(e.id)),i=e.childConcepts?.map(e=>xe(e,t)),o=i?.some(e=>e.recommended||e.hasMatchingDescendant)??!1;return{...e,...n?{recommended:!0}:{},...o?{hasMatchingDescendant:!0}:{},...i?{childConcepts:i}:{}}}var Ve=Object.prototype.hasOwnProperty;function Te(e,t){var n,i;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((i=e.length)===t.length)for(;i--&&Te(e[i],t[i]););return-1===i}if(!n||"object"==typeof e){for(n in i=0,e)if(Ve.call(e,n)&&++i&&!Ve.call(t,n)||!(n in t)||!Te(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!=e&&t!=t}const ke={tone:"primary"};function Se(e){let t,n=K(12);n[0]===e?t=n[1]:(t={...ke,...e},n[0]=e,n[1]=t);let i,o,r,{title:c,description:s,icon:a,tone:d,children:l}=t,p=a?"display icon":null;return n[2]!==l||n[3]!==s||n[4]!==c?(i=l||I(k,{flex:1,children:C(_,{gap:4,children:[c?I(x,{weight:"semibold",children:c}):null,s?I(x,{size:2,children:s}):null]})}),n[2]=l,n[3]=s,n[4]=c,n[5]=i):i=n[5],n[6]!==p||n[7]!==i?(o=C(S,{children:[p,i]}),n[6]=p,n[7]=i,n[8]=o):o=n[8],n[9]!==o||n[10]!==d?(r=I(T,{tone:d,padding:4,radius:3,border:!0,children:o}),n[9]=o,n[10]=d,n[11]=r):r=n[11],r}const ze={},Le={apiVersion:"v2023-05-01"};function He(e){let t,n=K(4);n[0]===e?t=n[1]:(t=JSON.stringify(e||{}),n[0]=e,n[1]=t);let i,o=t;return n[2]===o?i=n[3]:(i=JSON.parse(o),n[2]=o,n[3]=i),i}function $e(e,t){let i,o,r,c=K(11),{params:s,options:a,initialValue:d}=t,l=void 0===s?ze:s,p=void 0===a?Le:a,h=void 0===d?null:d,[m,u]=Z(!0),[f,g]=Z(null),[I,y]=Z(h),C=He(l),b=He(p),v=B(null),_=n();return c[0]!==_||c[1]!==f||c[2]!==b||c[3]!==C||c[4]!==e?(i=()=>{if(e&&!f&&!v.current)try{v.current=_.listenQuery(e,C,b).pipe(W(Te),Y(e=>(console.error(e),g(e),u(!1),y(null),e))).subscribe(e=>{y(t=>Te(t,e)?t:e),u(!1),g(null)})}catch(e){let t=e;console.error(t),u(!1),g(t)}return f&&v.current&&v.current.unsubscribe(),()=>{v.current&&=(v?.current?.unsubscribe(),null)}},o=[e,f,C,b,_],c[0]=_,c[1]=f,c[2]=b,c[3]=C,c[4]=e,c[5]=i,c[6]=o):(i=c[5],o=c[6]),U(i,o),c[7]!==I||c[8]!==f||c[9]!==m?(r={data:I,loading:m,error:f},c[7]=I,c[8]=f,c[9]=m,c[10]=r):r=c[10],r}const Ne=(e=1)=>{let t="^.^.concepts[]._ref",n=1;for(;e>n;)t=`^.${t}`,n++;return e>6?"":`"childConcepts": *[_id in ${t} && ^._id in broader[]._ref]|order(prefLabel)\n     {\n      "id": _id,\n      "level": ${e},\n      _originalId,\n      prefLabel,\n      definition,\n      example,\n      scopeNote,\n      ${Ne(e+1)||""}\n    }`},Ee=3,Pe=D({useWatchTree:function(e){const t="input"===e.mode,n=$e({fetch:t?`\n  select($branchId != null => \n    *[_id == $id][0] {\n      _updatedAt,\n      "concepts": concepts[$branchId in @->broader[]->.conceptId]->|order(prefLabel) {\n        "id": _id,\n        "level": 0,\n        "isOrphan": true,\n        _originalId,\n        prefLabel,\n        definition,\n        example,\n        scopeNote,\n        ${Ne()||""}\n      }\n    },\n    *[_id == $id][0] {\n      _updatedAt,\n      "topConcepts":topConcepts[]->|order(prefLabel){\n        "id": _id,\n        "level": 0,\n        _originalId,\n        prefLabel,\n        definition,\n        example,\n        scopeNote,\n        ${Ne()||""}\n      }, \n      "concepts": concepts[]->|order(prefLabel){\n        "id": _id,\n        "level": 0,\n        "isOrphan": \n          coalesce(\n            !array::intersects(\n              broader[]._ref, (\n                coalesce(^.concepts[]._ref, []) + coalesce(^.topConcepts[]._ref, [])\n              )\n            ), \n          true),\n        _originalId,\n        prefLabel,\n        definition,\n        example,\n        scopeNote,\n        ${Ne()||""}\n      }\n    }\n  )`:`*[_id == $id][0] {\n    _updatedAt,\n    "topConcepts": topConcepts[]->|order(prefLabel) {\n      "id": _id,\n      "level": 0,\n      _originalId,\n      prefLabel,\n      definition,\n      example,\n      scopeNote,\n      ${Ne()||""}\n    },\n    "concepts": concepts[]->|order(prefLabel) {\n      "id": _id,\n      "level": 0,\n      "isOrphan": \n        coalesce(\n          !array::intersects(\n            broader[]._ref, (\n              coalesce(^.concepts[]._ref, []) + coalesce(^.topConcepts[]._ref, [])\n            )\n          ),\n        true),\n      _originalId,\n      prefLabel,\n      definition,\n      example,\n      scopeNote,\n      ${Ne()||""}\n    }\n  }`,listen:t?'*[_type == "skosConcept" || _id == $id]':'*[_type == "skosConcept" || _type == "skosConceptScheme" ]'},{params:t?{id:e.documentId,branchId:e.branchId}:{id:e.documentId},options:{perspective:void 0===e.perspective?"drafts":[e.perspective]}});return{data:n.data??null,loading:n.loading,error:n.error?n.error:null}},useApplyConceptPlan:function(){const e=i({apiVersion:"2025-02-19"});return O(async t=>{"remove"!==t.kind?await e.transaction().createIfNotExists(t.createIfNotExists).create(t.create).patch(t.schemeId,e=>e.setIfMissing({[t.appendField]:[]}).append(t.appendField,[t.reference])).commit({autoGenerateArrayKeys:!0}):await e.transaction().createIfNotExists(t.createIfNotExists).patch(t.schemeId,e=>e.unset(t.unsetPaths)).commit()},[e])},useSemanticRecommendations:function(e){const t=i({apiVersion:"vX"}),n=j(()=>t.withConfig({perspective:"published"}),[t]),r=o(),[c,s]=Z([]),[a,d]=Z(null);return{conceptRecs:c,recsError:a,triggerSearch:O(t=>{if(d(null),!e||!t)return;const{fieldReferences:i,maxResults:o=Ee}=e;let c;try{c=function(e){const t=[],n=[];for(const{name:i,value:o}of e)"string"==typeof o&&""!==o.trim()?t.push(o):n.push(i);if(1===n.length)throw new Error(`Please fill out the ${n[0]} field to enable match scores.`);if(n.length>1)throw new Error(`The following fields must be filled out to enable match scores: ${n.join(", ")}`);return t.join(" ")}(i.map(e=>({name:e,value:r([e])})))}catch(e){return void d(e instanceof Error?e.message:"One or more required fields are empty")}n.fetch('*[_type == "skosConcept" && _id in *[_type == "skosConceptScheme" && schemeId == $schemeId][0]{\n    "ids": coalesce(topConcepts[]._ref, []) + coalesce(concepts[]._ref, [])\n  }.ids] | score(text::semanticSimilarity($searchQuery)) | order(_score desc) [0...$maxResults] {\n    "conceptId": _id,\n    "score": _score\n  }',{searchQuery:c,maxResults:o,schemeId:t}).then(e=>s(function(e){if(!e)return[];const t=[];for(const n of e)!n||"string"!=typeof n.conceptId||""===n.conceptId||"number"==typeof n.score&&t.push({conceptId:X(n.conceptId),score:n.score});return t}(e))).catch(e=>{console.error("Error fetching semantic recommendations: ",e),d(function(e){const t=e instanceof Error?e.message:"string"==typeof e?e:"";return/embedding/i.test(t)?"Semantic recommendations aren't enabled for this dataset.":"Unable to load semantic recommendations."}(e))})},[n,r,e])}}});function Me(){return F(Pe)}const Re={type:"skosConcept",template:{id:"skosConcept"}};function Ae(e){const t=Q(e),n=J(t),i=n?ee(t):void 0;return{isInRelease:n,releaseName:i,schemeId:n?te(t,i):ne(t)}}function Oe(e){const t=A(),n=function(){const e=F(ce),{routerPanesState:t,groupIndex:n}=y();return O(i=>{if(!e||!i)return;const o=[...t];o.splice(n+1,n+1,[{id:i,params:{type:"skosConcept"}}]);const r=e.resolvePathFromState({panes:o});e.navigateUrl({path:r})},[e,t,n])}(),i=Me().useApplyConceptPlan(),{ident:o}=F(we),r=e.displayed.baseIri;return O((c,s)=>{const a=function(e){const t=Ae(e.scheme._id),n=function(e,t){const n=Q(e);return t.isInRelease?te(n,t.releaseName):ne(n)}(e.newConceptUuid,t),i={_id:n,_type:"skosConcept",conceptId:e.conceptId,prefLabel:"",baseIri:e.schemeBaseIri,broader:[],related:[]};var o;e.broaderConcept&&(i.broader=[{_key:e.broaderKey,_ref:X(Q(e.broaderConcept.id)),_type:"reference",...(o=e.broaderConcept._originalId,ie(Q(o))?{_weak:!1}:{_weak:!0,_strengthenOnPublish:Re})}]);const r={_ref:X(Q(n)),_type:"reference",_key:e.newConceptKey,_strengthenOnPublish:Re,_weak:!0};return{kind:"create",schemeId:t.schemeId,newConceptId:n,createIfNotExists:{...e.scheme,_id:t.schemeId},create:i,appendField:"topConcept"===e.conceptType?"topConcepts":"concepts",reference:r}}({scheme:e.displayed,conceptType:c,broaderConcept:s?.id?{id:s.id,_originalId:s._originalId??""}:void 0,newConceptUuid:re(),conceptId:ye(o),schemeBaseIri:r,newConceptKey:re(),broaderKey:re()});i(a).then(()=>{t.push({closable:!0,status:"success",title:"Created new concept"}),n(a.newConceptId)}).catch(e=>{t.push({closable:!0,status:"error",title:"Error creating concept",description:e instanceof Error?e.message:"Unknown error occurred"})})},[e.displayed,o,r,i,t,n])}function De(e){const t=A(),n=Me().useApplyConceptPlan(),{markRemoved:i,unmarkRemoved:o}=F(_e);return O((r,c,s)=>{const a=function(e){const t="topConcept"===e.conceptType?"topConcepts":"concepts",{schemeId:n}=Ae(e.scheme._id);return{kind:"remove",schemeId:n,createIfNotExists:{...e.scheme,_id:n},unsetPaths:[`${t}[_ref=="${e.conceptRef}"]`]}}({scheme:e.displayed,conceptRef:r,conceptType:c});i(r),n(a).then(()=>{t.push({closable:!0,status:"success",title:(s?`"${s}"`:"Concept")+" removed from scheme"})}).catch(e=>{o(r),t.push({closable:!0,status:"error",title:"Error removing concept",description:e instanceof Error?e.message:"Unknown error occurred"})})},[n,e.displayed,t,i,o])}const Ze=({title:e,message:t})=>C(_,{gap:2,children:[I(L,{size:1,children:e}),I(x,{size:2,muted:!0,style:{whiteSpace:"pre-wrap"},children:t})]}),Be=({concept:e})=>{const[t,n]=Z(!1),i=O(()=>n(!1),[]),o=O(()=>n(!0),[]);return e&&(e.definition||e.example||e.scopeNote)?C(v,{children:[I(de,{delay:{open:750},content:I(k,{padding:1,sizing:"content",children:I(x,{muted:!0,size:1,children:"View concept details"})}),fallbackPlacements:["right","left"],placement:"top",portal:!0,children:I(V,{icon:ae,mode:"bleed",onClick:o,tone:"default"})}),t&&I(z,{header:e.prefLabel,id:"dialog-example",onClose:i,zOffset:1e3,width:1,children:I(k,{padding:4,paddingTop:2,paddingBottom:5,children:C(_,{gap:4,children:[e.definition&&I(Ze,{title:"Definition",message:e.definition}),e.example&&I(Ze,{title:"Examples",message:e.example}),e.scopeNote&&I(Ze,{title:"Scope Notes",message:e.scopeNote})]})})})]}):null};function Ue({concept:e,topConcept:t=!1,orphan:n=!1}){const i=F(ce),{routerPanesState:o,groupIndex:r}=y(),{id:c,prefLabel:s}=e??{},a=s||"[new concept]",d=O(()=>{if(!i||!c)return;const e=[...o];e.splice(r+1,r+1,[{id:c,params:{type:"skosConcept"}}]);const t=i.resolvePathFromState({panes:e});i.navigateUrl({path:t})},[c,i,o,r]);return I(de,{delay:{open:750},content:I(k,{padding:1,sizing:"content",children:I(x,{muted:!0,size:1,children:`View "${s}"`})}),fallbackPlacements:["right","left"],placement:"top",children:I(V,{mode:"bleed",paddingLeft:0,onClick:d,width:"fill",justify:"flex-start",children:C(x,{size:2,weight:t?"bold":"regular",textOverflow:"ellipsis",children:[a,(t||n)&&I(H,{fontSize:0,marginLeft:3,style:{verticalAlign:"middle"},children:t?"top concept":"orphan"})]})})})}const je=({action:e,handler:t})=>{const n={add:{message:"Add a child concept below this concept",icon:oe,tone:"positive"},remove:{message:"Remove this concept from this scheme",icon:le,tone:"critical"}};return I(de,{delay:{open:750},content:I(k,{padding:1,sizing:"content",children:I(x,{muted:!0,size:1,children:n[e].message})}),fallbackPlacements:["right","left"],placement:"top",children:I(V,{icon:n[e].icon,mode:"bleed",onClick:t,tone:n[e].tone,"aria-label":n[e].message})})};function Fe({concept:e,topConcept:t=!1,orphan:n=!1,selectConcept:i}){const{prefLabel:o,id:r,_originalId:c,recommended:s}=e??{},a=o||"[new concept]",d=O(()=>{i&&i({_ref:r,_type:"reference",_originalId:c})},[r,c,i]);return I(v,{children:i&&I(de,{delay:{open:750},content:I(k,{padding:1,sizing:"content",children:C(x,{muted:!0,size:1,children:[`Select "${o}"`,s&&" (recommended)"]})}),fallbackPlacements:["right","left","bottom"],placement:"top",portal:!0,children:I(V,{mode:"bleed",paddingLeft:0,onClick:d,width:"fill",justify:"flex-start",children:C(x,{size:2,weight:t?"bold":"regular",textOverflow:"ellipsis",children:[a,(t||n)&&I(H,{fontSize:0,marginLeft:3,style:{verticalAlign:"middle"},children:t?"top concept":"orphan"}),s&&I(H,{tone:"positive",fontSize:0,marginLeft:3,style:{verticalAlign:"middle"},children:"recommended"})]})})})})}const qe=({message:e,title:t,type:n})=>{const[i,o]=Z(!1),r=O(()=>o(!1),[]),c=O(()=>o(!0),[]);return C(v,{children:[I(de,{delay:{open:750},content:I(k,{padding:1,sizing:"content",children:I(x,{muted:!0,size:1,children:t})}),fallbackPlacements:["right","left"],placement:"top",portal:!0,children:I(V,{icon:"error"==n?pe:ae,mode:"bleed",onClick:c,tone:{info:"default",warn:"caution",error:"critical"}[n]})}),i&&I(z,{header:t,id:"dialog-example",onClose:r,zOffset:1e3,width:1,children:I(k,{padding:4,paddingBottom:5,children:I(x,{children:e})})})]})};function Ge({handler:e,visibility:t}){return I(V,{icon:he,mode:"bleed","aria-expanded":"open"==t,onClick:e,className:"ToggleButton-module_toggleButton__4X-Gs"})}!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(!(typeof document>"u")){var i=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===n&&i.firstChild?i.insertBefore(o,i.firstChild):i.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}(".ToggleButton-module_toggleButton__4X-Gs[aria-expanded='true'] svg {\n  rotate: 90deg;\n}\n");const Ke=({concept:e,selectConcept:t,inputComponent:n=!1})=>{const i=F(Ce)||{},o=F(ve),{globalVisibility:{treeVisibility:r}={treeVisibility:"open"}}=F(Ie)||{},c=Oe(i),s=De(i),a=O(()=>{c("concept",e)},[e,c]),d=O(()=>{s(e.id,"concept",e?.prefLabel)},[e.id,e?.prefLabel,s]),[l,p]=Z("closed"===r&&e.hasMatchingDescendant?"open":r||"open"),h=O(()=>{"open"==l?p("closed"):"closed"==l&&p("open")},[l]);return C(k,{className:l,children:[C(S,{align:"center",justify:"space-between",wrap:"nowrap",children:[C(S,{align:"center",gap:0,flex:1,style:{minWidth:0},children:[e?.childConcepts&&e.childConcepts.length>0&&I(Ge,{handler:h,visibility:l}),!e?.prefLabel&&I(k,{flex:1,marginLeft:e?.childConcepts&&0!=e.childConcepts.length?0:5,children:I(Ue,{concept:e})}),e?.prefLabel&&I(k,{flex:1,marginLeft:e?.childConcepts&&0!=e.childConcepts.length?0:5,children:n?I(Fe,{concept:e,selectConcept:t}):I(Ue,{concept:e})})]}),n&&I(Be,{concept:e}),!n&&"published"!==o&&e?.level&&e.level<5&&C($,{children:[I(je,{action:"add",handler:a}),I(je,{action:"remove",handler:d})]}),!n&&"published"!==o&&0==e.childConcepts?.length&&5==e.level&&C($,{children:[I(qe,{type:"warn",title:"Taxonomy Manager structure notice",message:"This concept is at the maximum Taxonomy Manager hierarchy depth of 5 levels. Additional child terms are not shown in the hierarchy tree."}),I(je,{action:"remove",handler:d})]}),e?.childConcepts&&e?.childConcepts?.length>0&&5==e.level&&C($,{children:[I(qe,{type:"error",title:"Taxonomy Manager structure warning",message:"This concept has unlisted child concepts. The maximum validated hierarchy depth is 5 levels."}),!n&&"published"!==o&&I(je,{action:"remove",handler:d})]})]}),e?.childConcepts&&e.childConcepts.length>0&&e?.level&&e.level<5&&I(We,{concepts:e.childConcepts,selectConcept:t,inputComponent:n,childVisibility:l})]})},We=({concepts:e,inputComponent:t=!1,selectConcept:n,childVisibility:i})=>I(k,{marginLeft:4,marginTop:2,display:"closed"==i?"none":"block",children:I(_,{gap:3,children:e.map(e=>I(Ke,{concept:e,selectConcept:n,inputComponent:t},e.id))})}),Ye=({concept:e,treeVisibility:t,inputComponent:n,selectConcept:i})=>{const o=F(Ce)||{},r=F(ve),c=!!o.displayed?.topConcepts?.length&&!n,s=Oe(o),a=De(o),[d,l]=Z("closed"===t&&e.hasMatchingDescendant?"open":t),p=O(()=>{"open"==d?l("closed"):"closed"==d&&l("open")},[d]),h=O(()=>{s("concept",e)},[e,s]),m=O(()=>{a(e.id,"concept",e?.prefLabel)},[e.id,e?.prefLabel,a]);return C(k,{className:d,children:[C(S,{align:"center",justify:"space-between",wrap:"nowrap",children:[C(S,{align:"center",gap:0,flex:1,style:{minWidth:0},children:[e?.childConcepts&&e.childConcepts.length>0&&I(Ge,{handler:p,visibility:d}),!e?.prefLabel&&I(k,{flex:1,marginLeft:e?.childConcepts&&0!=e.childConcepts.length?0:5,children:I(Ue,{concept:e,orphan:c})}),e?.prefLabel&&I(k,{flex:1,marginLeft:e?.childConcepts&&0!=e.childConcepts.length?0:5,children:n?I(Fe,{concept:e,selectConcept:i,orphan:c}):I(Ue,{concept:e,orphan:c})})]}),n&&I(Be,{concept:e}),!n&&"published"!==r&&C($,{children:[I(je,{action:"add",handler:h}),I(je,{action:"remove",handler:m})]})]}),e?.childConcepts&&e.childConcepts.length>0&&I(We,{concepts:e.childConcepts,selectConcept:i,inputComponent:n,childVisibility:d})]})},Xe=({document:e})=>{const[t,n]=Z(!1),[o,r]=Z(""),[c,s]=Z(""),a=O(()=>n(!1),[]),d=O(()=>n(!0),[]),l=O(e=>{r(e.currentTarget.value)},[]),p=O(e=>{s(e.currentTarget.value)},[]),h=function(){const e=A(),t=i({apiVersion:"2021-10-21"});return O((n,i,o)=>{const r=n.displayed?._id,c=n.displayed?.baseIri,s=n.displayed?.schemeId,a={_id:`drafts.${r}`,_type:"skosConceptScheme",schemeId:s,baseIri:c,title:i,description:o||""};t.createIfNotExists(a).then(t=>o?e.push({closable:!0,status:"success",title:"Title and Description added."}):e.push({closable:!0,status:"success",title:"Title added."})).catch(t=>{e.push({closable:!0,status:"error",title:"There has been an error",description:t.message})})},[t,e])}(),m=O(()=>{h(e,o,c)},[h,c,e,o]);return C("div",{style:{marginTop:"2rem"},children:[I(T,{padding:[3,3,4],radius:2,shadow:1,tone:"primary",children:C(_,{gap:6,children:[C(_,{gap:4,children:[I(L,{size:4,children:"New Concept Scheme"}),I(x,{size:2,children:'To start using hierarchy view taxonomy builder, first give your concept scheme a name and optional description. You can also use the "Editor" tab to add concepts to the tree manually.'})]}),I(V,{tone:"primary",fontSize:2,icon:se,onClick:d,text:"Add Title"})]})}),t&&I(z,{header:"Title & Description",id:"title-description",onClose:a,zOffset:1e3,width:1,children:I(k,{padding:4,children:C(_,{gap:4,children:[C(_,{gap:2,children:[I(L,{size:1,children:"Title"}),I(x,{size:1,muted:!0,children:"Describe the concept scheme in one or two words."})]}),I(N,{fontSize:2,onChange:l,padding:3,placeholder:"",value:o}),C(_,{gap:2,children:[I(L,{size:1,children:"Description (optional)"}),I(x,{size:1,muted:!0,children:"Describe the intended use of this concept scheme."})]}),I(E,{fontSize:2,onChange:p,padding:3,placeholder:"",value:c,rows:3}),I(V,{tone:"primary",fontSize:2,onClick:m,text:"Save"})]})})})]})},Qe=()=>I("div",{style:{marginTop:"2rem"},children:I(T,{padding:[3,3,4],radius:2,shadow:1,tone:"primary",children:C(_,{gap:4,children:[I(L,{size:4,children:"No Concepts"}),I(x,{size:2,children:"There are not yet any concepts assigned to this scheme. To create a multi-level hierarchy with specific entry points, create Top Concepts first, then add child concepts to them. To create a flat list of concepts, create Concepts directly."})]})})}),Je=({concept:e,treeVisibility:t,inputComponent:n,selectConcept:i})=>{const o=F(Ce)||{},r=F(ve),c=Oe(o),s=De(o),[a,d]=Z("closed"===t&&e.hasMatchingDescendant?"open":t),l=O(()=>{"open"==a?d("closed"):"closed"==a&&d("open")},[a]),p=O(()=>{c("concept",e)},[e,c]),h=O(()=>{s(e?.id,"topConcept",e?.prefLabel)},[e?.id,e?.prefLabel,s]);return C(k,{className:a,children:[C(S,{align:"center",justify:"space-between",wrap:"nowrap",children:[C(S,{align:"center",gap:0,flex:1,style:{minWidth:0},children:[e?.childConcepts&&e.childConcepts.length>0&&I(Ge,{handler:l,visibility:a}),!e?.prefLabel&&I(k,{flex:1,marginLeft:e?.childConcepts&&0!=e.childConcepts.length?0:5,children:I(Ue,{concept:e,topConcept:!0})}),e?.prefLabel&&I(k,{flex:1,marginLeft:e?.childConcepts&&0!=e.childConcepts.length?0:5,children:n?I(Fe,{concept:e,selectConcept:i,topConcept:!0}):I(Ue,{concept:e,topConcept:!0})})]}),n&&I(Be,{concept:e}),!n&&"published"!==r&&C($,{children:[I(je,{action:"add",handler:p}),I(je,{action:"remove",handler:h})]})]}),e?.childConcepts&&e.childConcepts.length>0&&I(We,{concepts:e.childConcepts,selectConcept:i,inputComponent:n,childVisibility:a})]})},et=({concepts:e,inputComponent:t,selectConcept:n})=>{const{globalVisibility:{treeId:i,treeVisibility:o}={treeId:"default",treeVisibility:"open"}}=F(Ie)||{};return e?.topConcepts?.length||e?.concepts?.length?I(k,{paddingTop:4,children:C(_,{gap:3,style:{listStyle:"none",paddingLeft:"0",marginBlockStart:"0"},children:[e?.topConcepts?.map(e=>I(Je,{concept:e,treeVisibility:o,inputComponent:t,selectConcept:n},`${e?.id}+${i}`)),e?.concepts?.filter(e=>e?.isOrphan).map(e=>I(Ye,{concept:e,treeVisibility:o,inputComponent:t,selectConcept:n},`${e.id}+${i}`))]})}):I(Qe,{})},tt=({branchId:e="",selectConcept:t,inputComponent:n,expanded:i,conceptRecs:o,recsError:r})=>{const c=F(Ce)||{},s=X(c.displayed?._id),a=F(ve),d=i?"open":"closed",l=Me(),{data:p,loading:h,error:m}=l.useWatchTree({mode:"input",documentId:s,branchId:e,perspective:a}),u=j(()=>new Set((o??[]).map(e=>e.conceptId)),[o]),f=j(()=>G(6),[u]),g=j(()=>!p||0===u.size||r?p:{topConcepts:p.topConcepts?.map(e=>xe(e,u)),concepts:p.concepts?.map(e=>xe(e,u))},[p,u,r]);return h?I(k,{padding:5,children:C(S,{align:"center",direction:"column",gap:5,height:"fill",justify:"center",style:{paddingTop:"1rem"},children:[I(P,{muted:!0}),I(x,{muted:!0,size:1,children:"Loading hierarchy…"})]})}):m?(console.warn(m),I(k,{padding:4,children:I(T,{padding:[3],radius:2,shadow:1,tone:"caution",children:I(x,{size:1,children:"There was a problem loading terms. Please check the scheme configuration and try again."})})})):p?I(Ie.Provider,{value:{globalVisibility:{treeId:f,treeVisibility:d}},children:C(k,{padding:4,paddingTop:0,children:[r&&I(T,{marginTop:2,padding:3,radius:2,shadow:1,tone:"caution",children:I(x,{size:2,children:r})}),I(et,{concepts:g,inputComponent:n||!1,selectConcept:t||(()=>{})})]})}):I(k,{padding:4,children:I(T,{padding:[3],radius:2,shadow:1,tone:"caution",children:I(x,{size:1,children:"This configuration does not have any terms associated with it. Please check the scheme and branch supplied and try again."})})})};function nt(){return I("svg",{"data-sanity-icon":!0,width:"25",height:"25",viewBox:"0 0 25 25",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:I("path",{d:"M5.5 6.5V5.9H4.9V6.5H5.5ZM11.5 6.5H12.1V5.9H11.5V6.5ZM5.5 9H4.9V9.6H5.5V9ZM11.5 9V9.6H12.1V9H11.5ZM13.5 11V10.4H12.9V11H13.5ZM19.5 11H20.1V10.4H19.5V11ZM13.5 13.5H12.9V14.1H13.5V13.5ZM19.5 13.5V14.1H20.1V13.5H19.5ZM13.5 16V15.4H12.9V16H13.5ZM19.5 16H20.1V15.4H19.5V16ZM13.5 18.5H12.9V19.1H13.5V18.5ZM19.5 18.5V19.1H20.1V18.5H19.5ZM5.5 7.1H11.5V5.9H5.5V7.1ZM6.1 9V6.5H4.9V9H6.1ZM11.5 8.4H5.5V9.6H11.5V8.4ZM10.9 6.5V9H12.1V6.5H10.9ZM13.5 11.6H19.5V10.4H13.5V11.6ZM14.1 13.5V11H12.9V13.5H14.1ZM19.5 12.9H13.5V14.1H19.5V12.9ZM18.9 11V13.5H20.1V11H18.9ZM13.5 16.6H19.5V15.4H13.5V16.6ZM14.1 18.5V16H12.9V18.5H14.1ZM19.5 17.9H13.5V19.1H19.5V17.9ZM18.9 16V18.5H20.1V16H18.9ZM8 17.85H13.5V16.65H8V17.85ZM8 12.85H13.5V11.65H8V12.85ZM7.9 9.5V17.85H9.1V9.5H7.9Z",fill:"currentColor"})})}function it(e,t){return e.filter(e=>!t.has(e.id)).map(e=>e.childConcepts?{...e,childConcepts:it(e.childConcepts,t)}:e)}const ot=({inputComponent:e=!1,selectConcept:t})=>{const n=F(Ce)||{},i=X(n.displayed?._id),o=F(ve),r=Me(),c=Oe(n),s=O(()=>{c("topConcept")},[c]),a=O(()=>{c("concept")},[c]),[d,l]=Z({treeId:G(6),treeVisibility:"open"}),p=O(()=>{l({treeId:G(6),treeVisibility:"open"})},[]),h=O(()=>{l({treeId:G(6),treeVisibility:"closed"})},[]),[m,u]=Z(()=>new Set),f=O(e=>{u(t=>{if(t.has(e))return t;const n=new Set(t);return n.add(e),n})},[]),g=O(e=>{u(t=>{if(!t.has(e))return t;const n=new Set(t);return n.delete(e),n})},[]),y=j(()=>({markRemoved:f,unmarkRemoved:g}),[f,g]),{data:b,loading:w,error:L}=r.useWatchTree({mode:"trunk",documentId:i,perspective:o});U(()=>{u(e=>{if(0===e.size)return e;const t=function(e){const t=new Set,n=e=>{if(e)for(const i of e)t.add(i.id),n(i.childConcepts)};return e&&(n(e.topConcepts),n(e.concepts)),t}(b),n=new Set([...e].filter(e=>t.has(e)));return n.size===e.size?e:n})},[b]);const z=j(()=>function(e,t){return e&&0!==t.size?{...e,topConcepts:(e.topConcepts??[]).filter(e=>!t.has(e.id)).map(e=>e.childConcepts?{...e,childConcepts:it(e.childConcepts,t)}:e),concepts:(e.concepts??[]).filter(e=>!t.has(e.id)).map(e=>e.childConcepts?{...e,childConcepts:it(e.childConcepts,t)}:e)}:e}(b,m),[b,m]);return w?I(k,{padding:4,paddingTop:6,children:C(S,{align:"center",direction:"column",gap:5,height:"fill",justify:"center",children:[I(P,{muted:!0}),I(x,{muted:!0,size:1,children:"Loading hierarchy…"})]})}):L?(console.error(L),I("div",{children:"Error here"})):z?I(Ie.Provider,{value:{globalVisibility:d},children:I(k,{padding:4,children:C(v,{children:[I(_,{gap:4,children:I(T,{borderBottom:!0,paddingBottom:1,display:"flex",flex:1,children:C(S,{justify:"space-between",flex:1,children:[I(T,{children:(z.topConcepts?.filter(e=>(e?.childConcepts?.length??0)>0).length>0||z.concepts?.filter(e=>(e?.childConcepts?.length??0)>0).length>0)&&C($,{gap:1,children:[I(V,{text:"Collapse",paddingY:2,mode:"bleed",onClick:h}),I(x,{weight:"semibold",muted:!0,size:1,children:"|"}),I(V,{text:"Expand",paddingY:2,mode:"bleed",onClick:p})]})}),I(T,{children:"published"!==o&&C($,{gap:1,children:[I(V,{text:"Add Top Concept",icon:oe,mode:"bleed",tone:"positive",paddingY:2,onClick:s}),I(V,{text:"Add Concept",icon:oe,mode:"bleed",tone:"positive",paddingY:2,onClick:a})]})})]})})}),I(_e.Provider,{value:y,children:I(et,{concepts:z,inputComponent:e,selectConcept:t||(()=>{})})})]})})}):I(Xe,{document:n})},rt=({document:e,branchId:t,inputComponent:n=!1,selectConcept:i,expanded:o,conceptRecs:c,recsError:s})=>{const{selectedPerspectiveName:a}=r();return I(Ce.Provider,{value:e||{},children:I(ve.Provider,{value:a,children:n?I(tt,{inputComponent:n,branchId:t,selectConcept:i,expanded:o,conceptRecs:c,recsError:s}):C(M,{width:1,children:[e?.displayed?.description&&I(k,{padding:4,paddingTop:6,children:I(_,{gap:4,children:C(_,{gap:2,children:[I(x,{size:1,weight:"semibold",children:"Description"}),I(x,{size:2,muted:!0,children:e?.displayed.description})]})})}),I(ot,{inputComponent:n,branchId:t})]})})})};function ct(t){const n=i({apiVersion:"vX"}),o=e(["_id"]),{name:a,title:d,value:l,semanticSearch:p}=t,h=Me(),{conceptRecs:m,recsError:u,triggerSearch:f}=h.useSemanticRecommendations(p),g=J(o),y=c(o),{selectedPerspectiveName:b}=r(),[v,w]=Z(!0),[L,H]=Z(!0),[$,N]=Z(!1),[M,A]=Z(void 0),[E,F]=Z(),{schemeId:D,branchId:j=null}=E?.params||{},{filter:B}=t.schemaType.options;U(()=>{(async function(){try{const e=await B({getClient:()=>n});F(e),H(!1)}catch(e){console.error("Error fetching filter values: ",e)}})().catch(e=>console.error("Error fetching filter values: ",e))},[B,n]),U(()=>{D&&n.fetch('{"displayed": *[schemeId == $schemeId][0]}',{schemeId:D}).then(e=>{e?.displayed&&(A(e),w(!1))}).catch(e=>console.warn(e))},[n,D]);const G=O(()=>{N(!0),f(D)},[f,D]),q=O(()=>{N(!1)},[]),X=O(e=>{(c(e?._originalId)||J(e?._originalId))&&(e._strengthenOnPublish={type:"skosConcept",template:{id:"skosConcept"}},e._weak=!0),delete e._originalId,y||g?n.patch(o).set({[a]:e}).commit().then(()=>N(!1)).catch(e=>console.error(e)):n.fetch("*[_id == $id][0]",{id:o}).then(t=>{t._id=`drafts.${t._id}`,t[a]=e,n.create(t).catch(e=>console.error("Error creating draft: ",e))}).then(()=>N(!1)).catch(e=>console.error(e))},[n,o,y,g,a]);if(!t.schemaType.options?.filter)return C(_,{gap:3,children:[t.renderDefault(t),I(k,{padding:4,children:I(T,{padding:[3],radius:2,shadow:1,tone:"caution",children:C(x,{size:1,children:["The ",I("code",{children:"ReferenceHierarchyInput()"})," component must be used with an accompanying"," ",I("code",{children:"schemeFilter()"})," or ",I("code",{children:"branchFilter()"}),". Please add an appropriate filter to the configuration for the ",d," field."]})})})]});if(0===t.schemaType.options?.filter.length)return C(_,{gap:3,children:[t.renderDefault(t),I(k,{padding:4,children:I(T,{padding:[3],radius:2,shadow:1,tone:"caution",children:C(x,{size:1,children:["There was a problem loading your filter settings. Please check the"," ",I("code",{children:"schemeFilter()"})," or ",I("code",{children:"branchFilter()"})," configuration for the"," ",d," field."]})})})]});if(v||L)return I(k,{padding:5,children:C(S,{align:"center",direction:"column",gap:5,height:"fill",justify:"center",style:{paddingTop:"1rem"},children:[I(P,{muted:!0}),I(x,{muted:!0,size:1,children:"Loading input component…"})]})});const K="published"===b;return C(_,{gap:4,children:[E?.browseOnly?l?t.renderDefault(t):I(s,{title:d,path:t.path,description:t.description,level:t.level,validation:t.validation,__unstable_presence:t.presence,children:I(T,{padding:3,radius:2,border:!0,children:I(x,{muted:!0,align:"center",size:1,children:"No items"})})}):t.renderDefault(t),I(R,{gridTemplateColumns:1,gap:3,children:I(V,{disabled:K,icon:nt,text:"Browse taxonomy tree",mode:"ghost",onClick:G})}),$&&M&&I(z,{header:d,id:"concept-select-dialog",onClose:q,zOffset:900,width:1,children:I(k,{padding:10,children:I(rt,{document:M,branchId:j,inputComponent:!0,selectConcept:X,expanded:E?.expanded,conceptRecs:m,recsError:u})})})]})}function st(t){const n=i({apiVersion:"2025-02-19"}),o=e(["_id"]),{name:d,title:l,value:p=[],semanticSearch:h}=t,m=a(o),u=c(o),{selectedPerspectiveName:f}=r(),[g,y]=Z(!0),[b,v]=Z(!0),[w,H]=Z(!1),[$,N]=Z({}),[M,E]=Z(),{schemeId:F,branchId:D=null}=M?.params||{},{filter:j}=t.schemaType.of[0].options,B=Me(),{conceptRecs:G,recsError:q,triggerSearch:X}=B.useSemanticRecommendations(h),K=A();U(()=>{(async function(){try{const e=await j({getClient:()=>n});E(e),v(!1)}catch(e){console.error("Error fetching filter values: ",e)}})().catch(e=>console.error("Error fetching filter values: ",e))},[j,n]),U(()=>{F&&n.fetch(`{"displayed": *[schemeId == "${F}"][0]}`).then(e=>{e?.displayed&&(N(e),y(!1))}).catch(e=>console.warn(e))},[n,F]);const Q=O(()=>{H(!0),X(F)},[X,F]),W=O(()=>{H(!1)},[]),Y=O(e=>{if((c(e?._originalId)||a(e?._originalId))&&(e._strengthenOnPublish={type:"skosConcept",template:{id:"skosConcept"}},e._weak=!0),delete e._originalId,p?.map(e=>e._ref).includes(e._ref))return H(!1),void K.push({status:"warning",title:"Taxonomy Term Not Added",description:"The selected concept is already included in this field.",duration:5e3,closable:!0});u||m?n.patch(o).setIfMissing({[d]:[]}).append(d,[e]).commit({autoGenerateArrayKeys:!0}).then(()=>H(!1)).catch(e=>console.error(e)):n.fetch(`*[_id == "${o}"][0]`).then(e=>{e._id=`drafts.${e._id}`,n.create(e).catch(e=>console.error("Error creating draft: ",e))}).then(()=>{n.patch(`drafts.${o}`).setIfMissing({[d]:[]}).append(d,[e]).commit({autoGenerateArrayKeys:!0}).then(()=>H(!1)).catch(e=>console.error(e))}).catch(e=>console.error(e))},[p,u,m,n,o,K,d]);if(!t.schemaType.of[0].options?.filter)return C(_,{gap:3,children:[t.renderDefault(t),I(k,{padding:4,children:I(T,{padding:[3],radius:2,shadow:1,tone:"caution",children:C(x,{size:1,children:["The ",I("code",{children:"ArrayHierarchyInput()"})," component must be used with an accompanying"," ",I("code",{children:"schemeFilter()"})," or ",I("code",{children:"branchFilter()"}),". Please add an appropriate filter to the configuration for the ",l," field."]})})})]});if(0===t.schemaType.of[0].options?.filter?.length)return C(_,{gap:3,children:[t.renderDefault(t),I(k,{padding:4,children:I(T,{padding:[3],radius:2,shadow:1,tone:"caution",children:C(x,{size:1,children:["There was a problem loading your filter settings. Please check the"," ",I("code",{children:"schemeFilter()"})," or ",I("code",{children:"branchFilter()"})," configuration for the"," ",l," field."]})})})]});if(t.schemaType.of.length>1)return C(_,{gap:3,children:[t.renderDefault(t),I(T,{padding:[3],radius:2,shadow:1,tone:"caution",children:I(_,{gap:4,children:C(_,{gap:2,children:[I(L,{size:2,children:"Input Component Not Supported for Multi-Schema Arrays"}),C(x,{size:1,children:["The Sanity Taxonomy Manager Hierarchy Input Component is not designed to support array inputs with more than one schema type. Please see the"," ",I("a",{href:"https://sanitytaxonomymanager.com",children:"Taxonomy Manager docs"})," for more information."]})]})})})]});if(g||b)return I(k,{padding:5,children:C(S,{align:"center",direction:"column",gap:5,height:"fill",justify:"center",style:{paddingTop:"1rem"},children:[I(P,{muted:!0}),I(x,{muted:!0,size:1,children:"Loading input component…"})]})});const J="published"===f;return C(_,{gap:3,children:[M?.browseOnly?p.length>0?t.renderDefault(t):I(s,{title:l,path:t.path,description:t.description,level:t.level,validation:t.validation,__unstable_presence:t.presence,children:I(T,{padding:3,radius:2,border:!0,children:I(x,{muted:!0,align:"center",size:1,children:"No items"})})}):t.renderDefault(t),I(R,{gridTemplateColumns:1,gap:3,children:I(V,{disabled:J,icon:nt,text:"Browse taxonomy tree",mode:"ghost",onClick:Q})}),w&&I(z,{header:l,id:"concept-select-dialog",onClose:W,zOffset:900,width:1,children:I(k,{children:I(rt,{document:$,branchId:D,inputComponent:!0,selectConcept:Y,expanded:M?.expanded,conceptRecs:G,recsError:q})})})]})}const at=e=>{const{onChange:t}=e,n=A(),i=O(()=>{t(d()),n.push({status:"success",title:"Value removed.",duration:2500,closable:!0})},[t,n]);return I(_,{gap:2,children:C($,{gap:[3,3,4],children:[e.renderDefault(e),I(V,{tone:"primary",fontSize:2,onClick:i,text:"Remove Value"})]})})};function dt(e){if(!e||"string"!=typeof e)throw new Error("Invalid or missing schemeId: scheme Id must be a string")}const lt=e=>{const{schemeId:t}=e||{};return dt(t),async n=>{const i=n?.getClient({apiVersion:"2025-02-19"});if(!i)throw new Error("Client not available");const{concepts:o,topConcepts:r}=await i.fetch(`{\n      "concepts": *[_type=="skosConceptScheme" && schemeId == "${t}"].concepts[]._ref,\n      "topConcepts": *[_type=="skosConceptScheme" && schemeId == "${t}"].topConcepts[]._ref\n    }`);return function(e){const{schemeId:t,concepts:n,topConcepts:i,expanded:o,browseOnly:r}=e;return{filter:"(_id in $concepts\n              || _id in $topConcepts)",params:{concepts:n,topConcepts:i,schemeId:t},expanded:o,browseOnly:r}}({schemeId:t,concepts:o,topConcepts:r,expanded:e?.expanded,browseOnly:e?.browseOnly})}},pt=e=>{const{schemeId:t,branchId:n=null}=e||{};return dt(t),function(e){if(!e||"string"!=typeof e)throw new Error("Invalid or missing branchId: branch Id must be a string")}(n),async i=>{const o=i?.getClient({apiVersion:"2023-01-01"});if(!o)throw new Error("Client not available");const{concepts:r}=await o.fetch('{      \n        "concepts": *[\n          _id in *[_type=="skosConceptScheme" && schemeId == $schemeId].concepts[]._ref\n            && ($branchId in broader[]->conceptId\n              || $branchId in broader[]->broader[]->conceptId\n              || $branchId in broader[]->broader[]->broader[]->conceptId\n              || $branchId in broader[]->broader[]->broader[]->broader[]->conceptId\n              || $branchId in broader[]->broader[]->broader[]->broader[]->broader[]->conceptId)\n          ]._id\n      }',{schemeId:t,branchId:n});return function(e){const{schemeId:t,branchId:n,concepts:i,expanded:o,browseOnly:r}=e;return{filter:"_id in $concepts",params:{concepts:i,schemeId:t,branchId:n},expanded:o,browseOnly:r}}({schemeId:t,branchId:n,concepts:r,expanded:e?.expanded,browseOnly:e?.browseOnly})}};function ht({document:e}){return{filter:"!(_id in $broader || _id in $related || _id == $self)",params:{self:X(Q(e._id)),broader:Array.isArray(e?.broader)?e.broader.map(({_ref:e})=>e):[],related:Array.isArray(e?.related)?e.related.map(({_ref:e})=>e):[]}}}var mt=[l({name:"baseIri",title:"Base URI",type:"url",validation:e=>e.required().error("Please supply a base URI in the format 'http://example.com/'"),description:"The root URI (Uniform Resource Identifier) used to create unique concept identifiers.",components:{input:function(t){const n=e(["conceptId"]),i=e(["schemeId"]);return C(_,{gap:2,children:[t.renderDefault(t),I(x,{muted:!0,size:1,children:C(v,{children:[I("strong",{children:"RDF URI: "}),t.value?t.value:"[base URI not defined] ",n||i||" [identifier not assigned]"]})})]})}}})];function ut(e,t=[],n){return p({name:"skosConcept",title:"Concept",type:"document",icon:me,initialValue:async(t,n)=>{if(e)return{baseIri:e,broader:[],related:[]};const{getClient:i}=n;return{baseIri:await i({apiVersion:"2021-03-25"}).fetch("\n        *[(_type == 'skosConcept' || _type == 'skosConceptScheme') && defined(baseIri)]| order(_createdAt desc)[0].baseIri\n      ")??void 0,broader:[],related:[]}},fields:[l({name:"prefLabel",title:"Preferred Label",type:"string",description:"The preferred lexical label for this concept.",validation:e=>e.required().custom((e,t)=>{const{getClient:n}=t;return n({apiVersion:"2025-06-10"}).withConfig({perspective:"raw"}).fetch(`*[_type == "skosConcept" && prefLabel == "${e}" && !(_id in path("drafts.**") || _id in path("versions.**"))][0]._id`).then(e=>{return n=e,i=t.document?._id,!(n&&!i?.includes(n))||"Preferred Label must be unique.";var n,i})})}),l({name:"definition",title:"Definition",type:"text",description:"A complete explanation of the intended meaning of the concept.",rows:3}),l({name:"example",title:"Examples",type:"text",description:"An example of the use of the concept.",rows:3}),l({name:"scopeNote",title:"Scope Note",type:"text",description:"A brief statement on the intended meaning of this concept, especially as an indication of how the use of the concept is limited in indexing practice.",rows:3}),l({name:"altLabel",title:"Alternate Label(s)",type:"array",description:"Synonyms, near-synonyms, abbreviations, and acronyms to a concept.",of:[{type:"string"}],validation:e=>e.unique()}),l({name:"hiddenLabel",title:"Hidden Label(s)",type:"array",description:"Character strings that need to be accessible to applications performing text-based indexing and search operations, but which should not be displayed to end users.",of:[{type:"string"}],validation:e=>e.unique()}),...mt,l({name:"conceptId",title:"Identifier",description:"Generate or re-generate the identifier for this concept according to parameters set in Taxonomy Manager plugin options. Note that this changes the concept's URI, which is not advisable if the concept is already in use in production. Use with caution.",type:"string",initialValue:ye(n),hidden:({document:e})=>!!e?.conceptId&&!n?.regenUi,readOnly:({document:e})=>!!e?.conceptId,components:{input:e=>I(be,{...e,ident:n})}}),l({name:"broader",title:"Broader Concept(s)",description:"Create hierarchy between concepts, for example to create category/subcategory, part/whole, or class/instance relationships.",type:"array",of:[{type:"reference",to:{type:"skosConcept"},options:{filter:ht}}]}),l({name:"related",title:"Related Concept(s)",description:'Indicate that two concepts are inherently "related", but that one is not in any way more general than the other.',type:"array",of:[{type:"reference",to:[{type:"skosConcept"}],options:{filter:ht}}]}),...t,l({name:"historyNote",title:"History Notes",type:"text",description:"Significant changes to the meaning or the form of this concept.",rows:3}),l({name:"editorialNote",title:"Editorial Notes",type:"text",description:"Information to aid in administrative housekeeping, such as reminders of editorial work still to be done, or warnings in the event that future editorial changes might be made.",rows:3}),l({name:"changeNote",title:"Change Notes",type:"text",description:"Fine-grained changes to a concept, for the purposes of administration and maintenance.",rows:3})],orderings:[{title:"Top Concepts",name:"topConcept",by:[{field:"topConcept",direction:"desc"},{field:"prefLabel",direction:"asc"}]},{title:"Preferred Label",name:"prefLabel",by:[{field:"prefLabel",direction:"asc"}]}],preview:{select:{title:"prefLabel"},prepare:({title:e})=>({title:e,media:ue})}})}function ft(e,t=[],n){return p({name:"skosConceptScheme",title:"Concept Scheme",type:"document",icon:nt,initialValue:async(t,n)=>{if(e)return{baseIri:e};const{getClient:i}=n;return{baseIri:await i({apiVersion:"2021-03-25"}).fetch("\n        *[(_type == 'skosConcept' || _type == 'skosConceptScheme') && defined(baseIri)]| order(_createdAt desc)[0].baseIri\n      ")??void 0}},fields:[l({name:"title",title:"Title",type:"string",description:"Taxonomy schemes group concepts into defined sets, such as thesauri, classification schemes, or facets. Concepts may belong to many (or no) concept schemes, and you may create as many (or few) concept schemes as you like"}),l({name:"description",title:"Description",type:"text",rows:5,description:"Describe the intended use of this scheme."}),l({name:"controls",title:"Concept Management Controls",deprecated:{reason:"This field was used for a previous version of the plugin and is no longer needed. Remove the value to hide this field."},type:"boolean",readOnly:!0,hidden:({document:e})=>void 0===e?.controls,components:{input:at}}),...mt,l({name:"schemeId",title:"Identifier",description:"Generate or re-generate the identifier for this scheme according to parameters set in Taxonomy Manager plugin options. Note that this changes the scheme's URI, which is not advisable if the scheme already is use in production. Use with caution.",type:"string",initialValue:ye(n),hidden:({document:e})=>!!e?.schemeId&&!n?.regenUi,readOnly:({document:e})=>!!e?.schemeId,components:{input:e=>I(be,{...e,ident:n})}}),l({name:"topConcepts",title:"Top Concepts",type:"array",validation:e=>e.unique(),of:[h({type:"reference",to:[{type:"skosConcept"}]})],options:{sortable:!1}}),l({name:"concepts",title:"Concepts",type:"array",validation:e=>e.unique(),of:[h({type:"reference",to:[{type:"skosConcept"}]})],options:{sortable:!1}}),...t],preview:{select:{title:"title"},prepare:({title:e})=>({title:e,media:nt})}})}const gt=/_key\s*==\s*['"](.*)['"]/,yt=/^\d*:\d*$/,bt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ct=/_key\s*==\s*['"](.*)['"]/;function It(e){if("string"!=typeof e)throw Error("Path is not a string");let t=e.match(bt);if(!t)throw Error("Invalid path string");return t.map(vt)}function vt(e){return function(e){return"number"==typeof e||"string"==typeof e&&/^\[\d+\]$/.test(e)}(e)?function(e){return Number(e.replace(/[^\d]/g,""))}(e):function(e){return"string"==typeof e?gt.test(e.trim()):"object"==typeof e&&"_key"in e}(e)?function(e){return{_key:e.match(Ct)[1]}}(e):function(e){if("string"==typeof e&&yt.test(e))return!0;if(!Array.isArray(e)||2!==e.length)return!1;let[t,n]=e;return!("number"!=typeof t&&""!==t||"number"!=typeof n&&""!==n)}(e)?function(e){let[t,n]=e.split(":").map(e=>""===e?e:Number(e));return[t,n]}(e):e}const wt=({document:e})=>{const{selectedPerspectiveName:t}=r(),{routerPanesState:n,groupIndex:i,handleEditReference:o}=y(),c=m(),s=u(e.displayed?._id??""),a=O((e,t)=>{const r=n[i+1]?.[0].params||{},{parentRefPath:c}=r;o({id:e,type:t,parentRefPath:c?It(c):[""],template:{id:e}})},[n,i,o]),{data:d,loading:l,error:p}=$e('*[!(_type in ["skosConcept","skosConceptScheme"]) && references($refId)]{_id,_type,title}',{params:{refId:s},options:{perspective:t?[t]:"drafts"}});return l?I(k,{padding:5,children:C(S,{align:"center",direction:"column",gap:5,height:"fill",justify:"center",style:{paddingTop:"1rem"},children:[I(P,{muted:!0}),I(x,{muted:!0,size:1,children:"Loading usage…"})]})}):p?I(_,{padding:4,gap:5,children:I(Se,{tone:"caution",children:"There was en error fetching use data"})}):d?.length?I(k,{padding:4,paddingTop:4,children:C(_,{gap:2,children:[I(T,{borderBottom:!0,paddingTop:3,paddingBottom:3,children:I($,{paddingTop:1,children:C(x,{weight:"semibold",muted:!0,size:1,children:["Resource count (all schemes): ",d.length]})})}),I(_,{gap:1,children:d?.map(e=>{const t=c.get(e._type);return t&&I(V,{onClick:()=>a(e._id,e._type),padding:2,mode:"bleed",children:I(f,{value:e,schemaType:t,layout:"block"})},e._id)})})]})}):I(_,{padding:4,gap:5,children:I(Se,{children:"This concept is not currently in use"})})},_t=e=>e.list().title("Taxonomy Manager").items([e.documentTypeListItem("skosConceptScheme").title("Concept Schemes"),e.documentTypeListItem("skosConcept").title("Concepts")]),xt=(e={})=>{const t=t=>I(we.Provider,{value:{ident:e.ident},children:I(rt,{...t})});return(e,{schemaType:n})=>{switch(n){case"skosConceptScheme":return e.document().views([e.view.component(t).title("Tree View").icon(nt),e.view.form().icon(ge)]);case"skosConcept":return e.document().views([e.view.form().icon(ge),e.view.component(wt).title("Tagged Resources").icon(fe)]);default:return e.document().views([e.view.form().icon(ge)])}}},Vt=g(e=>{const{baseUri:t,customConceptFields:n,customSchemeFields:i,ident:o}=e||{};return{name:"taxonomyManager",options:e,schema:{types:[ut(t,n,o),ft(t,i,o)]},plugins:[b({name:"taxonomy",title:"Taxonomy",structure:_t,defaultDocumentNode:xt({ident:o}),icon:nt})]}});export{st as ArrayHierarchyInput,ct as ReferenceHierarchyInput,rt as TreeView,pt as branchFilter,lt as schemeFilter,Vt as taxonomyManager};
//# sourceMappingURL=/sm/7acd64e245d6f4d83377fa797a0864d5da8ff8d6c354938fae86e17097a3884b.map