# encoding: utf-8

"""
Gherkin step implementations for shape-related features.
"""

from __future__ import absolute_import, print_function

from behave import given, when, then

from pptx import Presentation
from pptx.chart.chart import Chart
from pptx.dml.color import RGBColor
from pptx.enum.dml import MSO_FILL, MSO_THEME_COLOR
from pptx.enum.shapes import MSO_SHAPE, MSO_SHAPE_TYPE
from pptx.util import Inches

from helpers import cls_qname, saved_pptx_path, test_pptx, test_text


# given ===================================================

@given('a connector')
def given_a_connector(context):
    prs = Presentation(test_pptx('shp-common-props'))
    sld = prs.slides[0]
    context.shape = sld.shapes[4]


@given('a graphic frame')  # shouldn't matter, but this one contains a table
def given_a_table(context):
    prs = Presentation(test_pptx('shp-common-props'))
    sld = prs.slides[0]
    context.shape = sld.shapes[2]


@given('a graphic frame containing a chart')
def given_a_graphic_frame_containing_a_chart(context):
    prs = Presentation(test_pptx('shp-access-chart'))
    sld = prs.slides[0]
    context.shape = sld.shapes[0]


@given('a graphic frame containing a table')
def given_a_graphic_frame_containing_a_table(context):
    prs = Presentation(test_pptx('shp-access-chart'))
    sld = prs.slides[1]
    context.shape = sld.shapes[0]


@given('a group shape')
def given_a_group_shape(context):
    prs = Presentation(test_pptx('shp-common-props'))
    sld = prs.slides[0]
    context.shape = sld.shapes[3]


@given('a picture')
def given_a_picture(context):
    prs = Presentation(test_pptx('shp-common-props'))
    sld = prs.slides[0]
    context.shape = sld.shapes[1]


@given('a rotated {shape_type}')
def given_a_rotated_shape_type(context, shape_type):
    shape_idx = {
        'shape':         0,
        'picture':       1,
        'graphic frame': 2,
        'group shape':   3,
        'connector':     4,
    }[shape_type]
    prs = Presentation(test_pptx('shp-common-props'))
    sld = prs.slides[1]
    context.shape = sld.shapes[shape_idx]


@given('a shape')
def given_a_shape(context):
    prs = Presentation(test_pptx('shp-common-props'))
    sld = prs.slides[0]
    context.shape = sld.shapes[0]


@given('a {shape_type} on a slide')
def given_a_shape_on_a_slide(context, shape_type):
    shape_idx = {
        'shape':         0,
        'picture':       1,
        'graphic frame': 2,
        'group shape':   3,
        'connector':     4,