import dash 
from dash.dependencies import ALL, MATCH
from dash.exceptions import PreventUpdate
from dash.dependencies import Input, State, Output
from data_handler import DEBUG, FREQ
from data_handler import cache, cache_timeout

@dash.callback(
             Output({'type':'caret', 'index': MATCH}, 'style'),
             [Input({'type':'collapse', 'index': MATCH}, 'is_open')],
)
def rotate_section_caret(collapse_open):
    """ Rotates section 3 menu caret """
    rotation = 0 if collapse_open else 180
    rotate_caret = {
      'transform': 'rotate({}deg)'.format(rotation),
      '-ms-transform': 'rotate({}deg)'.format(rotation),
      '-webkit-transform': 'rotate({}deg)'.format(rotation)
    }
    return rotate_caret


# @dash.callback(
#     [Output('slider-interval', 'disabled'),
#      Output('slider-interval', 'n_intervals'),
#      Output('open-timeseries', 'style'),
#      Output('btn-play', 'className'),
#      ],
#     Input('btn-play', 'n_clicks'),
#     [State('slider-interval', 'disabled'),
#      State('model-slider-graph', 'value')],
#     prevent_initial_call=True
#     )
# def start_stop_autoslider(n_play, disabled, value):
#     """ Play/Pause map animation """
#     ctx = dash.callback_context
#     if DEBUG: print("VALUE", value)
#     if not value:
#         value = 0
#
#     if ctx.triggered:
#         button_id = ctx.triggered[0]["prop_id"].split(".")[0]
#         if button_id == 'btn-play' and disabled:
#             ts_style = { 'display': 'none' }
#             return not disabled, int(value/FREQ), ts_style, 'fa fa-pause text-center'
#         elif button_id == 'btn-play' and not disabled:
#             ts_style = { 'display': 'block' }
#             return not disabled, int(value/FREQ), ts_style, 'fa fa-play text-center'
#
#     raise PreventUpdate
# start/stop animation

# @dash.callback(
#     [Output('obs-slider-interval', 'disabled'),
#      Output('obs-slider-interval', 'n_intervals'),
#      Output('btn-obs-play', 'className')],
#     Input('btn-obs-play', 'n_clicks'),
#     [State('obs-slider-interval', 'disabled'),
#      State('obs-slider-graph', 'value')],
#     prevent_initial_call=True
# )
# @cache.memoize(timeout=cache_timeout)
# def start_stop_obs_autoslider(n_play, disabled, value):
#     """ Play/Pause map animation """
#     ctx = dash.callback_context
#     if DEBUG: print("VALUE", value)
#     if not value:
#         value = 0
#     if ctx.triggered:
#         button_id = ctx.triggered[0]["prop_id"].split(".")[0]
#         if button_id == 'btn-obs-play' and disabled:
#             return not disabled, int(value), 'fa fa-pause text-center'
#         elif button_id == 'btn-obs-play' and not disabled:
#             return not disabled, int(value), 'fa fa-play text-center'
#
#     raise PreventUpdate

# @dash.callback(
#     [Output({'type':'slider-interval', 'id': MATCH}, 'disabled'),
#      Output({'type':'slider-interval', 'id': MATCH}, 'n_intervals'),
#      Output('open-timeseries', 'style'),
#      Output({ 'tag': 'btn-play', 'id': MATCH}, 'className'),
#      ],
#     [Input({ 'tag': 'btn-play', 'id': MATCH}, 'n_clicks')],
#     [State({'type':'slider-interval', 'id': MATCH}, 'disabled'),
#      State({ 'tag': 'time-step-slider-graphs', 'index': MATCH}, 'value')],
#     prevent_initial_call=True
#     )
# def start_stop_autoslider(n_play, disabled, value):
#     """ Play/Pause map animation """
#     ctx = dash.callback_context
#     if DEBUG: print("VALUE", value)
#     if not value:
#         value = 0
#
#     if ctx.triggered:
#         import pdb; pdb.set_trace()
#         import json
#         button_id = json.loads(ctx.triggered[0]["prop_id"].split(".")[0])
#         # if button_id == 'btn-play' and disabled:
#         if button_id['tag'] == 'btn-play' and disabled:
#             ts_style = { 'display': 'none' }
#             return not disabled, int(value/FREQ), ts_style, ['fa fa-pause text-center']
#         elif button_id['tag'] == 'btn-play' and not disabled:
#             ts_style = { 'display': 'block' }
#             return not disabled, int(value/FREQ), ts_style, ['fa fa-play text-center']
#
#     raise PreventUpdate
