<commit_before>import React, { Component, PropTypes } from 'react';
import { formatMonth, formatYear, isSameDay, isDayOutsideMonth, isDayDisabled, getWeekArray, navigateMonth } from './utils';

// Dependencies
import classNames from 'classnames';

// Styles
import './calendar.scss';

const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

class Day extends Component {
    
    render() {

        const {month, date, disabledDays} = this.props;

        let className = 'cal__day';
        let modifiers = [];
        
        const isToday = isSameDay(date, new Date());

        if(isToday) {
            modifiers.push('today');
        }

        const isOutside = isDayOutsideMonth(date, month);

        if(isOutside) {
            modifiers.push('outside');
        }

        const isDisabled = isDayDisabled(date, disabledDays);

        if(isDisabled) {
            modifiers.push('disabled');
        }

        className += modifiers.map(modifier => ` ${className}--${modifier}`).join('');

        // if(isOutside && !enableOutsideDays) {
        //     return <div key={`outside${i}`} className={className}></div>;
        // }
        
        //const { onDayMouseEnter, onDayMouseLeave, onDayTouchTap, onDayClick } = this.props;
        
        // let tabIndex = null;

        // if((onDayTouchTap || onDayClick) && !isOutside) {
        //     tabIndex = -1;

        //     // focus on the first day of the month
        //     if(day.getDate() === 1) {
        //         tabIndex = this.props.tabIndex;
        //     }
        // }

        return(
            <td
              role="presentation"
              aria-label={date}
              onClick={this.props.onClick}
              className={className}
              >
                {date.getDate()}
            </td>
        );
    }
}

class Week extends Component {

    static defaultProps = {
        onDaySelect: () => {}
    }

    render() {

        let date = this.props.date,
            month = this.props.month;
        
        let days = this.props.days.map(day =>
            <Day
                key={day}
                date={day}
                month={month}
                onClick={this.props.onDaySelect.bind(null, day)}
                disabledDays={this.props.disabledDays}
            />
        );

        return(
            <tr className="cal__week">
                {days}
            </tr>
        );
    }
}

class Calendar extends Component {

    static propTypes = {
        
    }

    static defaultProps = {
        trimWeekdays: 1,
        // Array passed in options to disable dates
        //datesToDisable: [ 1, 4, 7, [2015,3,8], [2015,3,19], new Date(2015,3,26) ]
        datesToDisable: [new Date('07-05-2015'), new Date('07-06-2015'), new Date('07-07-2015')]
    }
    
    constructor(props) {
        super(props);
        this.state = {
            month: new Date()
        };
    }
    
    renderWeekdays() {
        
        var getDays = () => {
            return WEEKDAYS.map((weekday, index) => {
                let trim = this.props.trimWeekdays;
                let weekdayTrimmed = trim !== null ? weekday.substring(0, parseInt(trim)) : weekday;
                return <th key={index} scope="col" title={weekday}>{weekdayTrimmed}</th>
            });
        };
        
        return(
            <thead>
                <tr>
                    {getDays()}
                </tr>
            </thead>
        );
    }

    renderWeeksInMonth() {

        const month = this.state.month;

        let weeks = getWeekArray(month).map((week, index) =>
            <Week
                key={week[0].toString()}
                days={week}
                month={this.state.month}
                onDaySelect={this.props.onDaySelect}
                disabledDays={this.props.datesToDisable}
            />
        );

        return (
            <tbody>
                {weeks}
            </tbody>
        );
    }
    
    navigate(direction) {
        let month = this.state.month;
        this.setState({ month: navigateMonth(month, direction) });
    }

    diff(arr1, arr2) {
        
        let ret = [];

        for(i in this) {
            if(arr2.indexOf(arr1[i]) > -1) {
                ret.push(arr1[i]);
            }
        }
        return ret;
    }
    
    getModifiers(modifiers) {
        
        let arr = [];
        let len = modifiers ? modifiers.length : -1;
        
        if(len < 0) return null;
        
        for(let i = 0; i < len; i++) {
            arr.push('cal--' + modifiers[i].replace(/\s/g, ''));
        }
        
        return arr;
    }
    
