#kivy 1.11.1
#:import utils kivy.utils
#:import Transition kivy.uix.screenmanager
#:import ButtonBehavior kivy.uix.behaviors
#:import utils kivy.utils
#:import ScrollEffect kivy.effects.scroll.ScrollEffect
#:import Factory kivy.factory.Factory

# Image Button
# For button alone define image attributes immediately below 'ImageButton' declaration.
# For button and label declare 'ImageButton' within the context of a BoxLayout with a
# vertical orientation, followed by a 'Label' declaration at equal indentation level.
<ImageButton@ButtonBehavior+Image+BoxLayout>:
    orientation: 'horizontal'


# Navigation Bar
# Do not change the order of the objects within each BoxLayout. Doing so will break the
# button color-changing functionality as the path to each widget is dependent on the
# ordering of their objects.
<ButtonBar@BoxLayout>:
    orientation: 'horizontal'

    # Landing Button
    BoxLayout:
        id: landing_button
        orientation: 'vertical'

        # Background
        canvas.before:
            Color:
                rgba: utils.get_color_from_hex('#73AB84')
            Rectangle:
                pos: self.pos
                size: self.size
        ImageButton:
            source: 'receipt_icon.png'
            size_hint_y: .7
            on_release: app.root.current = 'landing'
        Label:
            text: 'Scan'
            color: utils.get_color_from_hex("#000000")
            size_hint_y: .3
            font_size: 14

    # Pantry Button
    BoxLayout:
        id: pantry_button
        orientation: 'vertical'

        # Background
        canvas.before:
            Color:
                rgba: utils.get_color_from_hex('#73AB84')
            Rectangle:
                pos: self.pos
                size: self.size
        ImageButton:
            source: 'apple_icon.png'
            size_hint_y: .7
            on_release: app.root.current = 'pantry'
        Label:
            text: 'Pantry'
            color: utils.get_color_from_hex("#000000")
            size_hint_y: .3
            font_size: 14

    # Ideas Button
    BoxLayout:
        id: ideas_button
        orientation: 'vertical'

        # Background
        canvas.before:
            Color:
                rgba: utils.get_color_from_hex('#73AB84')
            Rectangle:
                pos: self.pos
                size: self.size
        ImageButton:
            source: 'light_icon.png'
            size_hint_y: .7
            on_release: app.root.current = 'ideas'
        Label:
            text: 'Ideas'
            color: utils.get_color_from_hex("#000000")
            size_hint_y: .3
            font_size: 14

    # Settings Button
    BoxLayout:
        id: settings_button
        orientation: 'vertical'

        # Background
        canvas.before:
            Color:
                rgba: utils.get_color_from_hex('#73AB84')
            Rectangle:
                pos: self.pos
                size: self.size
        ImageButton:
            source: 'settings_icon.png'
            size_hint_y: .7
            on_release: app.root.current = 'settings'
        Label:
            text: 'Settings'
            color: utils.get_color_from_hex("#000000")
            size_hint_y: .3
            font_size: 14

    # About Button
    BoxLayout:
        id: about_button
        orientation: 'vertical'

        # Background
        canvas.before:
            Color:
                rgba: utils.get_color_from_hex('#73AB84')
            Rectangle:
                pos: self.pos
                size: self.size
        ImageButton:
            source: 'about_icon.png'
            size_hint_y: .7
            on_release: app.root.current = 'about'
        Label:
            text: 'About'
            color: utils.get_color_from_hex("#000000")
            size_hint_y: .3
            font_size: 14


# Menu Item
# Widget to be added to the ScrollMenu. Has two labels that can be accessed to display text.
<MenuItem@BoxLayout>:
    orientation: 'horizontal'
    size_hint_y: None
    height: dp(30)

    # Padding
    Label:
        size_hint_x: .1

    # Used Apple Button
    ImageButton:
        source: 'red_apple_icon.png'
        on_release: root.remove()
        size_hint_x: .075

    # Expired Apple Button
    ImageButton:
        source: 'brown_apple_icon.png'
        on_release: root.remove()
        size_hint_x: .075

    # Padding
    Label:
        size_hint_x: .05

    # Produce Label
    Label:
        id: produce_label
        text: "ProduceName (Quantity)"
        color: utils.get_color_from_hex("#000000")
        font_size: 18
        size_hint_x: .7

    # Expiration Label
    Label:
        id: expiration_label
        text: "TimeUntilExpired"
        color: utils.get_color_from_hex("#000000")
        font_size: 18
        size_hint_x: .2

    # Padding
    Label:
        size_hint_x: .1


