import{r as f,j as n}from"./iframe-p4aYZyoq.js";import{M as T}from"./message-BpVwJIll.js";import"./preload-helper-BDBacUwf.js";import"./index-Dx18ixSn.js";import"./information-CdWOuYio.js";import"./success-DH0eGKjE.js";import"./times-DeY5Bu0x.js";const he=/^\s*[>;](.*)$/m;function ge(e){if(!e)return;const[,r=""]=e.match(he)||[],[m]=r.split(" ").filter(Boolean);return m}const Se="ARNDCEQGHILKMFPSTWYV",Te="ACGTU",k=/[EQILFPXJ]/gi,L=/U/gi,A=Object.freeze({missingSequence:Object.freeze({valid:!1,message:"The sequence is missing"}),invalidSequence:Object.freeze({valid:!1,message:"The sequence is invalid"}),shortSequence:Object.freeze({valid:!1,message:"The sequence is too short"})}),Ae=Object.freeze({valid:!0}),Ue=/^[A-NP-Z*.-]+$/i,Ce=e=>/.*[>;]+/gm.test(e);function Ge(e){return e.split(/^[>;].*\n?$/gm).map(r=>r.replace(/\s/g,"")).filter(Boolean)}function ye(e,r){if(L.test(e)&&!k.test(e))return"na";if(k.test(e)&&!L.test(e))return"aa";const s={};for(let h=0;h<e.length;h+=1){const t=e.charAt(h);s[t]?s[t]+=1:s[t]=1}const i=100/e.length;return Object.keys(s).reduce((h,t)=>(Se.includes(t)&&(h.aa+=s[t]*i),Te.includes(t)&&(h.na+=s[t]*i),h),{aa:0,na:0}).na>r?"na":"aa"}function je(e){const r=/[^A-Z]|[NX]/gi,m=e.replace(r,"").toUpperCase();return ye(m,90)}function xe(e,r,m){if(!e)return A.missingSequence;let a;if(Ce(e)){const o=Ge(e);o.length>0&&([a]=o)}else a=e.replace(/\s/g,"");if(!a)return A.missingSequence;if(r&&a.length<r)return A.shortSequence;if(!Ue.test(a))return A.invalidSequence;const i=je(a);return i?{...Ae,likelyType:i,sequence:e}:A.invalidSequence}const be=/\s+/g,R=()=>({raw:"",name:"",header:"",sequence:""}),P=(e,r,m)=>({...xe(e.sequence,r),...e}),Ee=(e,r,m)=>{const a=[];let s=R();for(const i of e.split(`
`)){if(he.test(i)){if(s.sequence&&(a.push(P(s,r)),s=R()),s.header)s.header+=`
`;else{const o=ge(i);o&&(s.name=o)}s.header+=i}else s.sequence+=i.replace(be,"");s.raw&&(s.raw+=`
`),s.raw+=i}return s.raw&&a.push(P(s,r)),a},q=({value:e,onChange:r,placeholder:m,defaultValue:a,minimumLength:s,minimumSequences:i,maximumSequences:o,noDuplicateID:h})=>{var M,w,W;const[t,qe]=f.useState([]),U=f.useCallback(g=>{const S=Ee(g,s);qe(S),r==null||r(S)},[r,s]);f.useEffect(()=>{e||e===""?U(e):(a||a==="")&&U(a)},[e,a,U]);const D=[],V=[];if(t.length>1||t.length===1&&t[0].sequence.length>10){const g=new Map,S=new Map,_=new Map;for(const[l,c]of t.entries()){const{valid:u,message:d,name:p}=c;if(!u&&d){const N=(M=g.get(d))!=null?M:[];N.push({sequenceIndex:l+1,sequenceObject:c}),g.set(d,N)}const F=(w=S.get(p))!=null?w:[];F.push({sequenceIndex:l+1,sequenceObject:c}),S.set(p,F);const I=c.sequence.toLowerCase(),O=(W=_.get(I))!=null?W:[];O.push({sequenceIndex:l+1,sequenceObject:c}),_.set(I,O)}for(const[l,c]of g.entries())D.push(n.jsxs(T,{level:"failure","data-testid":"sequence-submission-error",children:["Error: ",l,". Sequence",c.length===1?" ":"s ",c.map(({sequenceIndex:u,sequenceObject:{name:d}},p)=>n.jsxs(f.Fragment,{children:[p?", ":"",u," ",d?n.jsxs(n.Fragment,{children:["(",n.jsx("code",{children:d}),")"]}):""]},u))]},c.map(({sequenceIndex:u})=>u).join("-")));if(h)for(const[l,c]of S.entries())c.length>1&&V.push(n.jsxs(T,{level:"failure",children:["Sequences"," ",c.map(({sequenceIndex:u},d)=>{let p="";return d&&(c.length===2?p=" and ":p=d+1===c.length?", and ":", "),n.jsxs(f.Fragment,{children:[p,u]},u)})," ","have the same identifier (",n.jsx("code",{children:l}),"), this is invalid."]},c.map(({sequenceIndex:u})=>u).join("-id-")));for(const l of _.values())l.length>1&&V.push(n.jsxs(T,{level:"info",children:["Sequences"," ",l.map(({sequenceIndex:c,sequenceObject:{name:u}},d)=>{let p="";return d&&(l.length===2?p=" and ":p=d+1===l.length?", and ":", "),n.jsxs(f.Fragment,{children:[p,c," ",u?n.jsxs(n.Fragment,{children:["(",n.jsx("code",{children:u}),")"]}):""]},c)})," ","are identical, this might be unintended."]},l.map(({sequenceIndex:c})=>c).join("-seq-")))}const fe=o&&t.length>o&&n.jsxs(T,{level:"failure",children:["Your input contains ",t.length," sequences which exceeds the submission limit of ",o,"."]})||i&&t.length&&t.length<i&&n.jsxs(T,{level:"failure",children:["Your input contains ",t.length," sequence",t.length===1?"":"s",". At least ",i," ","sequences are required."]})||t[0]&&t[0].sequence.length>10&&n.jsxs(T,{level:"info",children:["Your input contains ",t.length," sequence",t.length===1?"":"s","."]});return n.jsxs(n.Fragment,{children:[n.jsx("textarea",{className:"sequence-submission-input",value:e,onChange:g=>U(g.target.value),placeholder:m,"data-testid":"sequence-submission-input",defaultValue:a,spellCheck:"false"}),fe,D,V]})};try{sequencesubmission.displayName="sequencesubmission",sequencesubmission.__docgenInfo={description:"",displayName:"sequencesubmission",props:{value:{defaultValue:null,description:"The value, if needed.",name:"value",required:!1,type:{name:"string"}},defaultValue:{defaultValue:null,description:"The default value, if needed.",name:"defaultValue",required:!1,type:{name:"string"}},onChange:{defaultValue:null,description:"Triggers when the value is changed.",name:"onChange",required:!1,type:{name:"((processed: SequenceObject[]) => void)"}},placeholder:{defaultValue:null,description:"Display text when the textarea is empty.",name:"placeholder",required:!1,type:{name:"string"}},minimumLength:{defaultValue:null,description:"Minimum acceptable length for a sequence",name:"minimumLength",required:!1,type:{name:"number"}},minimumSequences:{defaultValue:null,description:"Minimum acceptable number of sequences",name:"minimumSequences",required:!1,type:{name:"number"}},maximumSequences:{defaultValue:null,description:"Maximum acceptable number of sequences",name:"maximumSequences",required:!1,type:{name:"number"}},noDuplicateID:{defaultValue:null,description:"Error if the same ID is used twice",name:"noDuplicateID",required:!1,type:{name:"boolean"}}}}}catch{}const Re={title:"Forms/Sequence Submission",component:q},C={render:()=>n.jsx(q,{placeholder:"Enter a sequence..."})},G={render:()=>n.jsx(q,{placeholder:"Enter a sequence...",defaultValue:"ACTGUACTGUACTGU+"})},ve=`> sequence_1
ACTGUACTGUACTGU
> sequence_2
ACTGAUTTGUATTGUUUGU
`,y={render:()=>n.jsx(q,{placeholder:"Enter a sequence...",defaultValue:ve})},Ve=`> sequence_1
ACTGUACTGUACTGU
> sequence_2
ACTGAUTTGUATTGUUUGU
> sequence_3
ACTGUACTGUACTGU
`,j={render:()=>n.jsx(q,{placeholder:"Enter a sequence...",defaultValue:Ve})},_e=`> sequence_1
ACTGUACTGUACTGU`,x={render:()=>n.jsx(q,{placeholder:"Enter a sequence...",defaultValue:_e,minimumSequences:2})},De=`> sequence_1
ACTGUACTGUACTGU
> sequence_2
ACTGAUTTGUATTGUUUGU
> sequence_3
ACTGCTGUAGU
> sequence_4
GUACTGU
`,b={render:()=>n.jsx(q,{placeholder:"Enter a sequence...",defaultValue:De,maximumSequences:3})},Me=`> sequence 1
ACTGUACTGUACTGU
> sequence 2
ACTGAUTTGUATTGUUUGU
> sequence 3
ACTGCTGUAGU
> sequence_4
GUACTGU
`,E={render:()=>n.jsx(q,{placeholder:"Enter a sequence...",defaultValue:Me,noDuplicateID:!0})},we=()=>{const[e,r]=f.useState("ACTG"),[m,a]=f.useState();return n.jsxs("form",{children:[n.jsx(q,{placeholder:"Enter a sequence...",value:e,onChange:s=>{var i,o;r((i=s[0])==null?void 0:i.sequence),a((o=s[0])==null?void 0:o.likelyType)}}),n.jsxs("p",{children:["Sequence:",n.jsx("output",{children:e})]}),n.jsxs("p",{children:["Likely type:",n.jsx("output",{children:m})]}),n.jsx("input",{type:"reset",onClick:s=>{s.preventDefault(),r("")}}),n.jsx("input",{type:"button",value:"async load sequence",onClick:()=>r("ACTGUACTGUACTGU")})]})},v={render:we};var z,B,Y;C.parameters={...C.parameters,docs:{...(z=C.parameters)==null?void 0:z.docs,source:{originalSource:`{
  render: () => <SequenceSubmissionComponent placeholder="Enter a sequence..." />
}`,...(Y=(B=C.parameters)==null?void 0:B.docs)==null?void 0:Y.source}}};var $,H,Q;G.parameters={...G.parameters,docs:{...($=G.parameters)==null?void 0:$.docs,source:{originalSource:`{
  render: () => <SequenceSubmissionComponent placeholder="Enter a sequence..." defaultValue="ACTGUACTGUACTGU+" />
}`,...(Q=(H=G.parameters)==null?void 0:H.docs)==null?void 0:Q.source}}};var X,Z,J;y.parameters={...y.parameters,docs:{...(X=y.parameters)==null?void 0:X.docs,source:{originalSource:`{
  render: () => <SequenceSubmissionComponent placeholder="Enter a sequence..." defaultValue={multipleSequences1} />
}`,...(J=(Z=y.parameters)==null?void 0:Z.docs)==null?void 0:J.source}}};var K,ee,ne;j.parameters={...j.parameters,docs:{...(K=j.parameters)==null?void 0:K.docs,source:{originalSource:`{
  render: () => <SequenceSubmissionComponent placeholder="Enter a sequence..." defaultValue={multipleSequences2} />
}`,...(ne=(ee=j.parameters)==null?void 0:ee.docs)==null?void 0:ne.source}}};var se,re,te;x.parameters={...x.parameters,docs:{...(se=x.parameters)==null?void 0:se.docs,source:{originalSource:`{
  render: () => <SequenceSubmissionComponent placeholder="Enter a sequence..." defaultValue={multipleSequences3} minimumSequences={2} />
}`,...(te=(re=x.parameters)==null?void 0:re.docs)==null?void 0:te.source}}};var ae,ce,ie;b.parameters={...b.parameters,docs:{...(ae=b.parameters)==null?void 0:ae.docs,source:{originalSource:`{
  render: () => <SequenceSubmissionComponent placeholder="Enter a sequence..." defaultValue={multipleSequences4} maximumSequences={3} />
}`,...(ie=(ce=b.parameters)==null?void 0:ce.docs)==null?void 0:ie.source}}};var ue,oe,le;E.parameters={...E.parameters,docs:{...(ue=E.parameters)==null?void 0:ue.docs,source:{originalSource:`{
  render: () => <SequenceSubmissionComponent placeholder="Enter a sequence..." defaultValue={multipleSequences5} noDuplicateID />
}`,...(le=(oe=E.parameters)==null?void 0:oe.docs)==null?void 0:le.source}}};var de,pe,me;v.parameters={...v.parameters,docs:{...(de=v.parameters)==null?void 0:de.docs,source:{originalSource:`{
  render: DynamicallyChangeValueRender
}`,...(me=(pe=v.parameters)==null?void 0:pe.docs)==null?void 0:me.source}}};const Pe=["SequenceSubmission","WithInvalidSequenceError","WithMultipleSequences","WithMultipleSequencesWarning","WithTooFewSequencesError","WithTooManySequencesError","WithDuplicateIdentifiersError","DynamicallyChangeValue"];export{v as DynamicallyChangeValue,C as SequenceSubmission,E as WithDuplicateIdentifiersError,G as WithInvalidSequenceError,y as WithMultipleSequences,j as WithMultipleSequencesWarning,x as WithTooFewSequencesError,b as WithTooManySequencesError,Pe as __namedExportsOrder,Re as default};