    render() {
        
        let modifiers = this.getModifiers(this.props.modifiers && this.props.modifiers.split(','));
        let classes = classNames('cal', modifiers, this.props.className);

        let monthLabel = formatMonth(this.state.month);
        let yearLabel = formatYear(this.state.month);
        
        return (
            <div className={classes}>
                <header className="cal__header"><commit_msg>added flexible options for dates to disable<commit_after>import React, { Component, PropTypes } from 'react';
import { formatMonth, formatYear, isSameDay, isDayOutsideMonth, isDayDisabled, getWeekArray, navigateMonth } from './utils';

// Dependencies
import classNames from 'classnames';

// Styles
import './calendar.scss';

const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

class Day extends Component {
    
    render() {

        const {month, date, disabledDays} = this.props;

        let className = 'cal__day';
        let modifiers = [];
        
        const isToday = isSameDay(date, new Date());

        if(isToday) {
            modifiers.push('today');
        }

        const isOutside = isDayOutsideMonth(date, month);

        if(isOutside) {
            modifiers.push('outside');
        }

        const isDisabled = isDayDisabled(date, disabledDays);

        if(isDisabled) {
            modifiers.push('disabled');
        }

        className += modifiers.map(modifier => ` ${className}--${modifier}`).join('');

        // if(isOutside && !enableOutsideDays) {
        //     return <div key={`outside${i}`} className={className}></div>;
        // }
        
        //const { onDayMouseEnter, onDayMouseLeave, onDayTouchTap, onDayClick } = this.props;
        
        // let tabIndex = null;

        // if((onDayTouchTap || onDayClick) && !isOutside) {
        //     tabIndex = -1;

        //     // focus on the first day of the month
        //     if(day.getDate() === 1) {
        //         tabIndex = this.props.tabIndex;
        //     }
        // }

        return(
            <td
              role="presentation"
              aria-label={date}
              onClick={this.props.onClick}
              className={className}
              >
                {date.getDate()}
            </td>
        );
    }
}

class Week extends Component {

    static defaultProps = {
        onDaySelect: () => {}
    }

    render() {

        let date = this.props.date,
            month = this.props.month;
        
        let days = this.props.days.map(day =>
            <Day
                key={day}
                date={day}
                month={month}
                onClick={this.props.onDaySelect.bind(null, day)}
                disabledDays={this.props.disabledDays}
            />
        );

        return(
            <tr className="cal__week">
                {days}
            </tr>
        );
    }
}

function normalizeDates(month, mixed) {

    let dates = [];

    for(let i = mixed.length; i--;) {

        let mix = mixed[i];

        // if it's a Date object already then push it
        // and contiue
        if(mix instanceof Date) {
            dates.push(mix);
            continue;
        }

        // test if digit and in between current month
        // or test to block day of week out somehow
        // reference pickadate and how they do it
        // just block out day for now
        if(/^\d+$/.test(mix)) {
            dates.push(new Date(month.getFullYear(), month.getMonth(), mix));
            continue;
        }

        if(Array.isArray(mix)) {
            dates.push(new Date(mix[0], mix[1], mix[2]));
            continue;
        }
    }

    return dates;
}

let d1 = new Date(2015,6,9);
let d2 = [ 1, 4, 7, [2015,6,8], [2015,6,19], new Date(2015,6,26) ];
let myDates = normalizeDates(d1, d2);

class Calendar extends Component {

    static propTypes = {
        
    }

    static defaultProps = {
        trimWeekdays: 1,
        datesToDisable: myDates
    }
    
    constructor(props) {
        super(props);
        this.state = {
            month: new Date()
        };
    }
    
    renderWeekdays() {
        
        var getDays = () => {
            return WEEKDAYS.map((weekday, index) => {
                let trim = this.props.trimWeekdays;
                let weekdayTrimmed = trim !== null ? weekday.substring(0, parseInt(trim)) : weekday;
                return <th key={index} scope="col" title={weekday}>{weekdayTrimmed}</th>
            });
        };
        
        return(
            <thead>
                <tr>
                    {getDays()}
                </tr>
            </thead>
        );
    }

    renderWeeksInMonth() {

        const month = this.state.month;

        let weeks = getWeekArray(month).map((week, index) =>
            <Week
                key={week[0].toString()}
                days={week}
                month={this.state.month}
                onDaySelect={this.props.onDaySelect}
                disabledDays={this.props.datesToDisable}
            />
        );

        return (
            <tbody>
                {weeks}
            </tbody>
        );
    }
    
    navigate(direction) {
        let month = this.state.month;
        this.setState({ month: navigateMonth(month, direction) });
    }
    
    getModifiers(modifiers) {
        
        let arr = [];
        let len = modifiers ? modifiers.length : -1;
        
        if(len < 0) return null;
        
        for(let i = 0; i < len; i++) {
            arr.push('cal--' + modifiers[i].replace(/\s/g, ''));
        }
        
        return arr;
    }
    
    render() {
        
        let modifiers = this.getModifiers(this.props.modifiers && this.props.modifiers.split(','));
        let classes = classNames('cal', modifiers, this.props.className);

        let monthLabel = formatMonth(this.state.month);
        let yearLabel = formatYear(this.state.month);
        
        return (
            <div className={classes}>
                <header className="cal__header">
{'fraction_non_alphanumeric': 0.13338902812587022, 'fraction_numerical': 0.009746588693957114, 'mean_word_length': 1.4842056721235877, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6918630', 'n_tokens_mistral': 3242, 'n_tokens_neox': 3030, 'n_words': 630}