<?php
/**
 * Brentwood Timetable — schedule data (developer-maintained).
 *
 * This mirrors the hardcoded weekly schedule from the legacy Laravel app
 * (resources/js/components/timetable.vue → daysData) plus the Academic Block
 * Rotation table. In the original site this grid was NOT editable by the
 * client — it lived in code — so we keep that here. The per-category CONTENT
 * panels (header/body/link) are likewise static and developer-maintained, in
 * bw_timetable_panels() below.
 *
 * To change the schedule: edit the arrays below. Times are 24h "H:i". Each
 * block's `cat` is a category slug; colours/labels for categories live in the
 * `categories` map. `bw_timetable_grid()` returns the whole structure.
 *
 * @package kadence-child
 */

defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'bw_timetable_grid' ) ) {
	function bw_timetable_grid() {
		// Category slug => label + colour (swatch behind each block). Colours are
		// the EXACT Tailwind values from the legacy CSS, so the grid matches
		// brentwood.ca. The slug also keys the content panels (bw_timetable_panels()).
		$categories = array(
			'academics'  => array( 'label' => 'Academics',  'color' => '#e11d48' ), // rose-600
			'arts'       => array( 'label' => 'Arts',        'color' => '#8b5cf6' ), // violet-500
			'athletics'  => array( 'label' => 'Athletics',   'color' => '#10b981' ), // emerald-500
			'food'       => array( 'label' => 'Food',        'color' => '#fb923c' ), // orange-400
			'advisor'    => array( 'label' => 'Advisor',     'color' => '#ef4444' ), // red-500
			'tutorial'   => array( 'label' => 'Tutorial',    'color' => '#ef4444' ), // red-500
			'assembly'   => array( 'label' => 'Assembly',    'color' => '#3b82f6' ), // blue-500
			'sleep-in'   => array( 'label' => 'Sleep-In',    'color' => '#0ea5e9' ), // sky-500
			'prep'       => array( 'label' => 'Prep',        'color' => '#ef4444' ), // red-500
			'activities' => array( 'label' => 'Activities',  'color' => '#0ea5e9' ), // sky-500
			'brunch'     => array( 'label' => 'Brunch',      'color' => '#eab308' ), // yellow-500
			'free-time'  => array( 'label' => 'Free Time',   'color' => '#0ea5e9' ), // sky-500
		);

		// b( name, start, end, category-slug ) — one block.
		$b = function ( $name, $start, $end, $cat ) {
			return array( 'name' => $name, 'start' => $start, 'end' => $end, 'cat' => $cat );
		};

		$days = array(
			array(
				'name'   => 'Monday',
				'blocks' => array(
					$b( 'Period 1', '08:15', '09:35', 'academics' ),
					$b( 'Break', '09:35', '09:55', 'food' ),
					$b( 'Advisor', '09:55', '10:20', 'advisor' ),
					$b( 'Period 2', '10:25', '11:45', 'academics' ),
					$b( 'Period 3', '11:55', '13:15', 'academics' ),
					$b( 'Lunch', '13:15', '14:00', 'food' ),
					$b( 'Arts Block 1', '14:00', '14:55', 'arts' ),
					$b( 'Arts Block 2', '15:00', '15:55', 'arts' ),
					$b( 'Arts Block 3', '16:00', '16:55', 'arts' ),
					$b( 'Arts Block 4', '17:00', '17:55', 'arts' ),
					$b( 'Dinner', '17:30', '18:30', 'food' ),
					$b( 'Academic Prep', '19:30', '21:30', 'prep' ),
				),
			),
			array(
				'name'   => 'Tuesday',
				'blocks' => array(
					$b( 'Period 1', '08:15', '09:35', 'academics' ),
					$b( 'Break', '09:35', '09:55', 'food' ),
					$b( 'Tutorial', '09:55', '10:20', 'tutorial' ),
					$b( 'Period 2', '10:25', '11:45', 'academics' ),
					$b( 'Period 3', '11:55', '13:15', 'academics' ),
					$b( 'Lunch', '13:15', '14:00', 'food' ),
					$b( 'Athletics', '14:00', '17:55', 'athletics' ),
					$b( 'Dinner', '17:30', '18:30', 'food' ),
					$b( 'Academic Prep', '19:30', '21:30', 'prep' ),
				),
			),
			array(
				'name'   => 'Wednesday',
				'blocks' => array(
					$b( 'Sleep In', '08:15', '09:25', 'sleep-in' ),
					$b( 'Period 1', '09:30', '10:35', 'academics' ),
					$b( 'Break', '10:35', '10:55', 'food' ),
					$b( 'Period 2', '10:55', '12:00', 'academics' ),
					$b( 'Period 3', '12:10', '13:15', 'academics' ),
					$b( 'Lunch', '13:15', '14:00', 'food' ),
					$b( 'Arts Block 1', '14:00', '14:55', 'arts' ),
					$b( 'Arts Block 2', '15:00', '15:55', 'arts' ),
					$b( 'Arts Block 3', '16:00', '16:55', 'arts' ),
					$b( 'Arts Block 4', '17:00', '17:55', 'arts' ),
					$b( 'Dinner', '17:30', '18:30', 'food' ),
					$b( 'Academic Prep', '19:30', '21:30', 'prep' ),
				),
			),
			array(
				'name'   => 'Thursday',
				'blocks' => array(
					$b( 'Period 1', '08:15', '09:35', 'academics' ),
					$b( 'Break', '09:35', '09:55', 'food' ),
					$b( 'Assembly', '09:55', '10:20', 'assembly' ),
					$b( 'Period 2', '10:25', '11:45', 'academics' ),
					$b( 'Period 3', '11:55', '13:15', 'academics' ),
					$b( 'Lunch', '13:15', '14:00', 'food' ),
					$b( 'Athletics', '14:00', '17:55', 'athletics' ),
					$b( 'Dinner', '17:30', '18:30', 'food' ),
					$b( 'Academic Prep', '19:30', '21:30', 'prep' ),
				),
			),
			array(
				'name'   => 'Friday',
				'blocks' => array(
					$b( 'Period 1', '08:15', '09:35', 'academics' ),
					$b( 'Break', '09:35', '09:55', 'food' ),
					$b( 'Tutorial', '09:55', '10:20', 'tutorial' ),
					$b( 'Period 2', '10:25', '11:45', 'academics' ),
					$b( 'Period 3', '11:55', '13:15', 'academics' ),
					$b( 'Lunch', '13:15', '14:00', 'food' ),
					$b( 'Arts Block 1', '14:00', '14:55', 'arts' ),
					$b( 'Arts Block 2', '15:00', '15:55', 'arts' ),
					$b( 'Arts Block 3', '16:00', '16:55', 'arts' ),
					$b( 'Arts Block 4', '17:00', '17:55', 'arts' ),
					$b( 'Dinner', '17:30', '18:30', 'food' ),
					$b( 'Academic Prep', '19:30', '21:30', 'prep' ),
				),
			),
			array(
				'name'   => 'Saturday',
				'blocks' => array(
					$b( 'Period 1', '10:15', '11:00', 'academics' ),
					$b( 'Period 2', '11:10', '11:55', 'academics' ),
					$b( 'Period 3', '12:05', '12:50', 'academics' ),
					$b( 'Lunch', '12:50', '14:00', 'food' ),
					$b( 'Athletics', '14:00', '17:55', 'athletics' ),
					$b( 'Dinner', '17:30', '18:30', 'food' ),
					$b( 'Evening Activity', '19:30', '21:30', 'activities' ),
				),
			),
			array(
				'name'   => 'Sunday',
				'blocks' => array(
					$b( 'Light Breakfast', '08:15', '10:30', 'food' ),
					$b( 'Brunch', '10:30', '12:00', 'brunch' ),
					$b( 'Free Time / Interhouse', '12:00', '17:55', 'free-time' ),
					$b( 'Dinner', '17:30', '18:30', 'food' ),
				),
			),
		);

		// Academic Block Rotation — period (row) × academic day (column). Letters
		// A–F; colours per letter below. Mirrors the legacy static table.
		$rotation = array(
			'title'   => 'Academic Block Rotation',
			'days'    => array( 'Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5', 'Day 6', 'Saturday 1', 'Saturday 2' ),
			'periods' => array(
				'Period 1' => array( 'A', 'D', 'C', 'F', 'B', 'E', 'A', 'D' ),
				'Period 2' => array( 'B', 'E', 'A', 'D', 'C', 'F', 'B', 'E' ),
				'Period 3' => array( 'C', 'F', 'B', 'E', 'A', 'D', 'C', 'F' ),
			),
			// Exact Tailwind values from the legacy CSS (.block-a … .block-f).
			'colors'  => array(
				'A' => '#f97316', // orange-500
				'B' => '#3b82f6', // blue-500
				'C' => '#8b5cf6', // violet-500
				'D' => '#eab308', // yellow-500
				'E' => '#f43f5e', // rose-500
				'F' => '#22c55e', // green-500
			),
		);

		return array(
			'categories' => $categories,
			'days'       => $days,
			// Extension point: the ACF "Timetable Management" page overlays editable
			// rotation content (title, day headers, period letters, colours) here.
			// With no ACF data the developer defaults above pass through unchanged.
			'rotation'   => apply_filters( 'bw_timetable_rotation', $rotation ),
		);
	}
}

