import React from 'react';
import GapReportChart from 'trc-client-core/src/report/GapReportChart';
import {learningPlanCsvUrl} from 'trc-client-core/src/constants/url';
import PrintChartView from 'trc-client-core/src/report/PrintChartView';
import Permissions from 'trc-client-core/src/user/Permissions';

var GapReportViewToyotaForLife = React.createClass({
    displayName: 'GapReportViewToyotaForLife',
    contextTypes: {
        location: React.PropTypes.object
    },
    render() {
        var {location} = this.context;
        var props = {
            location: location,
            sort: location.query.sort,
            filter: location.query.filter,
            view: this.props.params.gapReportView || 'grid'
        };

        if(Permissions.isPermission('REPORT_VISIBILITY_REGIONAL') && (!props.location.query.dealerCode)) {
            return null;
        }

        return (
            <div>
                <h2>Sales & Fleet</h2>
                <GapReportChart {...props} {...props.location.query} learningPlanId="tfl_sales_fleet" />
                {this.renderPrint('tfl_sales_fleet')}

                <h2>Guest Experience</h2>
                <GapReportChart {...props} {...props.location.query} learningPlanId="tfl_guest_experience" />
                {this.renderPrint('tfl_guest_experience')}

                <h2>Management & Administration</h2>
                <GapReportChart {...props} {...props.location.query} learningPlanId="tfl_management_administration" />
                {this.renderPrint('tfl_management_administration')}

                <h2>Service</h2>
                <GapReportChart {...props} {...props.location.query} learningPlanId="tfl_service" />
                {this.renderPrint('tfl_service')}

                <h2>Parts</h2>
                <GapReportChart {...props} {...props.location.query} learningPlanId="tfl_parts" />
                {this.renderPrint('tfl_parts')}

                <h2>Other</h2>
                <GapReportChart {...props} {...props.location.query} learningPlanId="tfl_other" />
                {this.renderPrint('tfl_other')}
            </div>
        );
    },

    renderPrint(learningPlanId) {
        return <PrintChartView href={learningPlanCsvUrl({learningPlanId})}/>;
    }
});

export default GapReportViewToyotaForLife
