import{j as o}from"./jsx-runtime-Dfk2JFgj.js";import{r as n}from"./index-CWN_QRa1.js";import{F as m}from"./index-DNsi8NHw.js";import"./index-CIVavKlu.js";import"./index-DllfNvuz.js";import"./DefaultPropsProvider-BPu7lNPC.js";import"./CheckGroup-BpaEcK_0.js";import"./v4-CtRu48qb.js";import"./index-6WYjB5r3.js";import"./index-Bk93qgka.js";import"./index-DnVHLn3F.js";import"./index-Cj3pldWQ.js";import"./tiny-invariant-CopsF_GD.js";import"./iframe-BT4Dhm0c.js";import"./index-DgIb9kCw.js";const _={title:"Components/FileUpload",component:m,argTypes:{id:{table:{disable:!0}},value:{table:{disable:!0}},onChange:{table:{disable:!0}},name:{table:{disable:!0}},onReadFile:{table:{disable:!0}},onClick:{table:{disable:!0}},uploadedAttachment:{table:{disable:!0}},uploadAttachment:{table:{disable:!0}},isMultiple:{table:{disable:!0}}}},x=e=>{const[l,i]=n.useState([]),[c,g]=n.useState([]),h=async a=>{const f=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(a.fileKey.name)),s={id:Math.floor(Math.random()*1e4),repositoryId:200002734,repositoryType:"AWS",repositoryCode:"staging-files.gpstrackit.com",repositoryPath:"staging-files.gpstrackit.com",fileKey:`${f}`,originalName:a.fileKey.name,__typename:"Attachment"};l.length>0?i([...l,s]):i([s]),g([s])};return o.jsx("div",{style:{width:"430px"},children:o.jsx(m,{label:e.label,maxSize:e.maxSize,helpText:e.helpText,maxSizeMessage:e.maxSizeMessage,filesExtensions:e.filesExtensions,isMultiple:e.isMultiple,isDisabled:e.isDisabled,placeholder:e.placeholder,style:e.style,onChange:a=>{i(a),console.log("onChange:",a)},value:l,uploadedAttachment:c,loadingUploadFile:e.loadingUploadFile,uploadAttachment:a=>{h(a),console.log("Uploading file: ",a.fileKey.name)}})})},t=x.bind({});t.args={filesExtensions:".jpg, .png, .txt",loadingUploadFile:!1,isMultiple:!1,isDisabled:!1,label:"attachments",helpText:"jpg, png, gif, txt, doc, docx, pdf, csv, xls, xlsx. 4MB",placeholder:"select_files",maxSize:.01,maxSizeMessage:"Max file size reached"};var r,p,d;t.parameters={...t.parameters,docs:{...(r=t.parameters)==null?void 0:r.docs,source:{originalSource:`args => {
  const [data, setData] = useState<{}[]>([]);
  const [prevData, setPrevData] = useState<{}[]>([]);
  const handleUploadedFile = async file => {
    const hash = await crypto.subtle.digest("SHA-1", new TextEncoder().encode(file.fileKey.name));
    const tempData = {
      "id": Math.floor(Math.random() * 10000),
      "repositoryId": 200002734,
      "repositoryType": "AWS",
      "repositoryCode": "staging-files.gpstrackit.com",
      "repositoryPath": "staging-files.gpstrackit.com",
      "fileKey": \`\${hash}\`,
      "originalName": file.fileKey.name,
      "__typename": "Attachment"
    };
    if (data.length > 0) {
      setData([...data, tempData]);
    } else {
      setData([tempData]);
    }
    setPrevData([tempData]);
  };
  return <div style={{
    width: "430px"
  }}>
            <FileUpload
    //{...args}
    label={args.label} maxSize={args.maxSize} helpText={args.helpText} maxSizeMessage={args.maxSizeMessage} filesExtensions={args.filesExtensions} isMultiple={args.isMultiple} isDisabled={args.isDisabled} placeholder={args.placeholder} style={args.style}
    //onReadFile={(file) => console.log("Reading file: ", file)}
    onChange={files => {
      setData(files);
      console.log("onChange:", files);
    }} value={data} uploadedAttachment={prevData} loadingUploadFile={args.loadingUploadFile} uploadAttachment={file => {
      handleUploadedFile(file);
      console.log("Uploading file: ", file.fileKey.name);
    }} />
        </div>;
}`,...(d=(p=t.parameters)==null?void 0:p.docs)==null?void 0:d.source}}};const j=["SingleFile"];export{t as SingleFile,j as __namedExportsOrder,_ as default};
