"""Defines tab settings."""

from prompt_toolkit.filters import buffer_has_focus

from euporie.core.config import add_setting

add_setting(
    name="backup_on_save",
    group="euporie.core.tabs.base",
    flags=["--backup-on-save"],
    type_=bool,
    help_="Create backups before saving files",
    default=False,
    description="""
        Determines whether a backup file should be created before saving a file.

        If set to ``True``, the original file will be copied to a new file with the
        same name but prefixed with ``.`` and suffixed with ``.bak`` before writing the
        updated contents.
    """,
)

add_setting(
    name="kernel_name",
    group="euporie.core.tabs.kernel",
    flags=["--kernel-name", "--kernel"],
    type_=str,
    help_="The name of the kernel to start by default",
    default="python3",
    description="""
        The name of the kernel selected automatically by the console app or in new
        notebooks. If set to an empty string, the user will be asked which kernel
        to launch.
    """,
)

add_setting(
    name="record_cell_timing",
    group="euporie.core.tabs.kernel",
    title="cell timing recording",
    flags=["--record-cell-timing"],
    type_=bool,
    help_="Should timing data be recorded in cell metadata.",
    default=False,
    schema={
        "type": "boolean",
    },
    description="""
        When set, execution timing data will be recorded in cell metadata.
    """,
)

add_setting(
    name="show_remote_inputs",
    group="euporie.core.tabs.kernel",
    flags=["--show-remote-inputs"],
    type_=bool,
    help_="Display inputs sent to the kernel by other clients",
    default=True,
    description="""
        If set to `True`, all code input sent to the kernel by any client will be
        displayed.

        If set to `False`, only inputs sent to the kernel by the current instance
        of euporie will be displayed, and all other inputs will be ignored.

    """,
)

add_setting(
    name="show_remote_outputs",
    group="euporie.core.tabs.kernel",
    flags=["--show-remote-outputs"],
    type_=bool,
    help_="Display kernel outputs triggered by other clients",
    default=True,
    description="""
        If set to `False`, only outputs generated by code input from the current
        instance of euporie will be displayed, and all other outputs will be
        ignored.

        If set to `True`, all outputs generated by the kernel will be
        displayed.
    """,
)

# euporie.core.tabs.notebook

add_setting(
    name="save_widget_state",
    group="euporie.core.tabs.notebook",
    flags=["--save-widget-state"],
    type_=bool,
    help_="Save a notebook's widget state in the notebook metadata",
    default=True,
    description="""
        When set to ``True``, the state of any widgets in the current notebook will
        be saves in the notebook's metadata. This enables widgets to be displayed
        when the notebook is re-opened without having to re-run the notebook.
    """,
)

add_setting(
    name="max_notebook_width",
    group="euporie.core.tabs.notebook",
    flags=["--max-notebook-width"],
    type_=int,
    help_="Maximum width of notebooks",
    default=120,
    schema={
        "minimum": 1,
    },
    description="""
        The maximum width at which to display a notebook.
    """,
)

add_setting(
    name="expand",
    group="euporie.core.tabs.notebook",
    flags=["--expand"],
    type_=bool,
    help_="Use the full width to display notebooks",
    default=False,
    description="""
        Whether the notebook page should expand to fill the available width
    """,
    cmd_filter=~buffer_has_focus,
)
