import PropTypes from "prop-types";
import React from "react";
import { Link } from "react-router-dom";
import { ExternalLink } from "../../../base";
import { ReferenceItemInfo } from "./Info";

export const ClonedFrom = ({ id, name }) => (
    <ReferenceItemInfo>
        <strong>Cloned From </strong>
        <Link to={`/refs/${id}`}>{name}</Link>
        <small>This reference was cloned from another reference in your Virtool instance.</small>
    </ReferenceItemInfo>
);

export const ImportedFrom = ({ name }) => (
    <ReferenceItemInfo>
        <strong>Imported From</strong>
        <span>{name}</span>
        <small>This reference was imported from a Virtool reference file.</small>
    </ReferenceItemInfo>
);

export const RemotesFrom = ({ slug }) => (
    <ReferenceItemInfo>
        <span>
            <strong>Remotes from </strong>
            <ExternalLink href={`https://www.github.com/${slug}`}>{slug}</ExternalLink>
        </span>
        <small>This reference can be kept in sync with a reference published on GitHub.</small>
    </ReferenceItemInfo>
);

export const ReferenceItemOrigin = ({ clonedFrom, importedFrom, remotesFrom }) => {
    if (clonedFrom) {
        return <ClonedFrom {...clonedFrom} />;
    }

    if (importedFrom) {
        return <ImportedFrom {...importedFrom} />;
    }

    if (remotesFrom) {
        return <RemotesFrom {...remotesFrom} />;
    }

    return (
        <span>
            <strong>Created</strong>
            <span>No File</span>
        </span>
    );
};

ReferenceItemOrigin.propTypes = {
    clonedFrom: PropTypes.object,
    importedFrom: PropTypes.object,
    remotesFrom: PropTypes.object
};

@@ -1404,16 +1404,48 @@
 eturn (%0A
+        %3CReferenceItemInfo%3E%0A    
         
@@ -1455,32 +1455,36 @@
 an%3E%0A            
+   
+ 
 %3Cstrong%3ECreated%3C
@@ -1482,16 +1482,30 @@
 %3ECreated
+ from scratch.
 %3C/strong
@@ -1523,42 +1523,114 @@
    %3C
+/
 span%3E
-No File%3C/span%3E%0A        %3C/span
+%0A            %3Csmall%3EPopulate this reference with OTUs to use it.%3C/small%3E%0A        %3C/ReferenceItemInfo
 %3E%0A  

Fix ugly reference item when reference was created from scratch