import './GenerativeFillButtons.scss';
import * as React from 'react';
import ReactLoading from 'react-loading';
import { Button, IconButton, Type } from 'browndash-components';
import { AiOutlineInfo } from 'react-icons/ai';
import { bgColor } from './imageEditorUtils/imageEditorConstants';
import { ImageEditTool, ImageToolType } from './imageEditorUtils/imageEditorInterfaces';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { SettingsManager } from '../../../util/SettingsManager';

interface ButtonContainerProps {
    onClick: () => Promise<void>;
    loading: boolean;
    onReset: () => void;
    btnText: string;
}

export function ApplyFuncButtons({ loading, onClick: getEdit, onReset, btnText }: ButtonContainerProps) {
    return (
        <div className="generativeFillBtnContainer">
            <Button text="RESET" type={Type.PRIM} color={SettingsManager.userVariantColor} onClick={onReset} />
            {loading ? (
                <Button
                    text={btnText}
                    type={Type.TERT}
                    color={SettingsManager.userVariantColor}
                    icon={<ReactLoading type="spin" color="#ffffff" width={20} height={20} />}
                    iconPlacement="right"
                    onClick={() => {
                        if (!loading) getEdit();
                    }}
                />
            ) : (
                <Button
                    text={btnText}
                    type={Type.TERT}
                    color={SettingsManager.userVariantColor}
                    onClick={() => {
                        if (!loading) getEdit();
                    }}
                />
            )}
            <IconButton
                type={Type.SEC}
                color={SettingsManager.userVariantColor}
                tooltip="Open Documentation"
                icon={<AiOutlineInfo size="16px" />}
                onClick={() => window.open('https://brown-dash.github.io/Dash-Documentation/features/generativeai/#editing', '_blank')}
            />
        </div>
    );
}

export function ImageToolButton(tool: ImageEditTool, isActive: boolean, selectTool: (type: ImageToolType) => void) {
    return (
        <div className="imageEditorButtonContainer">
            <Button
                style={{ width: '100%' }}
                text={tool.name}
                type={Type.TERT}
                color={isActive ? SettingsManager.userVariantColor : bgColor}
                icon={<FontAwesomeIcon icon={tool.icon} />}
                onClick={() => {
                    selectTool(tool.type);
                }}
            />
        </div>
    );
}
