//Lib
import React from 'react';
import classes from '../WizardStep1/WizardStep1.module.css';
import { IconWand } from '@tabler/icons-react';
import CopyButton from '../../UI/CopyButton/CopyButton';

function WizardStep4(props) {
    ////Vars
    //Needed to generate command for borg over LAN instead of WAN if env vars are set and option enabled.
    let HOSTNAME;
    let SSH_SERVER_PORT;
    if (
        props.selectedOption.lanCommand &&
        process.env.NEXT_PUBLIC_HOSTNAME_LAN &&
        process.env.NEXT_PUBLIC_SSH_SERVER_PORT_LAN
    ) {
        HOSTNAME = process.env.NEXT_PUBLIC_HOSTNAME_LAN;
        SSH_SERVER_PORT = process.env.NEXT_PUBLIC_SSH_SERVER_PORT_LAN;
    } else {
        HOSTNAME = process.env.NEXT_PUBLIC_HOSTNAME;
        SSH_SERVER_PORT = process.env.NEXT_PUBLIC_SSH_SERVER_PORT;
    }

    const configBorgmatic = `location:
    # List of source directories to backup.
    source_directories:
        - /your-repo-to-backup
        - /another/repo-to-backup

repositories:
    # Paths of local or remote repositories to backup to.
    - ssh://${props.selectedOption.unixUser}@${HOSTNAME}:${SSH_SERVER_PORT}/./${props.selectedOption.repository}

storage:
    archive_name_format: '{HOSTNAME}-documents-{now}'
    encryption_passphrase: "YOUR PASSPHRASE"

retention:
    # Retention policy for how many backups to keep.
    keep_daily: 7
    keep_weekly: 4
    keep_monthly: 6

consistency:
    # List of checks to run to validate your backups.
    checks:
        - name: repository
        - name: archives
        - frequency: 2 weeks

#hooks:
    # Custom preparation scripts to run.
    #before_backup:
    #   - prepare-for-backup.sh

    # Databases to dump and include in backups.
    #postgresql_databases:
    #   - name: users

    # Third-party services to notify you if backups aren't happening.
    #healthchecks: https://hc-ping.com/be067061-cf96-4412-8eae-62b0c50d6a8c`;

    return (
        <div className={classes.container}>
            <h1>
                <IconWand className={classes.icon} />
                Automate your backup
            </h1>
            <div className={classes.description}>
                The official borgbackup project provides a script in its
                documentation&nbsp;
                <a
                    href='https://borgbackup.readthedocs.io/en/stable/quickstart.html#automating-backups'
                    rel='noreferrer'
                    target='_blank'
                >
                    right here
                </a>
                .
            </div>

            <div className={classes.separator} />
            <h2>Vorta</h2>
            <div className={classes.description}>
                If you are using the Vorta graphical client, please refer
                to&nbsp;
                <a
                    href='https://vorta.borgbase.com/usage/#scheduling-automatic-backups'
                    rel='noreferrer'
                    target='_blank'
                >
                    this documentation
                </a>
                .
            </div>

            <h2>Borgmatic</h2>
            <div className={classes.description}>
                If you are using Borgmatic, you can check&nbsp;
                <a
                    href='https://torsion.org/borgmatic/docs/how-to/set-up-backups/#autopilot'
                    rel='noreferrer'
                    target='_blank'
                >
                    this documentation&nbsp;
                </a>
                and <b>adapt</b> and use the following script :
            </div>
            <div
                style={{
                    display: 'flex',
                    flexDirection: 'row',
                    justifyContent: 'flex-start',
                }}
            >
                <div className={classes.code}>{configBorgmatic}</div>
                <div
                    style={{
                        margin: '15px 0 auto 0',
                        display: 'flex',
                        alignContent: 'center',
                    }}
                >
                    <CopyButton dataToCopy={configBorgmatic} size={32} />
                </div>
            </div>
        </div>
    );
}

export default WizardStep4;
