import React from 'react'
import PropTypes from 'prop-types'
import ConfirmationTemplate from 'react-uikit/alert/templates/confirmation'

const warning =
    'If you proceed, you will be removed from this portfolio. The rest of the team members will still be able to use this portfolio.'

const PortfolioLeaveConfirm = ({
    currentUser,
    portfolio,
    portfolioId,
    isShowing,
    leavePortfolio,
    onDismiss,
}) => {
    const onConfirm = () => {
        onDismiss()
        leavePortfolio({
            portfolioId,
            userIds: portfolio.userIds.filter((id) => id !== currentUser.id),
        })
    }

    const message = portfolio?.courseSectionId ? (
        <React.Fragment>
            {warning}
            <br />
            You are currently part of a challenge or classroom and will be
            removed from participation.
        </React.Fragment>
    ) : (
        warning
    )
    return (
        <ConfirmationTemplate
            body={message}
            cancelText="Cancel"
            confirmText="Leave"
            dismissOnConfirm={false}
            header="Are you sure?"
            isShowing={isShowing}
            onConfirm={onConfirm}
            onDismiss={onDismiss}
            variant="negative"
        />
    )
}

PortfolioLeaveConfirm.propTypes = {
    currentUser: PropTypes.object,
    isShowing: PropTypes.bool,
    leavePortfolio: PropTypes.func,
    portfolio: PropTypes.object,
    portfolioId: PropTypes.string,
    showAccountDeactivation: PropTypes.func,
    onDismiss: PropTypes.func,
}

export default PortfolioLeaveConfirm