if ( ! function_exists( 'bw_timetable_panel_defaults' ) ) {
	/**
	 * Default per-category panel content. Used as the fallback AND as the source
	 * of the developer-controlled structural keys (`style`, `inline`) and the
	 * canonical category set. The editable text/images are overlaid from the ACF
	 * "Timetable Management" options page by bw_timetable_panels() — see
	 * inc/brentwood-timetable.php. Editing the options page does not touch this.
	 */
	function bw_timetable_panel_defaults() {
		// Per-category content panels — developer-maintained (static), pulled
		// verbatim from the live brentwood.ca timetable. Keyed by category slug
		// (matches the block 'cat' in bw_timetable_grid()). 'link' is left empty;
		// fill with an internal URL to show the CTA. Add panels by adding keys.
		return array(
			'academics' => array(
				'image'     => 26418,
				'images'    => array( 26418, 26419, 26420, 26421, 26422, 26423 ),
				'header'    => 'Academics',
				'body'      => '<p>The Brentwood timetable is focused around academics taking place in the morning, daily. Courses are taught Monday to Saturday, six days a week, from 8:15 am to 1:15 pm (Saturdays 10:15 am to 12:45 pm). Six academic blocks are rotated with three blocks per day on alternating days. A short break after the first class of the day, known as ‘Cookie Break’, gives students the chance to get a snack before finishing their morning classes. Tutorial blocks also take place on Tuesday and Friday mornings, where students have the opportunity to gain additional instruction in subjects that may require extra help.</p>',
				'link'      => '/academics',
				'link_text' => 'Learn more about Academics',
				'style'     => 'blue',
				'inline'    => 0,
			),
			'arts' => array(
				'image'     => 26426,
				'images'    => array( 26426, 26427, 26428, 26429 ),
				'header'    => 'Arts Schedule',
				'body'      => '<p>Arts take place on Monday, Wednesday, and Friday afternoons. Each arts afternoon is broken up into hour-long blocks, allowing students to choose up to four different arts courses. This scheduling framework enables students to try a multitude of artistic fields during their time at Brentwood and allows them to grow a love of the arts through regular practice. Our arts program has flourished in this environment and the results speak for themselves—on stage or screen, in the studios and workshops, and through our exhibits on public display around campus.</p>',
				'link'      => '/arts',
				'link_text' => 'Learn more about Arts',
				'style'     => '',
				'inline'    => 1,
			),
			'athletics' => array(
				'image'     => 26431,
				'images'    => array( 26431, 26432, 26433, 26434, 26435 ),
				'header'    => 'Athletics Schedule',
				'body'      => '<p>Athletics are run on Tuesday, Thursday, and Saturday afternoons—with our competitive teams also attending tournaments and league games when scheduled. Students are able to choose a different sport for each of the three terms. We offer a broad spectrum of recreational and competitive athletic opportunities, and encourage—particularly at the younger levels—student participation in multiple sports.</p>',
				'link'      => '/athletics',
				'link_text' => 'Learn more about Athletics',
				'style'     => '',
				'inline'    => 1,
			),
			'food' => array(
				'image'     => 26436,
				'images'    => array( 26436, 26437, 26438, 26439 ),
				'header'    => 'Food & Nutrition',
				'body'      => '<p><span>At Brentwood, we recognize the importance of good nutrition and how our diet impacts our intellectual performance, physical wellness, and overall quality of life. Our Food Services Team goes to great lengths to provide students with healthy meals that are prepared on site—all while supporting specific students with dietary restrictions. Our daily breakfast, lunch, and dinner servings consist of a prepared meal that is complemented by self-serve options such as soup, sandwich or wraps, and the salad bar. Outside of the main meals of the day, students can fuel up at ‘Cookie Break’ after the first class of the day, or during evening Prep—when snacks are available in the houses. As well, each Sunday students are treated to the famous Brentwood Sunday Brunch—with more delicious choices available than space on the plate.</span></p>',
				'link'      => '/student-life/student-services',
				'link_text' => 'Learn more about students services',
				'style'     => 'blue',
				'inline'    => 0,
			),
			'advisor' => array(
				'image'     => 26425,
				'images'    => array( 26425 ),
				'header'    => 'Advisors',
				'body'      => '<p><span>Every Monday morning, students in small grade groups meet with their Advisor to review the students’ overall Brentwood experience. Their Advisor is a person that helps students to navigate the plethora of options and opportunities at Brentwood—with a focus on making sure that the student is overcoming challenges and working towards a productive outcome in all areas of their experience, through self-advocacy. The strong relationship developed by Advisor and advisee, as they continue together through each grade, ensures that each student is properly supported and understood in all aspects of their learning journey.&nbsp;</span></p>',
				'link'      => '/why-brentwood/support',
				'link_text' => 'Learn more about student support',
				'style'     => 'white',
				'inline'    => 1,
			),
			'tutorial' => array(
				'image'     => 26442,
				'images'    => array( 26442 ),
				'header'    => 'Tutorial',
				'body'      => '<p><span>Dedicated time has been placed in our timetable to help students when they require additional instruction or assistance with their academics. This time highlights the need for students to develop the skills to identify any challenges they face and how best to self-advocate for their own learning styles. Tutorial takes shape in many ways, from one-on-one instruction with teachers to group work in our collaboration areas.&nbsp;</span></p>',
				'link'      => '',
				'link_text' => '',
				'style'     => '',
				'inline'    => 1,
			),
			'assembly' => array(
				'image'     => 26430,
				'images'    => array( 26430 ),
				'header'    => 'Assembly',
				'body'      => '<p><span>Every Thursday, our students and staff gather in the Killy Theatre for the schoolwide assembly. During this time, staff and student presenters promote upcoming events, celebrate our accomplishments, and reflect on topics taking place in the Brentwood community and around the world. Assembly brings our community together, where all students can feel the support of their peers while presenting or while being recognized for an achievement.&nbsp;</span></p>',
				'link'      => '',
				'link_text' => '',
				'style'     => '',
				'inline'    => 1,
			),
			'sleep-in' => array(
				'image'     => 26441,
				'images'    => array( 26441 ),
				'header'    => 'Sleep-in',
				'body'      => '<p><span>Every Wednesday morning, students begin classes at 9:30 am instead of 8:15 am. This mid-week sleep-in is designed to give students a well-deserved rest that will help them with both their physical and mental wellness. As well, during this time, our faculty meet to further their professional development in a collaborative setting.&nbsp;</span></p>',
				'link'      => '/why-brentwood/support',
				'link_text' => 'Learn more about student support',
				'style'     => 'blue',
				'inline'    => 1,
			),
			'prep' => array(
				'image'     => 26440,
				'images'    => array( 26440 ),
				'header'    => 'Evening Prep',
				'body'      => '<p><span>On weeknights, as the day is winding down, students return to their houses and engage in two hours of academic study, known as Prep. From 7:30 pm to 9:30 pm dedicated study time is supervised by the faculty, giving students the opportunity to get extra help when required and to not simply do homework in isolation. With all the students doing their prep at the same time, no one is missing out on any activities—further reducing distractions and increasing their ability to focus on completing work successfully.&nbsp;</span></p>',
				'link'      => '',
				'link_text' => '',
				'style'     => '',
				'inline'    => 0,
			),
			'activities' => array(
				'image'     => 26424,
				'images'    => array( 26424 ),
				'header'    => 'Saturday Night',
				'body'      => '<p><span>Saturday nights are one of the most engaging and joyful nights on campus. Many of the major school events take place on a Saturday night, including athletics showcases and arts performances that are attended by the entire school. Throughout the year, each boarding house will host an evening ‘open house’—where students from across campus come to enjoy a themed evening and celebrate the pride of each house. Saturday evenings are also a time when students can enjoy activities organized by their respective houseparents. These relaxed times in the house are often mentioned by alumni as some of their favourite moments at Brentwood.&nbsp;</span></p>',
				'link'      => '/student-life/activities',
				'link_text' => 'Learn more about student activities',
				'style'     => '',
				'inline'    => 1,
			),
		);
	}
}

if ( ! function_exists( 'bw_timetable_minutes' ) ) {
	/** Minutes since midnight for an "H:i" string (0 on bad input). */
	function bw_timetable_minutes( $hi ) {
		if ( ! preg_match( '/^(\d{1,2}):(\d{2})$/', trim( (string) $hi ), $m ) ) {
			return 0;
		}
		return ( (int) $m[1] ) * 60 + (int) $m[2];
	}
}