# Scroll Menu
# Modification of ScrollView widget that allows for greater than one children.
<ScrollMenu@ScrollView>:
    GridLayout:
        id: grid_layout
        size_hint_y: None
        cols: 1

Manager:
    transition: Transition.NoTransition()
    LandingPage:
    PantryPage:
        id: pantry_page
    IdeasPage:
    SettingsPage:
    AboutPage:
    InputPage:
        id: input_page



<LandingPage>:
    name: 'landing'

    Camera:
        id: camera
        resolution: (self.size[0],self.size[1])
        play: True
        allow_stretch: True

    BoxLayout:
        orientation: 'vertical'

        Label:
            size_hint_y: 1

        # Capture Button
        ImageButton:
            source: 'capture_icon.png'
            size_hint_y: .2
            on_release:
                root.capture()
                app.root.current = 'pantry'
                app.root.ids.pantry_page.read_image()


        BoxLayout:
            orientation: 'horizontal'
            size_hint_y: .2

            # Pantry Button
            BoxLayout:
                orientation: 'vertical'
                ImageButton:
                    source: 'apple_icon_colored.png'
                    on_release: app.root.current = 'pantry'
                Label:
                    text: 'Pantry'
                    color: utils.get_color_from_hex("#FFFFFF")
                    font_size: 22

            # Ideas Button
            BoxLayout:
                orientation: 'vertical'
                ImageButton:
                    source: 'light_icon_colored.png'
                    on_release: app.root.current = 'ideas'
                Label:
                    text: 'Ideas'
                    color: utils.get_color_from_hex("#FFFFFF")
                    font_size: 22


<PantryPage>:
    name: 'pantry'

    # Background
    canvas.before:
        Color:
            rgba: utils.get_color_from_hex("#99D19C")
        Rectangle:
            pos: self.pos
            size: self.size

    BoxLayout:
        orientation: 'vertical'

        # Title Bar
        BoxLayout:
            orientation: 'horizontal'
            size_hint_y: .1
            canvas.before:
                Color:
                    rgba: utils.get_color_from_hex("#73AB84")
                Rectangle:
                    size: self.size
                    pos: self.pos
            Label:
                size_hint_x: .2
            Label:
                id: title_text
                text: 'Pantry'
                color: utils.get_color_from_hex("#000501")
                font_size: 30
                size_hint_x: .6

            ImageButton:
                on_release: app.root.current = 'input'
                source: 'plus_icon.png'
                size_hint_x: .2

        #Subtitle Bar
        BoxLayout:
            orientation: 'horizontal'
            size_hint_y: .05
            Label:
                size_hint_x: .1
            Label:
                text: 'Used/Expired'
                color: utils.get_color_from_hex("#000000")
                bold: True
                size_hint_x: .15
            Label:
                size_hint_x: .05
            Label:
                text: 'Item'
                color: utils.get_color_from_hex("#000000")
                bold: True
                size_hint_x: .7
            Label:
                text: 'Time Remaining'
                color: utils.get_color_from_hex("#000000")
                bold: True
                size_hint_x: .2
            Label:
                size_hint_x: .1

        # Produce Menu
        ScrollMenu
            id: scroll_menu
            size_hint_y: .75

        # Navigation Bar
        ButtonBar:
            id: nav_bar
            size_hint_y: .15


<IdeasPage>:
    name: 'ideas'

    # Background
    canvas.before:
        Color:
            rgba: utils.get_color_from_hex("#99D19C")
        Rectangle:
            pos: self.pos
            size: self.size

    BoxLayout:
        orientation: 'vertical'

        # Title Bar
        Label:
            text: 'Ideas'
            color: utils.get_color_from_hex("#000501")
            size_hint_y: .1
            font_size: 30
            canvas.before:
                Color:
                    rgba: utils.get_color_from_hex("#73AB84")
                Rectangle:
                    size: self.size
                    pos: self.pos

        # Content
        Label:
            color: utils.get_color_from_hex("#000501")
            size_hint_y: .8

        # Navigation Bar
        ButtonBar:
            id: nav_bar
            size_hint_y: .15


