# Released under the MIT License. See LICENSE for details.
#
"""Bits of utility functionality related to co-op levels."""

import bauiv1 as bui
from bauiv1 import builtinassets
from bauiv1 import _commonassets, classicassets


class CoopLevelLockedWindow(bui.Window):
    """Window showing that a level is locked."""

    def __init__(self, name: bui.LangStr, dep_name: bui.LangStr):
        width = 550.0
        height = 250.0
        lock_tex = classicassets.textures.lock.get()
        assert bui.app.classic is not None
        uiscale = bui.app.ui_v1.uiscale
        super().__init__(
            root_widget=bui.containerwidget(
                size=(width, height),
                transition='in_right',
                scale=(
                    1.7
                    if uiscale is bui.UIScale.SMALL
                    else 1.3 if uiscale is bui.UIScale.MEDIUM else 1.0
                ),
            )
        )
        bui.textwidget(
            parent=self._root_widget,
            position=(150 - 20, height * 0.63),
            size=(0, 0),
            h_align='left',
            v_align='center',
            text=classicassets.strings.coop.level_is_locked(level=name),
            maxwidth=400,
            color=(1, 0.8, 0.3, 1),
            scale=1.1,
        )
        bui.textwidget(
            parent=self._root_widget,
            position=(150 - 20, height * 0.48),
            size=(0, 0),
            h_align='left',
            v_align='center',
            text=(classicassets.strings.coop).level_must_be_completed_first(
                level=dep_name
            ),
            maxwidth=400,
            color=bui.app.ui_v1.infotextcolor,
            scale=0.8,
        )
        bui.imagewidget(
            parent=self._root_widget,
            position=(56 - 20, height * 0.39),
            size=(80, 80),
            texture=lock_tex,
            opacity=1.0,
        )
        btn = bui.buttonwidget(
            parent=self._root_widget,
            position=((width - 140) / 2, 30),
            size=(140, 50),
            label=_commonassets.strings.actions.ok,
            on_activate_call=self._ok,
        )
        bui.containerwidget(
            edit=self._root_widget, selected_child=btn, start_button=btn
        )
        builtinassets.audio.error.get().play()

    def _ok(self) -> None:
        bui.containerwidget(edit=self._root_widget, transition='out_left')