<SettingsPage>:
    name: 'settings'

    # Background
    canvas.before:
        Color:
            rgba: utils.get_color_from_hex("#99D19C")
        Rectangle:
            pos: self.pos
            size: self.size

    BoxLayout:
        orientation: 'vertical'

        # Title Bar
        Label:
            text: 'Settings'
            color: utils.get_color_from_hex("#000501")
            size_hint_y: .1
            font_size: 30
            canvas.before:
                Color:
                    rgba: utils.get_color_from_hex("#73AB84")
                Rectangle:
                    size: self.size
                    pos: self.pos

        # Content
        Label:
            color: utils.get_color_from_hex("#000501")
            size_hint_y: .8

        # Navigation Bar
        ButtonBar:
            id: nav_bar
            size_hint_y: .15


<AboutPage>
    name: 'about'

    # Background
    canvas.before:
        Color:
            rgba: utils.get_color_from_hex("#99D19C")
        Rectangle:
            pos: self.pos
            size: self.size

    BoxLayout:
        orientation: 'vertical'

        # Title Bar
        Label:
            text: 'About'
            color: utils.get_color_from_hex("#000501")
            size_hint_y: .1
            font_size: 30
            canvas.before:
                Color:
                    rgba: utils.get_color_from_hex("#73AB84")
                Rectangle:
                    size: self.size
                    pos: self.pos

        # Content
        Label:
            text: 'Icons from https://icons8.com'
            color: utils.get_color_from_hex("#000501")
            size_hint_y: .8

        # Navigation Bar
        ButtonBar:
            id: nav_bar
            size_hint_y: .15


<InputPage>:
    name: 'input'
    id: input_widget

    # Background
    canvas.before:
        Color:
            rgba: utils.get_color_from_hex("#99D19C")
        Rectangle:
            pos: self.pos
            size: self.size

    BoxLayout:
        orientation: 'vertical'

        # Title Bar
        Label:
            text: 'Manual Input'
            color: utils.get_color_from_hex("#000501")
            size_hint_y: .1
            font_size: 30
            canvas.before:
                Color:
                    rgba: utils.get_color_from_hex("#73AB84")
                Rectangle:
                    size: self.size
                    pos: self.pos

        # Content
        BoxLayout:
            orientation: 'vertical'
            size_hint_y: .8
            Label
            # Input
            BoxLayout:
                orientation: 'horizontal'
                Label:
                    text: 'Produce Type:'
                    color: utils.get_color_from_hex("#000501")
                    size_hint_x: .4
                # Input Box
                TextInput:
                    id: produce_input
                    multiline: False
                    hint_text: 'i.e. Apple'
                    input_type: 'text'
                    size_hint_x: .4
                    cursor_color: utils.get_color_from_hex("#73AB84")
                    text_color: utils.get_color_from_hex("#73AB84")
                Label:
                    size_hint_x: .2
            Label

        # Button Bar
        BoxLayout:
            orientation: 'horizontal'
            size_hint_y: .15

            # Cancel Button
            BoxLayout:
                orientation: 'vertical'
                # Background
                canvas.before:
                    Color:
                        rgba: utils.get_color_from_hex('#73AB84')
                    Rectangle:
                        pos: self.pos
                        size: self.size
                ImageButton:
                    source: 'cancel_icon.png'
                    size_hint_y: .7
                    on_release: app.root.current = 'pantry'
                Label:
                    text: 'Cancel'
                    color: utils.get_color_from_hex("#000000")
                    size_hint_y: .3
                    font_size: 14

            #  Submit Button
            BoxLayout:
                orientation: 'vertical'
                # Background
                canvas.before:
                    Color:
                        rgba: utils.get_color_from_hex('#73AB84')
                    Rectangle:
                        pos: self.pos
                        size: self.size
                ImageButton:
                    source: 'submit_icon.png'
                    size_hint_y: .7
                    on_release:
                        app.root.current = 'pantry'
                        root.text_entered()

                Label:
                    text: 'Submit'
                    color: utils.get_color_from_hex("#000000")
                    size_hint_y: .3
                    font_size: 14

